MCPcopy Create free account
hub / github.com/ScaleML/AgentSPEX / format_inline_tool_result

Function format_inline_tool_result

src/harness/tools/formatting.py:11–42  ·  view source on GitHub ↗

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
)

Source from the content-addressed store, hash-verified

9
10
11def 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
45def _format_shell_run(

Callers 1

Calls 2

_format_shell_runFunction · 0.85
_format_generic_resultFunction · 0.85

Tested by

no test coverage detected