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

# Agent with Memory

> Store user preferences that persist across conversations.

Memory lets your agent remember facts about users across conversations. Unlike storage (which persists conversation history), memory stores user-level information like preferences and context.

**1. Create a Python file**

```python agent_with_memory.py theme={null}
from agno.agent import Agent
from agno.db.sqlite import SqliteDb
from agno.memory import MemoryManager
from agno.models.openai import OpenAIResponses
from agno.tools.yfinance import YFinanceTools
from rich.pretty import pprint

db = SqliteDb(db_file="tmp/agents.db")

memory_manager = MemoryManager(
    model=OpenAIResponses(id="gpt-5.2"),
    db=db,
)

agent = Agent(
    model=OpenAIResponses(id="gpt-5.2"),
    tools=[YFinanceTools(all=True)],
    db=db,
    memory_manager=memory_manager,
    enable_agentic_memory=True,
    markdown=True,
)

user_id = "investor@example.com"

# Tell the agent about yourself
agent.print_response(
    "I'm interested in AI and semiconductor stocks. My risk tolerance is moderate.",
    user_id=user_id,
    stream=True,
)

# The agent now knows your preferences
agent.print_response(
    "What stocks would you recommend for me?",
    user_id=user_id,
    stream=True,
)

# View stored memories
memories = agent.get_user_memories(user_id=user_id)
print("\nStored Memories:")
pprint(memories)
```

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

**2. Install dependencies**

```bash theme={null}
uv pip install -U agno openai yfinance sqlalchemy rich
```

**3. Export your OpenAI API key**

```bash Mac/Linux theme={null}
export OPENAI_API_KEY="your_openai_api_key_here"
```

```powershell Windows theme={null}
$Env:OPENAI_API_KEY="your_openai_api_key_here"
```

**4. Run Agent**

```bash theme={null}
python agent_with_memory.py
```

## Memory vs Storage

| Feature | Storage | Memory |
| - | - | - |
| What it stores | Conversation history | User preferences and facts |
| Scope | Per session | Per user (across all sessions) |
| Use case | "What did we discuss?" | "What do you know about me?" |

## Enabling Memory

1. **`enable_agentic_memory=True`** (used above): Adds an `update_user_memory` tool. The model decides whether to call it. Existing memories are added to context.
2. **`update_memory_on_run=True`**: Runs the memory manager for each non-empty user input. This adds a model call and does not guarantee that every detail becomes a memory.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.