Expand description
ToolResultTransformer — the last hands on a tool’s output before the
model reads it.
Truncation, redaction, moving something large out of the conversation and leaving a reference: these are policies about what a result may look like, not about what a tool does. A tool that enforces its own cap enforces it for everyone, in units it chose; a deployment that must never let a credential reach a provider has nowhere to say so at all.
§Last, and why that is the whole point
The chain runs after every hook, immediately before the outcome is
returned. That ordering is what makes a redacting transformer a guarantee
rather than a suggestion: nothing downstream can put back what it took
out. Run it earlier and a PostToolUse hook rewriting the result would
quietly undo it.
The cost of that choice is that hook payloads see the untransformed text. That is the right trade here — a hook is a local command the operator configured, at the same trust level as the engine itself, while the model is a remote party.
§Errors go through too
A failure message is as capable of carrying a path, a token or a hostname as a success is. A transformer that only saw successful results would be a redaction policy with a hole in it.
Structs§
- Redact
Literals - Replace known secrets wherever they appear.
- Result
Image - A large piece of binary content a tool returned, on its way to becoming an image block beside the tool result.
- Tool
Result Draft - A tool’s output, mid-flight.
- Truncate
Text - Cap a result’s length, saying so where it was cut.
Traits§
- Tool
Result Transformer - A policy about what a tool result may look like.
Functions§
- apply
- Run every transformer, in order.