mirror of
https://github.com/NCBM/plyngent.git
synced 2026-11-07 23:47:54 +08:00
core/agent: drop get_truncated hint from token-less generic truncation
This commit is contained in:
@@ -36,10 +36,13 @@ def truncate_tool_result(
|
|||||||
) -> str:
|
) -> str:
|
||||||
"""Cap tool output so huge dumps do not flood model context.
|
"""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
|
This is the generic agent-loop cap for arbitrary tool results — there is no
|
||||||
it may ask the user to raise the config limit (``max_tool_result_chars``).
|
resumable source, so no ``TRUNCATE_TOKEN`` is emitted here. Token-capable
|
||||||
``hint=False`` keeps the terse marker for internal shrinks whose cap is not
|
sources (``read_file`` / ``fetch`` / ``get_truncated``) embed their own
|
||||||
a user-facing config knob (e.g. request-time compacting).
|
``[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:
|
if max_chars < 1:
|
||||||
return text
|
return text
|
||||||
@@ -47,11 +50,7 @@ def truncate_tool_result(
|
|||||||
return text
|
return text
|
||||||
omitted = len(text) - max_chars
|
omitted = len(text) - max_chars
|
||||||
if hint:
|
if hint:
|
||||||
return (
|
return f"{text[:max_chars]}\n...[Truncated ({max_chars} chars max.; {omitted} chars omitted)]"
|
||||||
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 {omitted} characters]"
|
return f"{text[:max_chars]}\n...[truncated {omitted} characters]"
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -15,8 +15,9 @@ def test_truncate_tool_result_long() -> None:
|
|||||||
assert "Truncated" in out
|
assert "Truncated" in out
|
||||||
assert "20" in out
|
assert "20" in out
|
||||||
assert "30" in out
|
assert "30" in out
|
||||||
assert "get_truncated" in out
|
# Generic tool results carry no resumable source → no token, no get_truncated.
|
||||||
assert "configuration file" not in out
|
assert "get_truncated" not in out
|
||||||
|
assert "TRUNCATE_TOKEN" not in out
|
||||||
|
|
||||||
|
|
||||||
def test_truncate_tool_result_no_hint() -> None:
|
def test_truncate_tool_result_no_hint() -> None:
|
||||||
|
|||||||
@@ -44,8 +44,9 @@ def test_truncate_tool_result_long() -> None:
|
|||||||
assert "Truncated" in out
|
assert "Truncated" in out
|
||||||
assert "20" in out
|
assert "20" in out
|
||||||
assert "30" in out
|
assert "30" in out
|
||||||
assert "get_truncated" in out
|
# Generic tool results carry no resumable source → no token, no get_truncated.
|
||||||
assert "configuration file" not in out
|
assert "get_truncated" not in out
|
||||||
|
assert "TRUNCATE_TOKEN" not in out
|
||||||
|
|
||||||
|
|
||||||
def test_truncate_tool_result_no_hint() -> None:
|
def test_truncate_tool_result_no_hint() -> None:
|
||||||
|
|||||||
Reference in New Issue
Block a user