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.

Diagram

With Memory

👤 I’m Alex

💾 Saved

❓ Who am I?

🤖 You’re Alex!

Without Memory

❓ Who am I?

🤖 I don’t know


Quick Start

python
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

Diagram

Memory Types

💬 Short-Term
Current conversation

💾 Long-Term
Across sessions

📚 Knowledge
Documents & data

🤖 Agent


Memory Options

  1. Basic Memory (Conversation)
    python
    agent = Agent(
        instructions="You are helpful",
        memory=True  # Remembers the conversation
    )
  2. Long-Term Memory (Persistent)
    python
    agent = Agent(
        instructions="You are a personal assistant",
        memory={
            "provider": "sqlite",  # Store in database
            "db_path": "memory.db"
        }
    )
  3. Knowledge Memory (Documents)
    python
    agent = Agent(
        instructions="Answer from documents",
        knowledge=["docs/"],  # Load documents
        memory=True
    )

How Memory Works

Diagram

Memory Flow

📥 Your Message

🧠 Process

💾 Memory

💬 Response

💾 Save to Memory

StepWhat Happens
InputYou send a message
RetrieveAgent checks memory for context
ProcessCombines memory + new input
RespondGenerates informed response
SaveStores important info for later

Complete Example

python
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 Python

Multi-Agent Memory

Agents can share memory or have private memory:

Diagram

Shared Memory

🤖 Agent 1

💾 Shared Memory

🤖 Agent 2

python
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


Next: Multi-Agent Systems

Learn how multiple agents work together.