Required Environment Variables
Before deploying, ensure these are set in your production environment:| Variable | Required | Description |
|---|---|---|
OPENAI_API_KEY | Yes | Your OpenAI API key |
APP_TOKEN | Recommended | Authentication token for FastAPI endpoints |
Thread persistence uses callbacks you define to store threads in any database you choose.
This guide assumes you have already created an agency. If you haven’t, check out the Getting Started guide.
Deployment Process
Step 1: Persist Conversation Threads
By default, every time you create a new Chat persistence is handled through callback functions passed to the Agency constructor:
Agency(), it starts a fresh conversation thread. In production, you usually need to resume prior conversations or handle multiple users.Persist the full conversation history for each chat, including user-facing turns and agent-to-agent handoffs.
Step 2: Configure FastAPI Endpoints
Use FastAPI in one of two ways:This creates separate agency endpoints plus tool endpoints, for example:
- Single agency: call
agency.run_fastapi(...)from anAgencyinstance. - Multiple agencies and/or standalone tools: use top-level
run_fastapi(agencies=..., tools=[...]).
There can be multiple agencies in one server, and each agency key becomes its own endpoint prefix.
run_fastapi(agencies=...) injects load_threads_callback per request (for chat_history) and does not inject save_threads_callback.
If you need server-side persistence writes, wire that explicitly in your application flow./support/get_responseand/support/get_response_stream/sales/get_responseand/sales/get_response_stream/tool/health_check
- Setting Up FastAPI Endpoints
- Authentication
- Implementation reference (multiple agencies and tools)
- API Usage Example
Step 3: Deploy the Service
Use the Starter Template as your production base. It already includes FastAPI wiring and deployment defaults.
- Create a repo from the template
- Set
OPENAI_API_KEYandAPP_TOKEN - Follow the template README to deploy
host, port, app_token_env, cors_origins, enable_agui).