core/agent: soft context compact and cooperative cancel points

Shrink older tool dumps for model requests without mutating history;
check task cancellation between tool/model steps.
This commit is contained in:
2026-07-14 23:42:50 +08:00
parent 1da3e92f7c
commit 5cfe4d6a24
4 changed files with 395 additions and 5 deletions
+8 -1
View File
@@ -1,6 +1,7 @@
from __future__ import annotations
from plyngent.agent.budget import truncate_tool_result
from plyngent.agent.budget import estimate_message_chars, truncate_tool_result
from plyngent.lmproto.openai_compatible.model import ToolChatMessage, UserChatMessage
def test_truncate_tool_result_short() -> None:
@@ -13,3 +14,9 @@ def test_truncate_tool_result_long() -> None:
assert out.startswith("a" * 20)
assert "truncated" in out
assert "30" in out
def test_estimate_message_chars() -> None:
assert estimate_message_chars(UserChatMessage(content="hello")) == 5 # noqa: PLR2004
tool = ToolChatMessage(content="abc", tool_call_id="id1")
assert estimate_message_chars(tool) == 6 # noqa: PLR2004