- Building a minimal FastAPI app with a Upsonic agent using async endpoints and
agent.do_async() - Containerizing with Docker
- Running locally
Why async with FastAPI
FastAPI is async-native. Useagent.do_async() in your route handlers so the event loop is not blocked during LLM and tool calls. That keeps the server responsive under concurrent requests.
Setup
Create a new directory for your project
Create a new directory and navigate into it:Resulting structure:
Step 1: Create the FastAPI app
Step 2: Docker
Step 3: Structured responses (async)
Use Pydantic models andagent.do_async() with response_format for typed JSON responses.
Key takeaways
- Use async route handlers and
await agent.do_async(task)so FastAPI’s event loop stays non-blocking. - Use
response_format=YourPydanticModelwhen you need structured JSON. - Run in production with
uv run uvicorn main:app --host 0.0.0.0 --port 8000or via Docker as above.

