Format a tool result for display to the LLM. Handles special formatting for specific tools (like shell_run) and provides generic formatting for other tools. Args: function_name: Name of the tool that produced the result. payload: The tool's result payload. thoug
(
function_name: str, payload: Any, thought_footer_message: Optional[str] = None
)
| 9 | |
| 10 | |
| 11 | def format_inline_tool_result( |
| 12 | function_name: str, payload: Any, thought_footer_message: Optional[str] = None |
| 13 | ) -> str: |
| 14 | """Format a tool result for display to the LLM. |
| 15 | |
| 16 | Handles special formatting for specific tools (like shell_run) and |
| 17 | provides generic formatting for other tools. |
| 18 | |
| 19 | Args: |
| 20 | function_name: Name of the tool that produced the result. |
| 21 | payload: The tool's result payload. |
| 22 | thought_footer_message: When set, appended as a footer to shell_run results. |
| 23 | |
| 24 | Returns: |
| 25 | Formatted string representation of the result. |
| 26 | |
| 27 | Example: |
| 28 | result = format_inline_tool_result("shell_run", {"returncode": 0, "output": "hello"}) |
| 29 | # Returns: "Return code: 0\\nOutput: hello" |
| 30 | """ |
| 31 | # Unwrap nested result structures |
| 32 | if ( |
| 33 | isinstance(payload, dict) |
| 34 | and "result" in payload |
| 35 | and isinstance(payload["result"], dict) |
| 36 | ): |
| 37 | payload = payload["result"] |
| 38 | |
| 39 | if function_name == "shell_run": |
| 40 | return _format_shell_run(payload, thought_footer_message=thought_footer_message) |
| 41 | |
| 42 | return _format_generic_result(payload) |
| 43 | |
| 44 | |
| 45 | def _format_shell_run( |
no test coverage detected