Documentation
¶
Overview ¶
Package hook 定义 loop 引擎的全部扩展点。 采用小接口隔离:扩展只需实现关心的接口,NewAgent 内部类型断言归位。
并发契约:除 OnToolStart 与 OnToolEnd 外,引擎串行调用全部 hook 回调。 每个工具调用是独立单元(判定 → 执行 → 后处理整链跟调用走), OnToolStart / OnToolEnd 在同一轮的多个调用之间并发(单调用内 hooks 仍串行)—— 多个人工审批得以同时呈现而非排队;实现必须并发安全: 安全用法=只读 state、state.EmitEvent、阻塞等待 channel; 不安全用法=无锁写共享状态。工具 Invoke 同理并发 (但工具签名只拿到 ctx 与 args,碰不到 state)。 hook 自建的 goroutine 中不要读写 LoopState / Metadata—— 引擎对其并发访问不做保护,需要共享数据时自行加锁或只走 channel。
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var Abort = Action{Kind: KindAbort}
Abort 终止整个 loop(StopReason = aborted)。
View Source
var Proceed = Action{Kind: KindProceed}
Proceed 正常执行工具。
Functions ¶
This section is empty.
Types ¶
type Action ¶
type Action struct {
Kind ActionKind
Result string // Kind == KindSkip 时作为工具结果写入消息历史,空则用引擎默认文案
}
Action 是 ToolStartHook 的短路控制,内嵌短路时的工具结果: 决定"放行/跳过/终止"与"跳过时模型看到什么"是同一个决策,不应分离两处。
type ActionKind ¶ added in v1.0.1
type ActionKind int
const ( KindProceed ActionKind = iota KindSkip KindAbort )
type ModelEndHook ¶
type ModelStartHook ¶
type ToolEndHook ¶
Click to show internal directories.
Click to hide internal directories.