Deploying
Your app is a standard ASGI application, so it deploys like any FastAPI service:
run uvicorn main:app in a container. PyAgentic can generate a Dockerfile for
you from agents.toml.
The [deploy] section
Add a [deploy] section to agents.toml (beside your pyproject.toml):
[deploy]
target = "main:app" # the ASGI app uvicorn serves
python_version = "3.13"
dependencies = [] # extra pip packages to install in the image
port = 8000
env = ["OPENAI_API_KEY"] # environment variables required at runtime
Generating a Dockerfile
from pyagentic.api import write_dockerfile
write_dockerfile() # reads ./agents.toml, writes ./Dockerfile
Or get the contents as a string with generate_dockerfile(). The generated
Dockerfile installs your project and runs it with uvicorn:
FROM python:3.13-slim
WORKDIR /app
RUN pip install uv
RUN uv pip install --system "pyagentic-core[api]"
COPY . .
EXPOSE 8000
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000"]
Extra [deploy].dependencies are installed as an additional step:
Building and running
Build and run with your normal Docker tooling:
Pass secrets via --env-file or -e (the variables you listed in
[deploy].env):
!!! tip "Durable jobs in a container"
If you use async jobs, set [jobs].store to a path on a mounted
volume so job records survive container restarts. The default
.pyagentic/jobs.db lives in the container's filesystem and is lost when the
container is removed.
Next steps
- Review async jobs for long-running deployments
- Explore observability to trace agents in production