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

Function _truncate_tool_result

src/harness/agentic_loop/loop.py:107–118  ·  view source on GitHub ↗

Truncate a tool result to max_chars, preserving head and tail.

(result_str: str, max_chars: int)

Source from the content-addressed store, hash-verified

105
106
107def _truncate_tool_result(result_str: str, max_chars: int) -> str:
108 """Truncate a tool result to max_chars, preserving head and tail."""
109 if len(result_str) <= max_chars:
110 return result_str
111 head_len = int(max_chars * 0.7)
112 tail_len = int(max_chars * 0.2)
113 truncated_count = len(result_str) - head_len - tail_len
114 return (
115 f"{result_str[:head_len]}\n\n"
116 f"... [TRUNCATED: {truncated_count:,} characters removed] ...\n\n"
117 f"{result_str[-tail_len:]}"
118 )
119
120
121class AgenticLoop:

Callers 1

_inner_loopMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected