> For the complete documentation index, see [llms.txt](/llms.txt).
> A full single-fetch corpus is available at [llms-full.txt](/llms-full.txt).
---
title: Add AGNT5 to FastAPI
description: Mount AGNT5 serverless workflows in an existing FastAPI application and sync its deployed release.
last_verified: 2026-08-25
---

The Python ASGI adapter adds AGNT5 manifest and invoke routes without taking over your existing FastAPI application. AGNT5 calls those routes instead of maintaining a persistent worker connection.

## 1. Mount the adapter

Install the Python beta and mount the generated adapter:

```bash
uv add agnt5 fastapi 'uvicorn[standard]'
agnt5 serverless init \
  --provider http \
  --runtime python \
  --name orders-api
```

The generated module follows this pattern:

```python
import os
from fastapi import FastAPI
from agnt5 import workflow
from agnt5.serverless import serve

app = FastAPI()

@workflow
async def hello(ctx, name: str = "world") -> dict[str, str]:
    return {"message": f"hello {name}"}

agnt5_serverless = serve(
    service_name="orders-api",
    service_version=os.getenv("GIT_SHA", "local"),
    signing_secret=lambda: os.getenv("AGNT5_SERVERLESS_SIGNING_SECRET"),
)
agnt5_serverless.mount_fastapi(app)
```

## 2. Validate locally

```bash
export AGNT5_SERVERLESS_SIGNING_SECRET="$(openssl rand -base64 32)"
uv run uvicorn agnt5_serverless:app --host 127.0.0.1 --port 8787
agnt5 serverless validate http://127.0.0.1:8787
```

Run validation from a second terminal while Uvicorn remains active.

## 3. Deploy and sync

Deploy the ASGI service to an HTTPS host and configure the same signing secret there. Import the immutable release without activating it:

```bash
agnt5 serverless sync https://<fastapi-host> \
  --provider http \
  --immutable-ref <git-sha-or-release-id> \
  --signing-secret-env AGNT5_SERVERLESS_SIGNING_SECRET \
  --activate=false
```

`--provider fastapi` and `--provider python` remain compatibility aliases for `--provider http --runtime python`. Verify the deployment before repeating sync with `--activate=true`.

## Next steps

- [Serverless SDK reference](/docs/run/serverless-sdk-reference.md): use Python durable steps, timers, user input, and events.
- [Integrate Python web frameworks](/docs/integrations/python-web-frameworks.md): add the adapter to Starlette, Flask, Django, ASGI, or WSGI.
- [Deploy to Cloud Run](/docs/integrations/cloud-run-serverless.md): deploy the generated FastAPI service as an immutable revision.
- [Operate serverless endpoints](/docs/run/operate-serverless-endpoints.md): promote and recover releases safely.
- [Serverless CLI reference](/docs/cli/serverless.md): inspect sync and validation flags.
