This repo demonstrates how to deploy any Agency Swarm agency as a FastAPI application in a Docker container on Railway.
- Fully tested agency
- Docker installed is optional
- Python 3.12
-
Configure environment variables:
- For local testing: Copy
.env.example
to.env
and add your environment variables - For Railway: Configure environment variables in Railway Dashboard under Variables section
- For local testing: Copy
-
Add requirements: Add your extra requirements to the
requirements.txt
file. -
Add your Agency: Drag-and-drop your agency into the /src directory and import it according to the example in the
main.py
:from ExampleAgency.agency import agency
-
Set your APP_TOKEN: In
.env
, replaceYOUR_APP_TOKEN
with a secure token. This will be used for API authentication. -
Add settings.json: Run
python main.py
fromsrc/
directory, open thehttp://localhost:8000/demo-gradio
and send a message. This will save your agent settings in thesettings.json
file. This step is necessary to avoid recreating assistants on every application start. -
Deploy on Railway:
- Log into Railway
- Click "New Empty Project"
- Click "Add a service"
- Select "Empty service"
- Go to Settings
- Connect your repository
- Railway will automatically detect the Dockerfile
- Go to Variables in Railway dashboard
- Add new variable:
OPENAI_API_KEY
: Your OpenAI API key- Add any other required environment variables
- Click "Deploy" to start the build process
- Go to Settings to generate a domain:
- Verify port is set to 8000 (it's selected automatically after deployment)
- Click "Generate domain"
-
Test the interfaces:
- Gradio UI:
<YOUR_DEPLOYMENT_URL>/demo-gradio
(local: http://localhost:8000/demo-gradio) - API Documentation:
<YOUR_DEPLOYMENT_URL>/docs
(local: http://localhost:8000/docs)
- Gradio UI:
-
Test API:
- macOS/Linux:
curl -X POST \ -H "Content-Type: application/json" \ -H "Authorization: Bearer <YOUR_APP_TOKEN>" \ -d '{"message": "What is the capital of France?"}' \ <YOUR_DEPLOYMENT_URL>/api/agency
- Windows PowerShell:
curl -X POST ` -H "Content-Type: application/json" ` -H "Authorization: Bearer <YOUR_APP_TOKEN>" ` -d "{\"message\": \"What is the capital of France?\"}" ` <YOUR_DEPLOYMENT_URL>/api/agency
Request body:
{
"message": "What is the capital of France?",
"attachments": [
{
"file_id": "file-123",
"tools": [{ "type": "file_search" }, { "type": "code_interpreter" }]
}
]
}
message
: The message to send to the agent.attachments
(optional): A list of files attached to the message, and the tools they should be added to. See OpenAI Docs.
Response:
{
"response": "Paris"
}
All API requests require a Bearer token in the Authorization header:
Authorization: Bearer <YOUR_APP_TOKEN>
- Dark/Light mode support
- File upload capabilities
- Support for multiple agents
- Real-time streaming responses
- Code interpreter and file search tool integration