Overview
Instead of automatically injecting memories into context, this architecture gives agents explicit tools to read and write memories. The agent decides when to store information and when to retrieve it. This provides transparency, control, and efficient context usage.
The Tool-Based Approach
Explicit Over Implicit
Traditional approach:
Tool-based approach:
Memory Tools
Store Memory
Tool: remember
Description: Store important information for future reference
Parameters:
- content: The information to remember
- type: fact | preference | event | task
- importance: low | medium | high
- tags: Array of categorization tags
Returns: memory_id for reference
Retrieve Memories
Tool: recall
Description: Search for relevant memories
Parameters:
- query: What to search for
- type: Optional type filter
- limit: Max results (default 5)
- time_range: Optional date filter
Returns: Array of relevant memories with scores
Update Memory
Tool: update_memory
Description: Modify an existing memory
Parameters:
- memory_id: Which memory to update
- content: New content (optional)
- importance: New importance (optional)
Returns: Updated memory
Forget
Tool: forget
Description: Remove a memory
Parameters:
- memory_id: Which memory to remove
- reason: Why it's being forgotten
Returns: Confirmation
Architecture Flow
User: "Remember that I prefer window seats on flights"
Agent thinks: "User wants me to store a preference"
Agent calls: remember(
content="User prefers window seats on flights",
type="preference",
importance="medium",
tags=["travel", "flights", "seating"]
)
Agent responds: "Got it! I'll remember you prefer window seats."
---
User: "Book me a flight to NYC"
Agent thinks: "I should check if I have any flight preferences"
Agent calls: recall(
query="flight preferences travel",
type="preference"
)
Returns: [
{content: "User prefers window seats", score: 0.92},
{content: "User likes morning flights", score: 0.78}
]
Agent: "I'll look for morning flights with window seats to NYC..."
Benefits
Transparency
Users see memory operations:
Efficiency
Only retrieve when needed:
Control
Agent manages its own memory:
Debuggability
Easy to understand behavior:
Implementation
System Prompt
Instruct agent on memory tool usage:
You have access to memory tools:
Guidelines:
Memory Store
Backend for the tools:
Tool Handler
Process memory tool calls:
function handleMemoryTool(tool, params, userId):
switch tool:
case "remember":
embedding = embed(params.content)
return memory_store.add({
user_id: userId,
content: params.content,
embedding: embedding,
type: params.type,
importance: params.importance,
tags: params.tags,
created_at: now()
})
case "recall":
return memory_store.search({
user_id: userId,
query_embedding: embed(params.query),
filters: {type: params.type},
limit: params.limit
})
case "forget":
return memory_store.delete(params.memory_id)
When to Use
Good Fit
Consider Alternatives
Hybrid Approach
Combine explicit and implicit: