From aecb5fbc33b9c7e319afa4952808ab485da7eedb Mon Sep 17 00:00:00 2001 From: chengyongru Date: Thu, 2 Jul 2026 14:54:27 +0800 Subject: [PATCH] fix(agent): avoid tool compaction echo loops --- nanobot/agent/context_governance.py | 2 +- tests/agent/test_runner_governance.py | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/nanobot/agent/context_governance.py b/nanobot/agent/context_governance.py index 3622f73d..ed98cb2c 100644 --- a/nanobot/agent/context_governance.py +++ b/nanobot/agent/context_governance.py @@ -427,7 +427,7 @@ class ContextGovernor: @staticmethod def _summary_for(message: dict[str, Any]) -> str: name = message.get("name", "tool") - return f"[{name} result omitted from context]" + return f"[Prior {name} result compacted to fit context; the tool call already completed.]" def _legal_history_tail( self, diff --git a/tests/agent/test_runner_governance.py b/tests/agent/test_runner_governance.py index a8f88d15..c2b2a0b2 100644 --- a/tests/agent/test_runner_governance.py +++ b/tests/agent/test_runner_governance.py @@ -550,7 +550,7 @@ def test_microcompact_overflow_compacts_to_low_watermark(monkeypatch): def estimate(_provider, _model, msgs, _tools): return sum( 100 if (content := msg.get("content")) == long_content - else 1 if isinstance(content, str) and "omitted from context" in content + else 1 if isinstance(content, str) and "compacted to fit context" in content else 0 for msg in msgs if msg.get("role") == "tool" @@ -564,7 +564,7 @@ def test_microcompact_overflow_compacts_to_low_watermark(monkeypatch): set(), ) tool_msgs = [m for m in result if m.get("role") == "tool"] - compacted = [m for m in tool_msgs if "omitted from context" in str(m.get("content", ""))] + compacted = [m for m in tool_msgs if "compacted to fit context" in str(m.get("content", ""))] preserved = [m for m in tool_msgs if m.get("content") == long_content] assert len(compacted) == 8 @@ -609,7 +609,7 @@ def test_microcompact_compacts_newest_when_it_alone_overflows(monkeypatch): ) tool_msg = next(m for m in result if m.get("role") == "tool") - assert "omitted from context" in tool_msg["content"] + assert "compacted to fit context" in tool_msg["content"] assert compacted_tool_call_ids == {"c0"}