Decorate or observe agent lifecycle events: prompts, tool use, session boundaries.
在 agent 关键事件插入自定义逻辑——memory 子系统就是通过 hooks 实现的。
Two categories, separated at the type level — prefix-cache safety is a compile-time property:
两类 hooks,在类型层面区分,前缀缓存安全性在编译时保证:
| Hook | Hook | When | 触发时机 | Purpose | 作用 |
|---|---|---|---|---|---|
PrePromptHook |
Before user message is appended to history | 用户消息追加到历史之前 | Inject memory, expand slash commands, rewrite user text | 注入记忆、展开斜杠命令、改写用户文本 | |
PreToolUseHook |
Before tool call execution | 工具调用执行前 | Modify tool arguments, inject context | 修改工具参数、注入上下文 |
| Hook | Hook | When | 触发时机 |
|---|---|---|---|
PreTurn | Before each turn | 每轮开始前 | |
PostTurn | After each turn | 每轮结束后 | |
PostToolUse | After each tool call | 每个工具执行后 | |
SessionStart | Session begins | 会话开始时 | |
SessionEnd | Session ends | 会话结束时 |
checkpointHook) — PreTurn + SessionEnd to manage checkpoint stateinternal/memory) — PrePrompt + PostToolUse + SessionStart + SessionEnd for L/M/S three-tier memoryinternal/memory)——通过 PrePrompt + PostToolUse + SessionStart + SessionEnd 实现 L/M/S 三层记忆seek hooks$ seek hooks list # List trusted hook scripts $ seek hooks check --event <event> [--tool <tool>] # Dry-run: which hooks fire for this event/tool? $ seek hooks trust [--reset[=<path>]] # List trusted projects; --reset removes trust $ seek hooks audit # Audit hook call records
A single struct may implement multiple hook interfaces. Registry.Register dispatches it into every slot it satisfies.
一个结构体可以实现多个 hook 接口。Registry.Register 自动分发:
// A struct implementing both PrePrompt + PostTurn type myHook struct{} func (h *myHook) OnPrePrompt(ctx context.Context, in hooks.PrePromptIn) (hooks.PrePromptOut, error) { return hooks.PrePromptOut{UserText: in.UserText + "\n[injected context]"}, nil } func (h *myHook) OnPostTurn(ctx context.Context, ev hooks.PostTurnEvent) { // analyse, distil, persist... } // Register registry := hooks.NewRegistry() registry.Register(&myHook{})