Team With Memory Manager

Demonstrates persistent team memory updates through MemoryManager.

team_with_memory_manager.py
"""
Team With Memory Manager
========================

Demonstrates persistent team memory updates through MemoryManager.
"""

from uuid import uuid4

from agno.agent import Agent
from agno.db.postgres import PostgresDb
from agno.memory import MemoryManager
from agno.models.openai import OpenAIResponses
from agno.team import Team
from rich.pretty import pprint

# ---------------------------------------------------------------------------
# Setup
# ---------------------------------------------------------------------------
db_url = "postgresql+psycopg://ai:ai@localhost:5532/ai"
db = PostgresDb(db_url=db_url)

session_id = str(uuid4())
john_doe_id = "john_doe@example.com"

memory_manager = MemoryManager(model=OpenAIResponses(id="gpt-5-mini"))
memory_manager.clear()

# ---------------------------------------------------------------------------
# Create Members
# ---------------------------------------------------------------------------
agent = Agent(
    model=OpenAIResponses(id="gpt-5-mini"),
)

# ---------------------------------------------------------------------------
# Create Team
# ---------------------------------------------------------------------------
team = Team(
    model=OpenAIResponses(id="gpt-5-mini"),
    memory_manager=memory_manager,
    members=[agent],
    db=db,
    update_memory_on_run=True,
)

# ---------------------------------------------------------------------------
# Run Team
# ---------------------------------------------------------------------------
if __name__ == "__main__":
    team.print_response(
        "My name is John Doe and I like to hike in the mountains on weekends.",
        stream=True,
        user_id=john_doe_id,
        session_id=session_id,
    )
    team.print_response(
        "What are my hobbies?",
        stream=True,
        user_id=john_doe_id,
        session_id=session_id,
    )

    memories = team.get_user_memories(user_id=john_doe_id)
    print("John Doe's memories:")
    pprint(memories)

Example behavior

The early memory_manager.clear() call has no effect because the manager has no database yet. Agno supplies team.db to the manager during initialization. Remove the early call; existing records for the same user can remain across script invocations. update_memory_on_run=True then runs model-based memory extraction, and get_user_memories(user_id=...) shows what was stored.

Run the Example

Set up your virtual environment

uv venv --python 3.12
source .venv/bin/activate

Install dependencies

uv pip install -U agno "psycopg[binary]" openai sqlalchemy

Export your OpenAI API key

export OPENAI_API_KEY="your_openai_api_key_here"

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

Run the example

Save the code above as team_with_memory_manager.py, then run:

python team_with_memory_manager.py

Full source: cookbook/03_teams/06_memory/01_team_with_memory_manager.py