Summary
Add a middleware/interceptor pipeline for the Voice Agent client that lets developers inject custom logic at key points in the conversation lifecycle — before/after STT results, before/after LLM processing, before/after TTS output, and around function calls — without modifying the SDK internals.
Problem it solves
Developers building production voice agents need to add cross-cutting concerns — logging, PII detection, compliance checks, metric collection, response filtering, A/B testing — but the current event-based API requires writing this logic inline in event handlers. A middleware pipeline provides a composable, reusable pattern for layering concerns, similar to ASGI/WSGI middleware in web frameworks that Python developers already understand.
Proposed API
from deepgram import DeepgramClient, AgentMiddleware
class PIIRedactionMiddleware(AgentMiddleware):
async def on_transcript(self, transcript, next):
redacted = self.redact_pii(transcript)
return await next(redacted)
async def on_agent_response(self, response, next):
if self.contains_pii(response):
response = self.redact_pii(response)
return await next(response)
class MetricsMiddleware(AgentMiddleware):
async def on_transcript(self, transcript, next):
start = time.monotonic()
result = await next(transcript)
self.record_latency("stt", time.monotonic() - start)
return result
client = DeepgramClient()
agent = client.agent.v1.websocket(
middleware=[PIIRedactionMiddleware(), MetricsMiddleware()]
)
Acceptance criteria
Raised by the DX intelligence system.
Summary
Add a middleware/interceptor pipeline for the Voice Agent client that lets developers inject custom logic at key points in the conversation lifecycle — before/after STT results, before/after LLM processing, before/after TTS output, and around function calls — without modifying the SDK internals.
Problem it solves
Developers building production voice agents need to add cross-cutting concerns — logging, PII detection, compliance checks, metric collection, response filtering, A/B testing — but the current event-based API requires writing this logic inline in event handlers. A middleware pipeline provides a composable, reusable pattern for layering concerns, similar to ASGI/WSGI middleware in web frameworks that Python developers already understand.
Proposed API
Acceptance criteria
nextto proceedRaised by the DX intelligence system.