feat(mem0): keep tool results and fix consolidation flow
Build Nanobot OAuth / build (push) Successful in 6m4s
Build Nanobot OAuth / cleanup (push) Successful in 0s

- Keep tool results (truncated to 2000 chars) sent as role: "user"
  instead of skipping them entirely. mem0's parse_messages() ignores
  "tool" role, and tool output often contains useful facts (file
  reads, search results, web pages).
- Fix loop.py to call memory.consolidate() and return early when
  using mem0, preventing fallthrough to old MemoryStore logic.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
2026-03-01 07:47:18 +00:00
parent bdc3be650b
commit dc5d8edfec
2 changed files with 23 additions and 1 deletions
+9
View File
@@ -766,6 +766,15 @@ class AgentLoop:
if self.mem0_config and self.mem0_config.get("enabled") and HAS_MEM0:
memory = Mem0MemoryStore(self.workspace, config=self.mem0_config)
logger.debug("Using mem0 for memory consolidation")
# Mem0 has its own consolidation logic (feeds messages to mem0 for extraction)
await memory.consolidate(
session,
self.provider,
self.model,
archive_all=archive_all,
memory_window=self.memory_window,
)
return
else:
memory = MemoryStore(self.workspace)
logger.debug("Using MemoryStore for memory consolidation")
+14 -1
View File
@@ -346,8 +346,21 @@ Here is the conversation to extract facts from:
role = msg.get("role")
content = msg.get("content")
# Skip tool result messages entirely — they're bash output, grep results, JSON blobs
# Keep tool results but truncate long ones — they often contain
# the actual substance (file reads, search results, web pages).
# The extraction prompt handles ignoring code/JSON noise.
if role == "tool":
if isinstance(content, list):
text_parts = [
block.get("content", "") if isinstance(block, dict) else str(block)
for block in content
]
content = " ".join(text_parts).strip()
if isinstance(content, str) and len(content) > 2000:
content = content[:2000]
if not content or (isinstance(content, str) and len(content.strip()) < 10):
continue
mem0_messages.append({"role": "user", "content": content})
continue
# Skip system messages — they're boilerplate instructions, not facts