From 01df1ef3cf8107e249641fab501b9be0b4dc72d4 Mon Sep 17 00:00:00 2001 From: Joao Moura Date: Thu, 26 Feb 2026 00:38:33 -0800 Subject: [PATCH] refactor: increase memory recall limit and improve formatting - Updated memory recall limit from 5 to 10 in the Agent class to enhance memory retrieval capabilities. - Improved formatting of memory output by changing the join method to use double newlines for better readability in multiple locations. --- lib/crewai/src/crewai/agent/core.py | 8 ++++---- lib/crewai/src/crewai/memory/types.py | 6 +++++- lib/crewai/src/crewai/tools/memory_tools.py | 2 +- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/lib/crewai/src/crewai/agent/core.py b/lib/crewai/src/crewai/agent/core.py index e121a9771..83c2f0cfd 100644 --- a/lib/crewai/src/crewai/agent/core.py +++ b/lib/crewai/src/crewai/agent/core.py @@ -384,9 +384,9 @@ class Agent(BaseAgent): ) if unified_memory is not None: query = task.description - matches = unified_memory.recall(query, limit=5) + matches = unified_memory.recall(query, limit=10) if matches: - memory = "Relevant memories:\n" + "\n".join( + memory = "Relevant memories:\n" + "\n\n".join( m.format() for m in matches ) if memory.strip() != "": @@ -1811,10 +1811,10 @@ class Agent(BaseAgent): ), ) start_time = time.time() - matches = agent_memory.recall(formatted_messages, limit=5) + matches = agent_memory.recall(formatted_messages, limit=10) memory_block = "" if matches: - memory_block = "Relevant memories:\n" + "\n".join( + memory_block = "Relevant memories:\n" + "\n\n".join( m.format() for m in matches ) if memory_block: diff --git a/lib/crewai/src/crewai/memory/types.py b/lib/crewai/src/crewai/memory/types.py index e3d02e70d..2845fa4c1 100644 --- a/lib/crewai/src/crewai/memory/types.py +++ b/lib/crewai/src/crewai/memory/types.py @@ -100,7 +100,11 @@ class MemoryMatch(BaseModel): if self.record.metadata: for key, value in self.record.metadata.items(): if value: - lines.append(f" {key}: {value}") + if isinstance(value, list): + rendered_value = ", ".join(str(item) for item in value) + else: + rendered_value = str(value) + lines.append(f" {key}: {rendered_value}") return "\n".join(lines) diff --git a/lib/crewai/src/crewai/tools/memory_tools.py b/lib/crewai/src/crewai/tools/memory_tools.py index f088fef73..ead610cd5 100644 --- a/lib/crewai/src/crewai/tools/memory_tools.py +++ b/lib/crewai/src/crewai/tools/memory_tools.py @@ -57,7 +57,7 @@ class RecallMemoryTool(BaseTool): if not all_lines: return "No relevant memories found." - return "Found memories:\n" + "\n".join(all_lines) + return "Found memories:\n" + "\n\n".join(all_lines) class RememberSchema(BaseModel):