Skip to main content
team_user_profile.py
"""
Team Learning: User Profile
===========================
Team learns and recalls user profile across sessions.

This demonstrates that Team.add_learnings_to_context works correctly:
- Session 1: Team extracts user profile from conversation
- Session 2: Team recalls profile in new session (different session_id)
"""

from agno.agent import Agent
from agno.db.postgres import PostgresDb
from agno.models.openai import OpenAIResponses
from agno.team import Team

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

researcher = Agent(
    name="Researcher",
    model=OpenAIResponses(id="gpt-5.2"),
    role="Research and provide detailed information.",
)

writer = Agent(
    name="Writer",
    model=OpenAIResponses(id="gpt-5.2"),
    role="Write clear, concise content.",
)

team = Team(
    name="Content Team",
    model=OpenAIResponses(id="gpt-5.2"),
    members=[researcher, writer],
    db=db,
    learning=True,
    markdown=True,
)

if __name__ == "__main__":
    user_id = "profile_test@example.com"

    print("\n" + "=" * 60)
    print("SESSION 1: Share profile information")
    print("=" * 60 + "\n")

    team.print_response(
        "Hi, I'm Marcus. I'm a DevOps engineer at a fintech startup. "
        "I prefer practical examples over theory, and I work primarily with Kubernetes.",
        user_id=user_id,
        session_id="profile_session_1",
        stream=True,
    )

    lm = team.learning_machine
    print("\n--- Extracted Profile ---")
    lm.user_profile_store.print(user_id=user_id)

    print("\n" + "=" * 60)
    print("SESSION 2: Team should recall profile (NEW SESSION)")
    print("=" * 60 + "\n")

    team.print_response(
        "What do you know about me? Keep it brief.",
        user_id=user_id,
        session_id="profile_session_2",
        stream=True,
    )

Run the Example

1

Set up your virtual environment

uv venv --python 3.12
source .venv/bin/activate
uv venv --python 3.12
.venv\Scripts\activate
2

Install dependencies

uv pip install -U agno openai psycopg-binary sqlalchemy
3

Export your OpenAI API key

export OPENAI_API_KEY="your_openai_api_key_here"
$Env:OPENAI_API_KEY="your_openai_api_key_here"
4

Run PgVector

docker run -d \
  -e POSTGRES_DB=ai \
  -e POSTGRES_USER=ai \
  -e POSTGRES_PASSWORD=ai \
  -e PGDATA=/var/lib/postgresql/data/pgdata \
  -v pgvolume:/var/lib/postgresql/data \
  -p 5532:5432 \
  --name pgvector \
  agnohq/pgvector:18
5

Run the example

Save the code above as team_user_profile.py, then run:
python team_user_profile.py
Full source: cookbook/03_teams/12_learning/07_team_user_profile.py