mirror of
https://github.com/NCBM/plyngent.git
synced 2026-07-23 05:55:16 +08:00
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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user