Skip to main content
Patterns for production voice agents: observability, tool design, multi-agent systems, and guardrails.

Complete Example: Multi-Agent Customer Service

This example combines prompting, all three tool types, and multi-agent handoffs:

Observability

Log Metrics

Track performance and business metrics:

Built-in LLM Agent Metrics

LlmAgent automatically emits three timing metrics on every turn — no code needed:
MetricDescription
llm_first_chunk_msTime from start of response generation to first chunk (text or tool call) from the LLM
llm_first_text_msTime from start of response generation to first text chunk
agent_turn_msTotal agent processing time for the turn

Tool Patterns

Validation in Tools

Validate inputs before processing:

Async Operations in Tools

Handle long-running operations with proper timeout handling:

Error Handling

Handle errors gracefully in tools:

Agent Wrappers

Agent wrappers add cross-cutting behavior (logging, validation, routing) without modifying the underlying agent.

Guardrails: Safety and Content Filtering

Wrappers are ideal for implementing guardrails that filter unsafe content in both directions:
Common guardrail patterns:
  • Content safety filtering (toxicity, hate speech, PII)
  • Rate limiting and abuse prevention
  • Compliance checks (HIPAA, financial regulations)
  • Brand safety (off-brand responses)

Routing Between Multiple Agents

Dynamically switch between specialized agents based on conversation context:
Use with LlmAgent:

Best Practices

Keep wrappers focused on a single responsibility. Use async for and yield to preserve streaming. Stack simple wrappers rather than building one complex one.

Example Implementations

Full working examples demonstrating these patterns:
ExamplePatternDescription
Form FillerStateful toolsWalk users through a YAML-defined form with validation
Multi-Agent Transferagent_as_handoffEnglish/Spanish agent handoff
Chat SupervisorBackground researchSeparate agents for talking and longer-thinking