arbiter

package
v0.7.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 2, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package arbiter 是语义裁定层:按需唤醒的 LLM-as-function。

两平面对称(docs/engine-arbiter.md §二):

确定性平面:  flow.LoadState   → flow.Route     → Instruction
语义平面:    arbiter.Collect* → arbiter.Decide* → XxxDecision

纪律:Collect 集中 IO(从 store 读齐事实);Decide 除统一执行器管理的模型请求外无 IO, 可用历史 facts 离线重放;执行归 Engine。每场景一对函数 + 专属 Decision 类型, 场景不匹配的动作在类型上不可表达;剩余合法性由各类型的 Validate 拒绝—— Arbiter 输出与一切 LLM 输出同样不可信,事实校验是最后一道门。

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AdvanceHoldOp

type AdvanceHoldOp struct {
	Cancel bool                    `json:"cancel,omitempty"`
	After  domain.AdvanceHoldAfter `json:"after,omitempty"`
	Reason string                  `json:"reason,omitempty"`
}

AdvanceHoldOp 一次性暂停动作:在 Worker 边界或返工排空后暂停,也可取消。

type DispatchOp

type DispatchOp struct {
	Agent string `json:"agent"`
	Task  string `json:"task"`
}

DispatchOp 是各场景共享的派单动作。

type FailureDecision

type FailureDecision struct {
	Action   string      `json:"action"` // retry | reroute | abort
	Dispatch *DispatchOp `json:"dispatch,omitempty"`
	Reason   string      `json:"reason"`
}

FailureDecision 失败/僵局裁定。

func DecideFailure

func DecideFailure(ctx context.Context, model agentcore.ChatModel, systemPrompt string, facts FailureFacts) (FailureDecision, error)

DecideFailure 失败/僵局咨询。失败语义:返回 error → Engine 按最保守路径处理 (暂停 + notify),绝不无限咨询。

func (*FailureDecision) ValidateAgainst added in v0.7.3

func (d *FailureDecision) ValidateAgainst(f FailureFacts) error

type FailureFacts

type FailureFacts struct {
	Kind          string   `json:"kind"` // worker_failure | deadlock
	Agent         string   `json:"agent,omitempty"`
	Task          string   `json:"task,omitempty"`
	Error         string   `json:"error,omitempty"` // worker_failure:错误文本
	ErrorKind     string   `json:"error_kind,omitempty"`
	Repeats       int      `json:"repeats,omitempty"` // deadlock:同指令已派次数
	Phase         string   `json:"phase,omitempty"`
	NextChapter   int      `json:"next_chapter,omitempty"`
	PendingQueue  []int    `json:"pending_rewrites,omitempty"`
	FoundationGap []string `json:"foundation_missing,omitempty"`
	FactWarnings  []string `json:"fact_warnings,omitempty"`
}

FailureFacts 是 worker_failure / deadlock 两个场景共用的事实包: Engine 已做过确定性分类(重试/参数错等不到这里),送到 Arbiter 的都是 "确定性代码给不出出路"的残余。

type InterventionDecision

type InterventionDecision struct {
	Answer   string         `json:"answer,omitempty"`
	Rules    string         `json:"rules,omitempty"`
	Hold     *AdvanceHoldOp `json:"hold,omitempty"`
	Reopen   *ReopenOp      `json:"reopen,omitempty"`
	Dispatch *DispatchOp    `json:"dispatch,omitempty"`
	Reason   string         `json:"reason"`
}

InterventionDecision 干预裁定。动作组合自由,执行顺序由 Engine 固定: answer → rules → hold → reopen → dispatch;至多一个 dispatch(类型事实)。

func DecideIntervention

func DecideIntervention(ctx context.Context, model agentcore.ChatModel, systemPrompt string, facts InterventionFacts, text string) (InterventionDecision, error)

