Agent Memory
Understanding how agents maintain context and learn
Memory lets agents remember conversations and learn from past interactions. Without memory, every message is like starting fresh.
Quick Start
from praisonaiagents import Agent
# Enable memory with one parameter
agent = Agent(
instructions="You are a personal assistant",
memory=True # Remember conversations
)
agent.start("My name is Alex and I love Python")
# Later...
agent.start("What's my name?") # Agent remembers: "Alex"Types of Memory
Memory Options
- Basic Memory (Conversation)
python agent = Agent( instructions="You are helpful", memory=True # Remembers the conversation ) - Long-Term Memory (Persistent)
python agent = Agent( instructions="You are a personal assistant", memory={ "provider": "sqlite", # Store in database "db_path": "memory.db" } ) - Knowledge Memory (Documents)
python agent = Agent( instructions="Answer from documents", knowledge=["docs/"], # Load documents memory=True )
How Memory Works
| Step | What Happens |
|---|---|
| Input | You send a message |
| Retrieve | Agent checks memory for context |
| Process | Combines memory + new input |
| Respond | Generates informed response |
| Save | Stores important info for later |
Complete Example
from praisonaiagents import Agent
# Personal assistant with memory
assistant = Agent(
name="PersonalAssistant",
instructions="""You are a personal assistant.
Remember user preferences and past conversations.
Be helpful and personalized.""",
memory=True
)
# First conversation
assistant.start("I prefer short, bullet-point answers")
assistant.start("My favorite programming language is Python")
# Later conversation - agent remembers!
assistant.start("Explain how to read a file")
# Agent will give short, bullet-point answer about PythonMulti-Agent Memory
Agents can share memory or have private memory:
from praisonaiagents import Agent, AgentTeam
# Agents with shared memory
researcher = Agent(instructions="Research topics", memory=True)
writer = Agent(instructions="Write summaries", memory=True)
team = AgentTeam(
agents=[researcher, writer],
memory=True # Shared team memory
)Best Practices
Start Simple
Use memory=True first, add complexity later
Tell the agent what to remember in instructions
Use KnowledgeFor documents, use knowledge= not memory
Verify the agent remembers correctly
Next: Multi-Agent Systems
Learn how multiple agents work together.