Your lightweight open-source personal agent.
Python agent-frameworkai-agentai-agentschatbotchatopsdiscord-botllm-agentsllmslocal-llmmcpmodel-context-protocolmulti-agentopenai-compatibleopenclawpersonal-ai-assistantpythonself-hostedtelegram-bot-ai-assistantwebuiworkflow-automation
fix(agent): avoid tool compaction echo loops
chengyongruaecb5fbc33b9
diff --git a/nanobot/agent/context_governance.py b/nanobot/agent/context_governance.pyindex 3622f73d5..ed98cb2c5 100644--- a/nanobot/agent/context_governance.py+++ b/nanobot/agent/context_governance.py@@ -427,7 +427,7 @@ class ContextGovernor:@staticmethoddef _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.pyindex a8f88d153..c2b2a0b29 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 contentelse 0for msg in msgsif 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"}