DecideIntervention 干预分诊。失败语义:返回 error → 调用方显式回显 真实失败原因,且不产生任何写入(宁可不动,不可误动)。

func (*InterventionDecision) ValidateAgainst

func (d *InterventionDecision) ValidateAgainst(f InterventionFacts) error

ValidateAgainst 按事实做机械校验(场景内合法性;类型已排除跨场景动作)。

type InterventionFacts

type InterventionFacts struct {
	Phase             string           `json:"phase,omitempty"`
	Flow              string           `json:"flow,omitempty"`
	NovelName         string           `json:"novel_name,omitempty"`
	CompletedChapters int              `json:"completed_chapters"`
	TotalChapters     int              `json:"total_chapters,omitempty"`
	NextChapter       int              `json:"next_chapter,omitempty"`
	PendingRewrites   []int            `json:"pending_rewrites,omitempty"`
	ReopenCount       int              `json:"reopen_count,omitempty"` // 用户显式 /reopen 重开完结书的累计次数
	FoundationMissing []string         `json:"foundation_missing,omitempty"`
	PlanningTier      string           `json:"planning_tier,omitempty"`
	AdvanceMode       string           `json:"advance_mode,omitempty"`
	HasAdvanceHold    bool             `json:"has_advance_hold"`
	AdvanceHoldAfter  string           `json:"advance_hold_after,omitempty"`
	AdvanceHoldReason string           `json:"advance_hold_reason,omitempty"`
	Running           bool             `json:"running"`                  // 干预到达时是否有 run 在进行
	CheckpointSeq     int64            `json:"checkpoint_seq,omitempty"` // Collect 时刻最新 checkpoint;Engine 对账用
	RecentDecisions   []RecentDecision `json:"recent_decisions,omitempty"`
}

InterventionFacts 干预分诊的事实包(Collect 时刻快照)。 Engine 在边界执行 Dispatch 前用 Phase/QueueHead 做对账(咨询与执行之间隔着 worker 运行,事实可能已推进;不符 → 丢弃并以新事实重询)。

func CollectInterventionFacts

func CollectInterventionFacts(st *storepkg.Store) (InterventionFacts, error)

CollectInterventionFacts 从 store 读齐分诊事实。任何控制事实读取失败都显式 返回错误,禁止 Arbiter 在零值拼成的不完整快照上做语义决策。

func (InterventionFacts) QueueHead

func (f InterventionFacts) QueueHead() int

QueueHead 返回重写队列头(无则 0),Engine 对账用。

type PlanStartDecision

type PlanStartDecision struct {
	Planner string `json:"planner"` // architect_long | architect_short
	Task    string `json:"task"`    // 交给规划师的完整任务(含扩充后的需求)
	Reason  string `json:"reason"`
}

PlanStartDecision 启动裁定:选规划师并产出(必要时扩充过的)任务文本。

func DecidePlanStart

func DecidePlanStart(ctx context.Context, model agentcore.ChatModel, systemPrompt, requirement, style string) (PlanStartDecision, error)

DecidePlanStart 启动裁定:根据用户需求选规划师;需求过短(<20 字)时在 task 里 自主补充差异化方向、目标读者与核心消费点、至少一个非常规钩子。 失败语义:返回 error → 调用方显式报错中止启动(启动期用户在场,报错优于猜测)。

func (*PlanStartDecision) Validate

func (d *PlanStartDecision) Validate() error

type RecentDecision

type RecentDecision struct {
	At     string `json:"at"`
	Input  string `json:"input"`
	Reason string `json:"reason,omitempty"`
}

RecentDecision 是干预记忆:最近几次裁定的摘要,覆盖"上次改的怎么样了"类跨干预引用。

type ReopenOp

type ReopenOp struct {
	Chapters []int  `json:"chapters"`
	Reason   string `json:"reason,omitempty"`
}

ReopenOp 完本返工:把全书重开进返工态并把目标章入队(仅 phase=complete 合法)。

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL