Summary
Add a FastAPI-compatible WebSocket middleware that wraps Deepgram's Voice Agent API, enabling developers to deploy voice agents as standard API endpoints with minimal boilerplate. The middleware should handle WebSocket upgrade, audio proxying, session lifecycle, and error handling.
Problem it solves
Developers building voice agent backends with FastAPI currently write 50-100 lines of WebSocket handling code for each endpoint — managing the Deepgram connection lifecycle, audio proxying, and error recovery manually. A middleware abstraction reduces this to a few lines of configuration while following FastAPI's dependency injection patterns.
Proposed API
from deepgram.contrib.fastapi import DeepgramAgentMiddleware, AgentConfig
agent_config = AgentConfig(
listen={"model": "nova-3"},
think={"provider": {"type": "open_ai"}, "model": "gpt-4o-mini"},
speak={"model": "aura-asteria-en"},
tools=[lookup_order, create_ticket],
)
app = FastAPI()
@app.websocket("/agent")
async def agent_endpoint(websocket: WebSocket):
async with DeepgramAgentMiddleware(websocket, config=agent_config) as session:
await session.run() # Handles audio proxy, events, tool execution
Acceptance criteria
Raised by the DX intelligence system.
Summary
Add a FastAPI-compatible WebSocket middleware that wraps Deepgram's Voice Agent API, enabling developers to deploy voice agents as standard API endpoints with minimal boilerplate. The middleware should handle WebSocket upgrade, audio proxying, session lifecycle, and error handling.
Problem it solves
Developers building voice agent backends with FastAPI currently write 50-100 lines of WebSocket handling code for each endpoint — managing the Deepgram connection lifecycle, audio proxying, and error recovery manually. A middleware abstraction reduces this to a few lines of configuration while following FastAPI's dependency injection patterns.
Proposed API
Acceptance criteria
Raised by the DX intelligence system.