> ## Documentation Index
> Fetch the complete documentation index at: https://docs.archil.com/llms.txt
> Use this file to discover all available pages before exploring further.

# OpenAI Agents SDK

> Keep OpenAI Agents SDK conversation history in a SQLiteSession file on an Archil disk, so a session continues on any machine or sandbox.

The [OpenAI Agents SDK](https://openai.github.io/openai-agents-python/sessions/) keeps a conversation's history in a session. `SQLiteSession` is in memory unless you give it a file path, and then it writes every item of every session to that SQLite file. Put the file on an Archil disk, and a conversation started in one sandbox continues in another, with the agent's files next to it.

> [!NOTE]
>
> SQLite takes one writing machine per database file. Mount the disk on one machine at a time, as below, or give each
> agent its own disk. If many workers on different machines serve the same sessions at once, use a database-backed
> session such as `SQLAlchemySession` on Postgres or `RedisSession`, and keep the files on the disk.

## Mount a disk

Create a disk in the [Archil console](https://console.archil.com) and save a [disk token](https://docs.archil.com/concepts/authorization.md#token-based-disk-authorization) for it. Then mount it on the machine that runs the agent:

> [tab] Any Linux host
>
> Your own server, a container with FUSE access, or another provider's sandbox. See [Mount on Linux](https://docs.archil.com/mounting/linux.md) for the requirements.
>
> ```bash theme={null}
> curl -s https://archil.com/install | sh
> export ARCHIL_MOUNT_TOKEN="<disk-token>"
> sudo mkdir -p /mnt/archil
> sudo --preserve-env=ARCHIL_MOUNT_TOKEN archil mount dsk-0123456789abcdef /mnt/archil --region aws-us-west-2
> ```

> [tab] Archil sandbox
>
> Pass the disk in `mounts` when you create the [sandbox](https://docs.archil.com/compute/sandboxes/introduction.md#attaching-an-archil-disk), and Archil mounts it for you:
>
> ```python theme={null}
> import archil
>
> sandbox = archil.create_sandbox(
>     name="openai-agent",
>     base_image="python:3.13",
>     mounts=[archil.SandboxMountSpec(disk="dsk-0123456789abcdef", path="/mnt/archil")],
> )
> ```

## Give the session a file on the disk

Install the SDK and export your OpenAI API key:

```bash theme={null}
pip install openai-agents
export OPENAI_API_KEY=sk-...
```

Pass a path on the disk as the session's database file. Each `session_id`, here a user ID, is its own conversation in that file:

```python agent.py theme={null}
import asyncio
import sys
from pathlib import Path

from agents import Agent, Runner, SQLiteSession

DB = Path("/mnt/archil/openai-agents/sessions.db")
DB.parent.mkdir(parents=True, exist_ok=True)

agent = Agent(name="Assistant", instructions="Reply in one sentence.")


async def main(user_id: str, message: str) -> None:
    session = SQLiteSession(user_id, str(DB))
    result = await Runner.run(agent, message, session=session)
    print(result.final_output)
    print("items in session:", len(await session.get_items()))


asyncio.run(main(sys.argv[1], sys.argv[2]))
```

Run two turns of the same session:

```bash theme={null}
python3 agent.py user-123 "My name is Ada."
python3 agent.py user-123 "What is my name?"
```

The model's replies vary. Each turn adds the user's message and the agent's reply to the session, so the second run sends the first exchange along with the new question:

```text theme={null}
items in session: 2
items in session: 4
```

## Continue on another machine

Unmount the disk, which flushes every write to Archil, and mount it on a different machine. In an Archil sandbox, stopping or deleting the sandbox does the same; the disk and its data are kept.

```bash theme={null}
# On the first machine
sudo archil unmount /mnt/archil

# On the second machine, after mounting the disk as above
python3 agent.py user-123 "Summarize our chat."
```

The session's earlier turns come from the file on the disk, so the model sees all three user messages:

```text theme={null}
items in session: 6
```

## What's on the disk

| Path | Written by | What it holds |
| - | - | - |
| `/mnt/archil/openai-agents/sessions.db` | `SQLiteSession` | Every item of every session, by `session_id`: user messages, agent replies and tool calls. |
| Anything else under `/mnt/archil` | Your tools | Files the agent creates or edits. Point file tools at the disk so they persist with the conversation. |

## One writer at a time

By default, a mount takes [exclusive access](https://docs.archil.com/concepts/sharing-disks.md) to the disk, so a second machine can't mount it for writing while the first one has it. That's what SQLite needs: its file locks don't extend across machines. A second `archil mount` while the disk is mounted elsewhere stops with a message about revoking the other client's delegations.

To run many agents at once, give each agent, tenant or user [its own disk](https://docs.archil.com/guides/storage/per-tenant-storage.md), each with its own `sessions.db`. If many workers on different machines need the same sessions at the same time, use `SQLAlchemySession` with Postgres or `RedisSession`, listed in the SDK's [sessions docs](https://openai.github.io/openai-agents-python/sessions/), and keep the files on the disk.

## Next steps

> [card] [Agent frameworks](https://docs.archil.com/guides/agents/agent-frameworks.md)
>
> What LangGraph, CrewAI and Microsoft Agent Framework keep in files.

> [card] [Code interpreter](https://docs.archil.com/guides/agents/code-interpreter.md)
>
> A Python kernel that keeps its state in a persistent sandbox.

> [card] [Sharing disks](https://docs.archil.com/concepts/sharing-disks.md)
>
> Exclusive, shared and conditional mounts.

> [card] [Per-tenant storage](https://docs.archil.com/guides/storage/per-tenant-storage.md)
>
> One disk per tenant, provisioned through the API.


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