forked from retoor/devplacepy
Update werkend
This commit is contained in:
@@ -206,6 +206,59 @@ class _FakeLLMWithRealLimit:
|
||||
return "short summary"
|
||||
|
||||
|
||||
def test_proactive_compaction_targets_40_percent_of_threshold():
|
||||
messages = _long_message_history(100)
|
||||
threshold = context_size(messages) - 50
|
||||
llm = _FakeLLM([{"role": "assistant", "content": "done"}])
|
||||
trace_events = []
|
||||
result = run_async(
|
||||
react_loop(
|
||||
llm,
|
||||
_FakeDispatcher(),
|
||||
messages,
|
||||
tools=[],
|
||||
state=AgentState(),
|
||||
settings=_settings_for_test(keep_tail=4, threshold=threshold),
|
||||
max_iterations=5,
|
||||
plan_required=False,
|
||||
verify_required=False,
|
||||
on_trace=lambda event, name, detail: trace_events.append(event),
|
||||
)
|
||||
)
|
||||
assert result == "done"
|
||||
assert "compact" in trace_events
|
||||
assert context_size(messages) <= int(threshold * 0.4)
|
||||
|
||||
|
||||
def test_proactive_compaction_retries_when_first_pass_is_not_enough():
|
||||
giant = "X" * 300_000
|
||||
messages = _long_message_history(20)
|
||||
messages.append(
|
||||
{"role": "tool", "tool_call_id": "1", "name": "big_tool", "content": giant}
|
||||
)
|
||||
messages.append({"role": "user", "content": "please continue"})
|
||||
|
||||
llm = _FakeLLM([{"role": "assistant", "content": "done"}])
|
||||
result = run_async(
|
||||
react_loop(
|
||||
llm,
|
||||
_FakeDispatcher(),
|
||||
messages,
|
||||
tools=[],
|
||||
state=AgentState(),
|
||||
settings=_settings_for_test(keep_tail=2, threshold=50_000),
|
||||
max_iterations=5,
|
||||
plan_required=False,
|
||||
verify_required=False,
|
||||
)
|
||||
)
|
||||
|
||||
assert result == "done"
|
||||
assert llm.summarize_calls > 1
|
||||
giant_message = next(m for m in messages if m.get("name") == "big_tool")
|
||||
assert len(giant_message["content"]) < len(giant)
|
||||
|
||||
|
||||
def test_one_oversized_tail_message_alone_still_recovers():
|
||||
giant = "X" * 300_000
|
||||
messages = _long_message_history(16)
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
# retoor <retoor@molodetz.nl>
|
||||
|
||||
from devplacepy.services.devii.llm import _sanitize_tool_calls, _sanitize_tool_name
|
||||
|
||||
|
||||
def test_sanitize_tool_name_leaves_clean_names_untouched():
|
||||
assert _sanitize_tool_name("plan") == "plan"
|
||||
assert _sanitize_tool_name("project_write_file") == "project_write_file"
|
||||
|
||||
|
||||
def test_sanitize_tool_name_strips_a_harmony_channel_leak():
|
||||
assert _sanitize_tool_name("plan<|channel|>commentary") == "plan"
|
||||
|
||||
|
||||
def test_sanitize_tool_name_strips_any_special_token_style_suffix():
|
||||
assert _sanitize_tool_name("verify<|message|>") == "verify"
|
||||
assert _sanitize_tool_name("recall<|end|>") == "recall"
|
||||
|
||||
|
||||
def test_sanitize_tool_name_falls_back_to_original_if_nothing_survives():
|
||||
assert _sanitize_tool_name("<|channel|>commentary") == "<|channel|>commentary"
|
||||
|
||||
|
||||
def test_sanitize_tool_calls_mutates_leaked_names_in_place():
|
||||
message = {
|
||||
"role": "assistant",
|
||||
"tool_calls": [
|
||||
{"id": "1", "function": {"name": "plan<|channel|>commentary", "arguments": "{}"}},
|
||||
{"id": "2", "function": {"name": "verify", "arguments": "{}"}},
|
||||
],
|
||||
}
|
||||
_sanitize_tool_calls(message)
|
||||
assert message["tool_calls"][0]["function"]["name"] == "plan"
|
||||
assert message["tool_calls"][1]["function"]["name"] == "verify"
|
||||
|
||||
|
||||
def test_sanitize_tool_calls_handles_no_tool_calls():
|
||||
message = {"role": "assistant", "content": "hi"}
|
||||
_sanitize_tool_calls(message)
|
||||
assert message == {"role": "assistant", "content": "hi"}
|
||||
|
||||
|
||||
def test_sanitize_tool_calls_ignores_malformed_function_entries():
|
||||
message = {"tool_calls": [{"id": "1", "function": "not-a-dict"}]}
|
||||
_sanitize_tool_calls(message)
|
||||
assert message["tool_calls"][0]["function"] == "not-a-dict"
|
||||
Reference in New Issue
Block a user