Core Principle: Keep It Simple

The #1 rule: Let agents use memory naturally, without complex rules.
# ✅ RIGHT: Simple memory tools
agent = YourAgent(
    tools=[memory.remember, memory.recall]
)

# ❌ WRONG: Hardcoded logic
if "important" in user_input:
    memory.remember(user_input)  # Too rigid

The 3 Essential Patterns

1. Keep Tools Simple

# Clean, simple tools
def remember(content):
    return memory.remember(content)

def recall(query):
    return memory.recall(query)

# Agent uses them naturally
agent = Agent(tools=[remember, recall])

2. Store Objects, Not Strings

# ✅ Store structured data
memory.remember({
    "user": "john_doe",
    "preference": "dark_mode",
    "set_date": "2024-03-20"
})

# ❌ Avoid plain strings
memory.remember("John likes dark mode")  # Harder to search

3. Use Clear IDs (When Needed)

# Only set IDs for things you'll retrieve directly
memory.remember(api_config, id="config_v1")
config = memory.get("config_v1")  # Direct access

# Let AgentMind handle IDs for searchable content
memory.remember("User feedback about checkout")  # Auto-ID

Common Patterns That Work

User-Scoped Memory

# Each user gets their own memory space
def create_user_memory(user_id):
    def remember(content):
        return memory.remember(content, user_id=user_id)
    
    def recall(query):
        return memory.recall(query, user_id=user_id)
    
    return remember, recall

# Give each user's agent their own tools
user_memory = create_user_memory("user_123")
agent = Agent(tools=user_memory)

Session Context

# Track conversation context
session_id = str(uuid.uuid4())

# Agent stores context per session
memory.remember(
    {"topic": "debugging React hooks", "session": session_id}
)

# Later, retrieve session context
context = memory.recall("discussion topics", metadata={"session": session_id})

Critical Information

# Mark important stuff
memory.remember(
    content={"api_key": "sk-...", "expires": "2024-12-01"},
    metadata={"critical": True, "type": "credential"}
)

# Agent can prioritize critical memories
critical = memory.recall("critical information")

Real-World Tips

Handle Failures Gracefully

def safe_recall(query, default="No memory found"):
    try:
        result = memory.recall(query)
        return result if result else default
    except:
        return default

# Your agent keeps working even if memory fails
context = safe_recall("user preferences")

Don’t Store Secrets

# ❌ NEVER store sensitive data
memory.remember("password123")  # Don't!
memory.remember("ssn: 123-45-6789")  # Don't!

# ✅ Store references instead
memory.remember("User authenticated successfully")
memory.remember("Payment method on file")

Clean Up Old Memories

# Periodically clean up
memory.forget_before("2023-01-01")  # Remove old data

# Or let your agent decide
if memory.get_stats().total_memories > 10000:
    # Agent decides what to keep
    agent.execute("Clean up old unimportant memories")

Quick Checklist

Do’s ✅

  • Let agents control their memory
  • Store structured data (dicts/objects)
  • Use user_id to segment memories
  • Handle failures gracefully
  • Clean up old memories periodically

Don’ts ❌

  • Hardcode memory rules
  • Store passwords or sensitive data
  • Forget to handle errors
  • Let memory grow infinitely
  • Mix different users’ data

Advanced: Multi-Agent Memory

# Agents can share memory
sales_agent = Agent(tools=[memory.remember, memory.recall])
support_agent = Agent(tools=[memory.recall])  # Read-only

# Sales agent stores customer info
sales_agent: "Customer interested in enterprise plan"

# Support agent can access it
support_agent: memory.recall("customer plan interest")
# "Customer interested in enterprise plan"

Get Help