Expand description
In-process hooks into the agent loop: the extension point the loop did not have.
The loop has exactly one turn shape and six places where policy could differ: the start of
a run, the request for a turn, the model’s answer, a tool about to run, a tool’s result,
and the end of a run. A LoopHook sees all six and may change what happens next.
run_start ─▶ [ completion_call ─▶ model ─▶ model_turn_finished ─▶ dispatch ─▶ tool ─▶ outcome ]* ─▶ run_settled§Three rules, because a hook is control flow and control flow is easy to regret
Actions, not booleans. Every method returns an action enum whose default is “carry on”, so a hook that wants to observe can say nothing, and adding an event later cannot break a hook written today.
Hooks are awaited inline, so they must be cheap. A hook runs inside the loop, in the
way of the next model call: anything that blocks here is latency on every turn. A hook that
needs to shell out, call a network service, or take its time is a plugin
(crate::plugins), which runs in its own process with its own timeouts. That boundary is
deliberate and it is the only reason the loop stays predictable.
A patch is not sticky. [hooks::RequestPatch] affects the one turn its event belonged
to; the event fires again next turn and produces a fresh answer. A hook that sets
tool_choice: required every turn has built an infinite loop, and it will look like a bug
in the model.
§What a hook is not for
Not for anything that must survive a restart (that is M13), not for anything that must run out of process (plugins), and not for replacing the loop’s own guarantees — cancellation, the iteration cap and the dangling-call repair stay where they are, because a hook cannot be trusted to preserve them.
Structs§
- Call
Event - A turn about to request the model.
- Dispatch
- A tool call about to run.
- Dispatch
Repair - What a hook asked to do with a malformed call: the name and the argument string the call should run with instead.
- Hook
Info - A hook this build knows by name.
- Loop
Hooks - The hooks a runtime runs, in registration order.
- Outcome
- A tool result, before the model sees it.
- Recall
Sessions - The archive, read as memory: the closest earlier sessions for this prompt, injected before the model’s first request rather than left for it to ask for.
- Recall
Settings - What
[hooks.recall-sessions]accepts, with what a bare[hooks]gets. - Redact
Secrets - Replaces secrets in tool results before the model reads them, and before they are stored.
- Reporting
- Where a hook’s one-line report goes, and how often.
- Request
Patch - How a turn’s request differs from the agent’s defaults.
- RunStart
- A run beginning.
promptis what the user asked for, after the CLI resolved it. - Settled
- How a run ended, for hooks that audit or clean up.
- Turn
- The model’s answer to a turn, before it is stored.
Enums§
- Call
Action - Dispatch
Action - Ending
- Outcome
Action - RunStart
Action - Tool
Choice - The
tool_choicevalues an OpenAI-compatible endpoint understands. - Turn
Action
Constants§
- DEFAULT_
ORDER - What
[hooks] orderis when the section is absent. - SHIPPED
- The hooks this build ships. A name in
[hooks] ordermust be one of these.
Traits§
- Loop
Hook - One place to intervene in the loop. Every method has a “carry on” default, so implement only what you need.
Functions§
- describe
- The
# hooks:lineseclipse config showprints above the section: the order that is in effect, and for each hook the loop point it is wired at. - from_
config - Build the hooks
[hooks]names, in the order it names them. - from_
config_ reporting from_config, with the report going where the caller says.- recall_
terms - Words a prompt is searched by: the content words, in the order they were typed.
- validate
validate_withagainst what this build ships.- validate_
with - Check
[hooks]against the hooksknown, saying what is wrong and what to do about it.