> ## Documentation Index
> Fetch the complete documentation index at: https://docs.agno.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Team Learning: User Memory

> Team learns observations and context about the user across sessions.

```python team_user_memory.py theme={null}
"""
Team Learning: User Memory
==========================
Team learns observations and context about the user across sessions.

User memory captures:
- Observations about the user's situation
- Context from conversations
- Patterns in user behavior
"""

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")

analyst = Agent(
    name="Analyst",
    model=OpenAIResponses(id="gpt-5.2"),
    role="Analyze data and provide insights.",
)

advisor = Agent(
    name="Advisor",
    model=OpenAIResponses(id="gpt-5.2"),
    role="Provide strategic recommendations.",
)

team = Team(
    name="Strategy Team",
    model=OpenAIResponses(id="gpt-5.2"),
    members=[analyst, advisor],
    db=db,
    learning=True,
    markdown=True,
)

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

    print("\n" + "=" * 60)
    print("SESSION 1: Share context about current situation")
    print("=" * 60 + "\n")

    team.print_response(
        "We're preparing for a Series A raise. Our MRR is $50K, growing 15% month-over-month. "
        "Main challenge is our CAC is too high relative to LTV.",
        user_id=user_id,
        session_id="memory_session_1",
        stream=True,
    )

    lm = team.learning_machine
    print("\n--- Extracted Memories ---")
    lm.user_memory_store.print(user_id=user_id)

    print("\n" + "=" * 60)
    print("SESSION 2: Follow up (team should remember context)")
    print("=" * 60 + "\n")

    team.print_response(
        "Given what you know about our situation, what metrics should we focus on improving?",
        user_id=user_id,
        session_id="memory_session_2",
        stream=True,
    )
```

## Run the Example

<Steps>
  <Snippet file="create-venv-step.mdx" />

  <Step title="Install dependencies">
    ```bash theme={null}
    uv pip install -U agno openai psycopg-binary sqlalchemy
    ```
  </Step>

  <Step title="Export your OpenAI API key">
    <CodeGroup>
      ```bash Mac/Linux theme={null}
      export OPENAI_API_KEY="your_openai_api_key_here"
      ```

      ```bash Windows theme={null}
      $Env:OPENAI_API_KEY="your_openai_api_key_here"
      ```
    </CodeGroup>
  </Step>

  <Snippet file="run-pgvector-step.mdx" />

  <Step title="Run the example">
    Save the code above as `team_user_memory.py`, then run:

    ```bash theme={null}
    python team_user_memory.py
    ```
  </Step>
</Steps>

Full source: [cookbook/03\_teams/12\_learning/08\_team\_user\_memory.py](https://github.com/agno-agi/agno/blob/main/cookbook/03_teams/12_learning/08_team_user_memory.py)
