Expand description
ModelInterceptor — the request on its way out, and the message on its
way back.
Two moments matter for anyone who wants to shape what the engine says to a provider and what it does with the answer: just before a request is sent, when the messages, tools and parameters are assembled and nothing has left the process yet; and just after a complete message has been assembled from a stream, when it is whole enough to reason about.
§There is deliberately no per-chunk hook
The obvious third moment — every streamed delta — is the one this does not offer. A turn produces thousands of chunks, so a hook there is called thousands of times, and the cost is invisible to whoever writes it: their function looks cheap, the streaming looks broken. Worse, a hook that can rewrite chunks can produce a message that never existed as a coherent whole, which nothing downstream is built to handle.
So the contract offers complete things: the complete request, the complete
message. Both are called once per model call, which
does_not_run_per_chunk has a test for. If a deployment genuinely
needs to transform a stream as it arrives, the answer is a declarative rule
the engine executes natively — not a callback in the chunk loop.
Structs§
- Model
Request View - A model request, assembled and not yet sent.
Traits§
- Model
Interceptor - Shapes what goes to the provider and what comes back.
Functions§
- intercept_
message - Run every interceptor over a completed message.
- intercept_
request - Run every interceptor over a request.