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§
- Next
Dispatch - The rest of the chain, ending in the engine’s own dispatch.
- Tool
Answer - A tool that ran, and what it produced.
- Tool
Call - The call being made, as a wrapper may see it. Read-only by design — see the module docs.
- Tool
Exec - The conditions the call runs under, as a wrapper may change them.
Traits§
- Tool
Middleware - A ring around every tool call.
Functions§
- dispatch_
through - Run
chainarounddispatch.
Type Aliases§
- Tool
Outcome - What dispatch returns.