Deploy multiple AI agents as separate Railway services that communicate via Redis and Postgres.
An orchestrator receives HTTP requests and dispatches tasks to agent-specific Redis queues. Each agent pulls from its queue, calls OpenAI, writes results to Postgres, and optionally pushes a follow-up task to the next agent's queue.
HTTP request → Orchestrator → Redis queue:researcher → Researcher Agent
↓
Postgres ← results
↓
Redis queue:writer → Writer Agent
↓
Postgres ← article
| Service | Description |
|---|---|
| orchestrator | FastAPI HTTP service that receives tasks and dispatches to Redis queues |
| researcher | Worker that researches a topic via OpenAI and passes findings to the writer |
| writer | Worker that turns research into a finished article via OpenAI |
| init | One-shot service that creates the tasks table in Postgres |
| PostgreSQL | Stores task state, agent outputs, and final results |
| Redis | Message queue between services |
| Variable | Description | Required |
|---|---|---|
OPENAI_API_KEY |
Your OpenAI API key | Yes |
STARTUP_DELAY_SECONDS |
Seconds to wait before polling (researcher: 0, writer: 5) | No |
Variables DATABASE_URL and REDIS_URL are automatically set by Railway when you reference the database services.
POST /tasks?topic=quantum+computinghits the orchestrator- Orchestrator creates a task in Postgres and pushes it to
queue:researcher - Researcher pulls the task, calls OpenAI for research, writes results to Postgres, pushes a new task to
queue:writer - Writer pulls the task, calls OpenAI to produce an article, writes the final output to Postgres
GET /tasks/{task_id}returns the completed result
After deploying, send a task to the orchestrator:
curl -X POST "https://your-orchestrator.up.railway.app/tasks?topic=quantum+computing"Check the result (replace TASK_ID with the returned ID):
curl "https://your-orchestrator.up.railway.app/tasks/TASK_ID"# Start Postgres and Redis locally
docker run -d --name pg -e POSTGRES_PASSWORD=postgres -p 5432:5432 postgres
docker run -d --name redis -p 6379:6379 redis
# Set environment variables
export DATABASE_URL=postgresql://postgres:postgres@localhost:5432/postgres
export REDIS_URL=redis://localhost:6379
export OPENAI_API_KEY=your-key
# Run the init script
python init/main.py
# Start services in separate terminals
uvicorn orchestrator.app:app --host 0.0.0.0 --port 8000
python researcher/worker.py
python writer/worker.py