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

# Media Storage Across Turns

> Read successfully offloaded S3 media across multiple turns of one session.

Run a second turn against media that a successful first-turn upload stored in S3.

> [!WARNING]
>
> This example does not assert that offload succeeded. A storage failure can leave inline media in the persisted run, so verify the MediaReference and S3 object before using it as a read-back test.

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

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

**1. Install dependencies**

```bash theme={null}
uv pip install -U "agno[s3]" openai sqlalchemy
```

**2. Export environment variables**

```bash Mac/Linux theme={null}
export AWS_REGION="your_aws_region_here"
export MEDIA_S3_BUCKET="your_media_s3_bucket_here"
export OPENAI_API_KEY="your_openai_api_key_here"
```

```bash Windows theme={null}
$Env:AWS_REGION="your_aws_region_here"
$Env:MEDIA_S3_BUCKET="your_media_s3_bucket_here"
$Env:OPENAI_API_KEY="your_openai_api_key_here"
```

**3. Configure AWS credentials**

Configure the AWS SDK default credential chain with environment variables, a shared credentials file, or an IAM role.

**4. Run the example**

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

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

**5. Verify the offload**

Confirm that the first stored run contains a MediaReference and that its storage key exists in the S3 bucket before treating the second turn as an S3 read-back test.

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


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