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

# Media Storage Across Turns

> Read offloaded media back from storage across multiple turns of a session.

Demonstrates a multi-turn conversation over offloaded media.

```python media_storage_multiturn.py theme={null}
"""
Multi-turn Media Storage
========================

Demonstrates a multi-turn conversation over offloaded media. Turn 1 uploads the image to S3
and keeps only a MediaReference; turn 2 asks about it without re-attaching it. The stored
reference is re-signed on read, so the model fetches the image from S3 and the bytes never
travel back through the database.

store=False keeps history client-side; OpenAIResponses would otherwise chain turns via
previous_response_id and turn 2 would send no image at all.

Requirements:
- uv pip install 'agno[s3]'
- AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, AWS_REGION
- Set MEDIA_S3_BUCKET to the destination bucket
"""

import os

import httpx
from agno.agent import Agent
from agno.db.sqlite import SqliteDb
from agno.media import Image
from agno.media.storage import S3MediaStorage
from agno.models.openai import OpenAIResponses

# ---------------------------------------------------------------------------
# Setup
# ---------------------------------------------------------------------------
DB_FILE = "tmp/multiturn.db"
IMAGE_URL = "https://picsum.photos/id/15/800/600.jpg"

bucket = os.getenv("MEDIA_S3_BUCKET")
if not bucket:
    raise ValueError("MEDIA_S3_BUCKET must be set to the destination S3 bucket")

storage = S3MediaStorage(
    bucket=bucket,
    region=os.getenv("AWS_REGION"),
    prefix="agno/media/",
    presigned_url_expiry=3600,  # 1 hour
)

# ---------------------------------------------------------------------------
# Create the Agent
# ---------------------------------------------------------------------------
agent = Agent(
    model=OpenAIResponses(
        id="gpt-5.5", store=False
    ),  # keep history client-side, see docstring
    media_storage=storage,
    db=SqliteDb(db_file=DB_FILE),
    session_id="multiturn-session",
    add_history_to_context=True,
)

# ---------------------------------------------------------------------------
# Run the Agent
# ---------------------------------------------------------------------------
if __name__ == "__main__":
    image_bytes = httpx.get(IMAGE_URL, follow_redirects=True).content

    # Turn 1: send the image and ask about it
    agent.print_response(
        "What do you see in this image?",
        images=[Image(content=image_bytes, format="jpeg", mime_type="image/jpeg")],
    )

    # Turn 2: ask again without re-attaching it — the reference is re-signed for the model
    agent.print_response("What was the image about?")
```

## Run the Example

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

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

  <Step title="Export your AWS credentials">
    <CodeGroup>
      ```bash Mac/Linux theme={null}
      export AWS_ACCESS_KEY_ID="your_key_id"
      export AWS_SECRET_ACCESS_KEY="your_secret"
      export AWS_REGION="us-east-1"
      export MEDIA_S3_BUCKET="your_bucket"
      ```

      ```bash Windows theme={null}
      $Env:AWS_ACCESS_KEY_ID="your_key_id"
      $Env:AWS_SECRET_ACCESS_KEY="your_secret"
      $Env:AWS_REGION="us-east-1"
      $Env:MEDIA_S3_BUCKET="your_bucket"
      ```
    </CodeGroup>
  </Step>

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

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

Full source: [cookbook/06\_storage/07\_media\_storage\_multiturn.py](https://github.com/agno-agi/agno/blob/main/cookbook/06_storage/07_media_storage_multiturn.py)
