To Model Output • AI Agent SDK
to_model_output: Optional hook returning a compact, model-facing view of “result“.
to_model_output
Method
</div>
Optional hook returning a compact, model-facing view of `result`.
`result is the tool's raw return value (the output channel), not the enclosing :class:ToolResult. This is the single hook contract used everywhere: safe_run and the agent executor both invoke it with the output value. Override to feed the LLM a terse summary/diff instead of the full tool output for context economy; the full result still reaches display, hooks, and tracing. Return None` (the default) to keep today’s behaviour where the model sees the full output.
Signature
def to_model_output(result: Any) -> Optional[Any]Parameters
ParamField
AnyNo description available.
Returns
ResponseField
Optional[Any]The result of the operation.
Source
View on GitHubpraisonaiagents/tools/base.py at line 284