Serving Agents Behind an API
Wrap your agent in FastAPI with auth, request validation, and streaming over SSE or WebSockets.
From Notebook to Service
A working agent in a notebook is the start. To ship, wrap it in an HTTP API that other services can call.
FastAPI Skeleton
from fastapi import FastAPI
from pydantic import BaseModel
app = FastAPI()
class AgentRequest(BaseModel):
query: str
user_id: str
class AgentResponse(BaseModel):
answer: str
trace_id: str
@app.post('/agents/qa', response_model=AgentResponse)
def qa(req: AgentRequest):
trace_id = run_agent(req.query, req.user_id)
return AgentResponse(answer=result.answer, trace_id=trace_id)All lessons in this course
- Serving Agents Behind an API
- Async Workflows and Background Jobs
- Rate Limiting and Quota Management
- Blue-Green and Canary Deploys for Agents