Skip to main content

Module hooks

Module hooks 

Source
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§

CallEvent
A turn about to request the model.
Dispatch
A tool call about to run.
DispatchRepair
What a hook asked to do with a malformed call: the name and the argument string the call should run with instead.
HookInfo
A hook this build knows by name.
LoopHooks
The hooks a runtime runs, in registration order.
Outcome
A tool result, before the model sees it.
RecallSessions
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.
RecallSettings
What [hooks.recall-sessions] accepts, with what a bare [hooks] gets.
RedactSecrets
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.
RequestPatch
How a turn’s request differs from the agent’s defaults.
RunStart
A run beginning. prompt is 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§

CallAction
DispatchAction
Ending
OutcomeAction
RunStartAction
ToolChoice
The tool_choice values an OpenAI-compatible endpoint understands.
TurnAction

Constants§

DEFAULT_ORDER
What [hooks] order is when the section is absent.
SHIPPED
The hooks this build ships. A name in [hooks] order must be one of these.

Traits§

LoopHook
One place to intervene in the loop. Every method has a “carry on” default, so implement only what you need.

Functions§

describe
The # hooks: lines eclipse config show prints 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_with against what this build ships.
validate_with
Check [hooks] against the hooks known, saying what is wrong and what to do about it.