To Model Output • AI Agent SDK

to_model_output: Optional hook returning a compact, model-facing view of “result“.

to_model_output

Method

</div>

This is a method of the BaseTool class in the base module.

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

python
def to_model_output(result: Any) -> Optional[Any]

Parameters

ParamField Any

No description available.

Returns

ResponseField Optional[Any]

The result of the operation.

Source

View on GitHub

praisonaiagents/tools/base.py at line 284


Related Documentation