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.
This commit is contained in:
Joao Moura
2026-02-26 00:38:33 -08:00
parent 358fd92e6b
commit 01df1ef3cf
3 changed files with 10 additions and 6 deletions

View File

@@ -384,9 +384,9 @@ class Agent(BaseAgent):
) )
if unified_memory is not None: if unified_memory is not None:
query = task.description query = task.description
matches = unified_memory.recall(query, limit=5) matches = unified_memory.recall(query, limit=10)
if matches: if matches:
memory = "Relevant memories:\n" + "\n".join( memory = "Relevant memories:\n" + "\n\n".join(
m.format() for m in matches m.format() for m in matches
) )
if memory.strip() != "": if memory.strip() != "":
@@ -1811,10 +1811,10 @@ class Agent(BaseAgent):
), ),
) )
start_time = time.time() start_time = time.time()
matches = agent_memory.recall(formatted_messages, limit=5) matches = agent_memory.recall(formatted_messages, limit=10)
memory_block = "" memory_block = ""
if matches: if matches:
memory_block = "Relevant memories:\n" + "\n".join( memory_block = "Relevant memories:\n" + "\n\n".join(
m.format() for m in matches m.format() for m in matches
) )
if memory_block: if memory_block:

View File

@@ -100,7 +100,11 @@ class MemoryMatch(BaseModel):
if self.record.metadata: if self.record.metadata:
for key, value in self.record.metadata.items(): for key, value in self.record.metadata.items():
if value: 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) return "\n".join(lines)

View File

@@ -57,7 +57,7 @@ class RecallMemoryTool(BaseTool):
if not all_lines: if not all_lines:
return "No relevant memories found." 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): class RememberSchema(BaseModel):