> ## 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 Storage

> Persist conversation history across runs.

Storage lets your agent remember conversations. With the same `session_id`, it picks up where you left off, even after restarting.

**1. Create a Python file**

```python agent_with_storage.py theme={null}
from agno.agent import Agent
from agno.db.sqlite import SqliteDb
from agno.models.openai import OpenAIResponses
from agno.tools.yfinance import YFinanceTools

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

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

session_id = "finance-session"

# Turn 1: Analyze a stock
agent.print_response(
    "Give me a quick analysis of NVIDIA",
    session_id=session_id,
    stream=True,
)

# Turn 2: The agent remembers NVDA from turn 1
agent.print_response(
    "Compare that to AMD",
    session_id=session_id,
    stream=True,
)

# Turn 3: Ask based on full conversation
agent.print_response(
    "Which looks like the better investment?",
    session_id=session_id,
    stream=True,
)
```

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

**2. Install dependencies**

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

**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_storage.py
```

## Key Concepts

* **Session:** A conversation thread identified by `session_id`
* **Same `session_id` = continuous conversation**, even across script runs
* **`add_history_to_context=True`:** Includes previous messages in context
* **`num_history_runs=5`:** Number of previous runs to include


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