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(memory): preserve full consolidation input
dajiaohuangd4e23dec12c6
diff --git a/nanobot/agent/memory.py b/nanobot/agent/memory.pyindex 0e738e311..a381d13f7 100644--- a/nanobot/agent/memory.py+++ b/nanobot/agent/memory.py@@ -669,11 +669,28 @@ class MemoryStore:max_chars: int | None = None,session_key: str | None = None,) -> str:- """Persist and return a bounded raw checkpoint when summarization degrades."""- checkpoint = self._build_raw_checkpoint(messages, max_chars=max_chars)- self.append_history(checkpoint, session_key=session_key)+ """Persist raw messages in bounded chunks and return a checkpoint."""+ limit = max_chars if max_chars is not None else _RAW_ARCHIVE_MAX_CHARS+ chunk_size = min(max(1, limit), _HISTORY_ENTRY_HARD_CAP - 1_000)+ formatted = self._format_messages(public_history_messages(messages))+ chunks = [+ formatted[start:start + chunk_size]+ for start in range(0, len(formatted), chunk_size)+ ] or [""]+ for part, chunk in enumerate(chunks, start=1):+ suffix = f" (part {part}/{len(chunks)})" if len(chunks) > 1 else ""+ self.append_history(+ f"[RAW] {len(messages)} messages{suffix}\n{chunk}",+ session_key=session_key,+ )logger.warning(- "Memory consolidation degraded: raw-archived {} messages", len(messages)+ "Memory consolidation degraded: raw-archived {} messages in {} entries",+ len(messages),+ len(chunks),+ )+ checkpoint = self._normalize_history_entry(+ f"[RAW] {len(messages)} messages\n{formatted}",+ max_chars=limit,)return checkpointdiff --git a/tests/agent/test_consolidator.py b/tests/agent/test_consolidator.pyindex 587d0becd..05a217b85 100644--- a/tests/agent/test_consolidator.py+++ b/tests/agent/test_consolidator.py@@ -1333,7 +1333,6 @@ class TestCompactIdleSession:assert mock_provider.chat_stream_with_retry.await_count == 2entries = store.read_unprocessed_history(since_cursor=0)assert len(entries) == 1- assert entries[0]["content"].startswith("[RAW] ")assert "important answer" in entries[0]["content"]assert sessions.get_or_create("cli:repeated-tool").last_archived == 2@@ -1391,8 +1390,9 @@ class TestCompactIdleSession:assert "[RAW]" in resultmock_provider.chat_stream_with_retry.assert_not_awaited()entries = store.read_unprocessed_history(since_cursor=0)- assert len(entries) == 1- assert entries[0]["content"].startswith("[RAW] ")+ assert len(entries) > 1+ assert all(entry["content"].startswith("[RAW] ") for entry in entries)+ assert "x" * 100_000 in "".join(entry["content"].split("\n", 1)[1] for entry in entries)assert sessions.get_or_create("sdk:oversized").last_archived == 1@pytest.mark.asyncio@@ -1523,7 +1523,7 @@ class TestRawArchiveTruncation:messages = [{"role": "user", "content": big}]store.raw_archive(messages)entries = store.read_unprocessed_history(since_cursor=0)- assert len(entries) == 1+ assert len(entries) > 1assert len(entries[0]["content"]) < 50_000assert "[RAW]" in entries[0]["content"]