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

# In Memory Storage for Agent

> Keep agent sessions in an in-memory database that clears when the process exits.

```python in_memory_storage_for_agent.py theme={null}
"""Run `uv pip install ddgs openai` to install dependencies."""

from agno.agent import Agent
from agno.db.in_memory import InMemoryDb

# ---------------------------------------------------------------------------
# Setup
# ---------------------------------------------------------------------------
db = InMemoryDb()

# ---------------------------------------------------------------------------
# Create Agent
# ---------------------------------------------------------------------------
agent = Agent(db=db)

# ---------------------------------------------------------------------------
# Run Agent
# ---------------------------------------------------------------------------
if __name__ == "__main__":
    # The Agent sessions will now be stored in the in-memory database
    agent.print_response("Give me an easy and healthy dinner recipe")
```

## Run the Example

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

**1. Install dependencies**

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

**2. Export your OpenAI API key**

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

**3. Run the example**

Save the code above as `in_memory_storage_for_agent.py`, then run:

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

Full source: [cookbook/06\_storage/in\_memory/in\_memory\_storage\_for\_agent.py](https://github.com/agno-agi/agno/blob/v3.0.4/cookbook/06_storage/in_memory/in_memory_storage_for_agent.py)


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