2026-07-14 23:24:11 +08:00
|
|
|
from __future__ import annotations
|
|
|
|
|
|
2026-07-14 23:42:50 +08:00
|
|
|
from plyngent.agent.budget import estimate_message_chars, truncate_tool_result
|
|
|
|
|
from plyngent.lmproto.openai_compatible.model import ToolChatMessage, UserChatMessage
|
2026-07-14 23:24:11 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_truncate_tool_result_short() -> None:
|
|
|
|
|
assert truncate_tool_result("hello", 100) == "hello"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 "30" in out
|
2026-07-14 23:42:50 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_estimate_message_chars() -> None:
|
2026-07-15 10:35:30 +08:00
|
|
|
assert estimate_message_chars(UserChatMessage(content="hello")) == 5
|
2026-07-14 23:42:50 +08:00
|
|
|
tool = ToolChatMessage(content="abc", tool_call_id="id1")
|
2026-07-15 10:35:30 +08:00
|
|
|
assert estimate_message_chars(tool) == 6
|