feat(mem0): keep tool results and fix consolidation flow
- 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:
@@ -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")
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user