> ## Documentation Index
> Fetch the complete documentation index at: https://phidatainc.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

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

  <Step title="Install dependencies">
    ```bash theme={null}
    uv pip install -U agno openai
    ```
  </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>

  <Step title="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
    ```
  </Step>
</Steps>

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