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

# Microsoft Agent Framework and AutoGen

> Keep Microsoft Agent Framework workflow checkpoints in FileCheckpointStorage on an Archil disk, so a failed workflow resumes on another machine. Also covers AutoGen save_state.

[Microsoft Agent Framework](https://learn.microsoft.com/en-us/agent-framework/workflows/checkpoints) workflows save a checkpoint at the end of every superstep: each executor's state, the messages waiting for the next step, and shared state. `FileCheckpointStorage` writes those checkpoints as files to a directory you choose, and Microsoft describes it as storage for single-machine workflows. Put that directory on an Archil disk, and a workflow that stops on one machine resumes on another from its last checkpoint, without repeating the steps that already finished.

> [!NOTE]
>
> Run one machine against a checkpoint directory at a time. To run many workflows at once, give each its own
> directory or disk. For checkpoints that many processes write concurrently, Microsoft's docs recommend
> `CosmosCheckpointStorage` on Azure Cosmos DB; keep the files your executors write on the disk either way.

## 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 workflow:

> [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="agent-framework-workflow",
>     base_image="python:3.13",
>     mounts=[archil.SandboxMountSpec(disk="dsk-0123456789abcdef", path="/mnt/archil")],
> )
> ```

## Point checkpoint storage at the disk

Install Agent Framework:

```bash theme={null}
pip install agent-framework
```

This workflow has two executors. `Gather` stands in for a slow step, such as an agent researching a topic, and writes `sources.md`. `Write` writes the report, and fails when `CRASH=1` is set, to show what happens when a machine stops partway through. On start, the script resumes from the latest checkpoint if there is one:

```python workflow.py theme={null}
import asyncio
import os
from pathlib import Path

from agent_framework import (
    Executor,
    FileCheckpointStorage,
    WorkflowBuilder,
    WorkflowContext,
    handler,
)

ROOT = Path("/mnt/archil/agent-framework")
CHECKPOINTS = ROOT / "checkpoints"
WORK = ROOT / "work"
CHECKPOINTS.mkdir(parents=True, exist_ok=True)
WORK.mkdir(parents=True, exist_ok=True)


class Gather(Executor):
    @handler
    async def gather(self, topic: str, ctx: WorkflowContext[str]) -> None:
        # A slow step, such as an agent researching the topic.
        (WORK / "sources.md").write_text(f"sources for {topic}\n")
        print("gather: wrote sources.md")
        await ctx.send_message(topic)


class Write(Executor):
    @handler
    async def write(self, topic: str, ctx: WorkflowContext[None, str]) -> None:
        if os.environ.get("CRASH") == "1":
            raise RuntimeError("simulated crash before writing")
        (WORK / "report.md").write_text(f"report on {topic}\n")
        print("write: wrote report.md")
        await ctx.yield_output("report.md")


def build(storage: FileCheckpointStorage):
    gather, write = Gather(id="gather"), Write(id="write")
    return (
        WorkflowBuilder(name="report", start_executor=gather, checkpoint_storage=storage)
        .add_edge(gather, write)
        .build()
    )


async def main() -> None:
    storage = FileCheckpointStorage(str(CHECKPOINTS))
    workflow = build(storage)
    latest = await storage.get_latest(workflow_name=workflow.name)
    try:
        if latest is None:
            result = await workflow.run("archil")
        else:
            print("resuming from checkpoint", latest.checkpoint_id)
            result = await workflow.run(checkpoint_id=latest.checkpoint_id)
        print("outputs:", result.get_outputs())
    except Exception as e:
        print("workflow failed:", e)
    print("checkpoints on disk:", len(await storage.list_checkpoints(workflow_name=workflow.name)))


asyncio.run(main())
```

Run it with the crash turned on. `Gather` finishes and its superstep is checkpointed, then `Write` fails:

```bash theme={null}
CRASH=1 python3 workflow.py
```

```text theme={null}
gather: wrote sources.md
workflow failed: simulated crash before writing
checkpoints on disk: 2
```

## Resume 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. Then run the workflow again:

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

# On the second machine, after mounting the disk as above
python3 workflow.py
```

The new machine resumes from the checkpoint after `Gather`, so only `Write` runs:

```text theme={null}
resuming from checkpoint b61a1ebf-8344-498d-a39c-a9913ead8508
write: wrote report.md
outputs: ['report.md']
checkpoints on disk: 3
```

Once a workflow has finished, its latest checkpoint is the finished one. Start the next run under a new workflow name or in a new checkpoint directory.

## What's on the disk

| Path | Written by | What it holds |
| - | - | - |
| `/mnt/archil/agent-framework/checkpoints/` | `FileCheckpointStorage` | One JSON file per checkpoint. Non-JSON values are pickled, and Agent Framework restricts which types it will load; see [security considerations](https://learn.microsoft.com/en-us/agent-framework/workflows/checkpoints#security-considerations). |
| `/mnt/archil/agent-framework/work/` | Your executors | The files the workflow produces. Checkpoints hold the workflow's state, not these files, so keep them on the disk too. |

Checkpoint storage is trusted state: anyone who can write the checkpoint directory can change what the workflow loads. A disk's credentials are scoped to that disk, so give each tenant [its own disk](https://docs.archil.com/guides/storage/per-tenant-storage.md).

## AutoGen

AutoGen's README says the project is in maintenance mode and points new users to Microsoft Agent Framework. If you still run AutoGen AgentChat, `save_state()` on an agent or team returns a dictionary that, per [AutoGen's docs](https://microsoft.github.io/autogen/stable/user-guide/agentchat-user-guide/tutorial/state.html), can be serialized to a file or written to a database. Write it as a JSON file under `/mnt/archil`, and call `load_state()` with it on the next machine. The one-writer rule below applies the same way.

## 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, and two machines can't resume the same workflow at once. A second `archil mount` while the disk is mounted elsewhere stops with a message about revoking the other client's delegations.

To run many workflows at once, give each workflow, tenant or task its own disk. For checkpoints that many processes share, use `CosmosCheckpointStorage`, 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 the OpenAI Agents SDK keep in files.

> [card] [Temporal](https://docs.archil.com/guides/agents/temporal.md)
>
> Durable workflows, with each activity in its own sandbox and its files on a disk.

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