Skip to main content

Module tool_middleware

Module tool_middleware 

Source
Expand description

ToolMiddleware — the ring around tool dispatch.

Timeouts, retries, metrics, caching, idempotent de-duplication: none of these belong to a tool’s implementation and none of them are permission decisions. They are the things you wrap a call in. With nowhere to put them, they get hardcoded into the loop — which is where the engine’s existing timeout and retry logic lives today, and why adding a per-tool deadline currently means editing the turn.

§What a wrapper may do, and the one thing it may not

It may narrow the signal: hand the call a stricter cancellation than the turn’s, which is how a timeout is expressed. It may short-circuit: answer without calling through at all, which is how a cache hit is expressed. It may call through more than once, which is how a retry is expressed.

It may not rewrite the call’s input. That is a different act with a different risk — rewriting arguments turns an approved call into a different call, after approval — and it belongs to a hook point of its own with its own trust rules. Here it is not a rule to remember, it is a thing the types do not let you say: the call arrives behind a shared reference and dispatch takes no arguments.

§Order

Wrappers nest in registration order: the first registered is outermost, so it sees the others’ retries as one call. That is the ordering a metrics wrapper wants (register it first and it measures everything inside) and the one a cache wants (register it first and a hit costs nothing further in).

Structs§

NextDispatch
The rest of the chain, ending in the engine’s own dispatch.
ToolAnswer
A tool that ran, and what it produced.
ToolCall
The call being made, as a wrapper may see it. Read-only by design — see the module docs.
ToolExec
The conditions the call runs under, as a wrapper may change them.

Traits§

ToolMiddleware
A ring around every tool call.

Functions§

dispatch_through
Run chain around dispatch.

Type Aliases§

ToolOutcome
What dispatch returns.