core/agent: drop get_truncated hint from token-less generic truncation

This commit is contained in:
2026-08-11 18:21:45 +08:00
parent c2735dada3
commit b5950bdb57
3 changed files with 14 additions and 13 deletions
+8 -9
View File
@@ -36,10 +36,13 @@ def truncate_tool_result(
) -> str:
"""Cap tool output so huge dumps do not flood model context.
With ``hint=True`` the suffix tells the model the result was cut and that
it may ask the user to raise the config limit (``max_tool_result_chars``).
``hint=False`` keeps the terse marker for internal shrinks whose cap is not
a user-facing config knob (e.g. request-time compacting).
This is the generic agent-loop cap for arbitrary tool results — there is no
resumable source, so no ``TRUNCATE_TOKEN`` is emitted here. Token-capable
sources (``read_file`` / ``fetch`` / ``get_truncated``) embed their own
``[TRUNCATE_TOKEN: ...]`` marker via :func:`truncate_with_token`, and only
there does the result point the model at ``get_truncated`` (hint and token
always appear together). ``hint=False`` keeps the terse marker for internal
shrinks whose cap is not a user-facing knob (e.g. request-time compacting).
"""
if max_chars < 1:
return text
@@ -47,11 +50,7 @@ def truncate_tool_result(
return text
omitted = len(text) - max_chars
if hint:
return (
f"{text[:max_chars]}\n"
f"...[Truncated ({max_chars} chars max.; {omitted} chars omitted). "
f"Use `get_truncated` when a `TRUNCATE_TOKEN` is shown.]"
)
return f"{text[:max_chars]}\n...[Truncated ({max_chars} chars max.; {omitted} chars omitted)]"
return f"{text[:max_chars]}\n...[truncated {omitted} characters]"
+3 -2
View File
@@ -15,8 +15,9 @@ def test_truncate_tool_result_long() -> None:
assert "Truncated" in out
assert "20" in out
assert "30" in out
assert "get_truncated" in out
assert "configuration file" not in out
# Generic tool results carry no resumable source → no token, no get_truncated.
assert "get_truncated" not in out
assert "TRUNCATE_TOKEN" not in out
def test_truncate_tool_result_no_hint() -> None:
+3 -2
View File
@@ -44,8 +44,9 @@ def test_truncate_tool_result_long() -> None:
assert "Truncated" in out
assert "20" in out
assert "30" in out
assert "get_truncated" in out
assert "configuration file" not in out
# Generic tool results carry no resumable source → no token, no get_truncated.
assert "get_truncated" not in out
assert "TRUNCATE_TOKEN" not in out
def test_truncate_tool_result_no_hint() -> None: