core/agent: token-ify generic tool-result cap and compact shrinks

This commit is contained in:
2026-08-11 18:50:10 +08:00
parent ec1ae59a28
commit 6fdfb8398e
3 changed files with 26 additions and 35 deletions
+6 -10
View File
@@ -11,21 +11,17 @@ def test_truncate_tool_result_short() -> None:
def test_truncate_tool_result_long() -> None:
text = "a" * 50
out = truncate_tool_result(text, 20)
assert out.startswith("a" * 20)
assert "Truncated" in out
assert "20" in out
assert "30" 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
# Generic tool results now embed a memory token too (resumable via get_truncated).
assert "truncate_token=" in out
assert out.startswith(("a" * 10, "a" * 20)) # marker is budgeted
def test_truncate_tool_result_no_hint() -> None:
text = "a" * 50
out = truncate_tool_result(text, 20, hint=False)
assert out.startswith("a" * 20)
assert "truncated" in out
assert "get_truncated" not in out
def test_truncate_tool_result_fits_no_marker() -> None:
assert truncate_tool_result("tiny", 100) == "tiny"
assert "Truncated" not in truncate_tool_result("tiny", 100)
def test_estimate_message_chars() -> None: