Skip to content

Hook points ​

Choose the narrowest lifecycle point that has the information and control your policy needs.

Run hooks ​

HookRuns whenTypical use
onRunStartThe prompt run begins.Validate limits or environment policy.
onRunEndThe run completes successfully.Record a final audit annotation.
onRunErrorThe run fails.Correlate or classify the failure.

Run hooks can continue or cancel the run.

Turn and completion hooks ​

HookRuns whenTypical use
onTurnStartAn agent turn begins.Track turn-level policy or state.
onTurnEndAn agent turn finishes.Record turn completion.
onCompletionCallA model call is about to run.Observe model-call intent or enforce a limit.
onCompletionResponseA model call returns.Inspect normalized completion behavior.
onCompletionErrorA model call fails.Record provider-call failure context.

A tool-using run can contain several turns and completion calls. Run-level callbacks happen once; turn and completion callbacks may happen repeatedly.

Tool hooks ​

HookRuns whenTypical use
onToolCallThe model has selected a tool.Run, skip, cancel, or request approval.
onToolResultA tool returns successfully.Inspect the result or cancel future work.
onToolErrorTool execution fails.Record or classify the failure.

onToolCall has the broadest control surface because it runs before the selected tool executes.

Control by phase ​

ControlRun, turn, completion, and result hooksonToolCall
ContinueYesYes, with tool.run() or no return value
Cancel the runYes, with run.cancel(reason)Yes, with tool.cancel(reason)
Skip one toolNoYes, with tool.skip(reason)
Request approvalNoYes, with tool.requestApproval(...)

Returning nothing means continue. Return a control action only when the hook changes what the runtime should do.

Follow the runtime boundary ​

Use observers for passive telemetry that should never affect execution. Use middleware when request, response, input, or output data needs transformation. Hooks should remain reserved for lifecycle observation that belongs with a run decision.

Built for Anvia.