Agent Memory

Store and recall user-specific facts across agent runs.

The local database setup below requires Docker. Use a disposable database: this example calls db.clear_memories(), which clears the entire memory table, including other users' records.

Agent memory stores user-specific facts in a database and recalls them in later runs.

User Memories

Set enable_agentic_memory=True to let the agent decide when to create or update memories:

Install dependencies and set your key before running the examples:

pip install agno openai "psycopg[binary]" sqlalchemy
export OPENAI_API_KEY="your-api-key"

Run PgVector

docker run -d \
  -e POSTGRES_DB=ai \
  -e POSTGRES_USER=ai \
  -e POSTGRES_PASSWORD=ai \
  -e PGDATA=/var/lib/postgresql \
  -v pgvolume:/var/lib/postgresql \
  -p 5532:5432 \
  --name pgvector \
  agnohq/pgvector:18
memory_demo.py
from agno.agent import Agent
from agno.models.openai import OpenAIResponses
from agno.db.postgres import PostgresDb
from rich.pretty import pprint

user_id = "ava"

db_url = "postgresql+psycopg://ai:ai@localhost:5532/ai"

db = PostgresDb(
    db_url=db_url,
    memory_table="user_memories",
)


memory_agent = Agent(
    model=OpenAIResponses(id="gpt-5.2"),
    db=db,
    enable_agentic_memory=True,
    # Alternatively, run MemoryManager during each run:
    # update_memory_on_run=True,
    markdown=True,
)

db.clear_memories()

memory_agent.print_response(
    "My name is Ava and I like to ski.",
    user_id=user_id,
    stream=True,
)
print("Memories about Ava:")
pprint(memory_agent.get_user_memories(user_id=user_id))

memory_agent.print_response(
    "I live in San Francisco. Where should I move within a four-hour drive?",
    user_id=user_id,
    stream=True,
)
print("Memories about Ava:")
pprint(memory_agent.get_user_memories(user_id=user_id))

enable_agentic_memory=True gives the agent one update_user_memory tool backed by MemoryManager. Set update_memory_on_run=True to start automatic extraction concurrently with the main model call instead. It processes the current input, and successful run completion waits for that background work.

Developer Resources