enable_agentic_memory=True to give an agent the update_user_memory tool. Passing MemoryManager(delete_memories=True) lets the tool delete memories for the current user_id, in addition to adding and updating them.
Code
agentic_memory.py
from agno.agent import Agent
from agno.db.postgres import PostgresDb
from agno.memory import MemoryManager
from agno.models.openai import OpenAIResponses
from rich.pretty import pprint
db_url = "postgresql+psycopg://ai:ai@localhost:5532/ai"
db = PostgresDb(db_url=db_url)
john_doe_id = "john_doe@example.com"
agent = Agent(
model=OpenAIResponses(id="gpt-5.2"),
db=db,
memory_manager=MemoryManager(delete_memories=True),
enable_agentic_memory=True,
)
agent.print_response(
"My name is John Doe and I like to hike in the mountains on weekends.",
stream=True,
user_id=john_doe_id,
)
agent.print_response("What are my hobbies?", stream=True, user_id=john_doe_id)
memories = agent.get_user_memories(user_id=john_doe_id)
print("Memories about John Doe:")
pprint(memories)
agent.print_response(
"Remove all existing memories of me.",
stream=True,
user_id=john_doe_id,
)
memories = agent.get_user_memories(user_id=john_doe_id)
print("Memories about John Doe:")
pprint(memories)
agent.print_response(
"My name is John Doe and I like to paint.", stream=True, user_id=john_doe_id
)
memories = agent.get_user_memories(user_id=john_doe_id)
print("Memories about John Doe:")
pprint(memories)
agent.print_response(
"I don't paint anymore. I draw instead.", stream=True, user_id=john_doe_id
)
memories = agent.get_user_memories(user_id=john_doe_id)
print("Memories about John Doe:")
pprint(memories)
Usage
1
Set up your virtual environment
uv venv --python 3.12
source .venv/bin/activate
uv venv --python 3.12
.venv\Scripts\activate
2
Set your API key
export OPENAI_API_KEY=xxx
3
Install dependencies
uv pip install -U agno openai sqlalchemy 'psycopg[binary]'
4
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
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
5
Run example
python agentic_memory.py