Skip to main content
Agency Swarm reuses your existing Agent definitions for voice. This page shows how to adapt agents for spoken conversations.

Try it locally

Save this as voice_demo.py. It starts the packaged browser client on your computer, so you can speak with your agent before you host anything.
  1. Install the voice extra: pip install "agency-swarm[voice]".
  2. Set OPENAI_API_KEY, then run python voice_demo.py.
  3. Open http://127.0.0.1:8000, click Connect, and allow microphone access.
When you are ready to host the browser client or connect phone calls, use the Deployment guide.

What you can build

  • Phone receptionist — answers calls, routes to specialists, captures caller details.
  • Live support triage — gathers context, lets callers interrupt, and escalates to a human or another agent.
  • Language coach — listens, corrects pronunciation, and keeps the dialogue short and encouraging.

Prerequisites

Define your agent (same API)

You keep using the standard Agent class—voice agents are regular agents with the same tools, handoffs, and instructions.
Keep using the same agent definitions—add voice= only when you care about the spoken persona.
Set voice to any supported realtime token:
  • OpenAI voices: alloy, ash, ballad, cedar, coral, echo, marin, sage, shimmer, verse
  • xAI voices: ara, eve, leo, rex, sal

One voice per call

A call uses a single voice from start to finish. Once the model has spoken, the realtime API refuses to switch voices—OpenAI answers with a cannot_update_voice error. Agency Swarm therefore picks the voice as the call starts and keeps it, even when the call hands off to another agent.
The voice comes from the first place that sets one:
  1. The voice= you pass to run_realtime() or the demo launcher.
  2. The voice= on your entry agent—the agent that answers the call.
  3. The provider’s own default when neither is set.
A voice= on any other agent is not used for that call. It is still worth setting: that agent uses its own voice whenever it is the one answering. If you want variety without picking voices by hand, build the agency with randomize_agent_voices=True. Every agent without an explicit voice gets a deterministic random pick from the provider’s list, and the entry agent’s pick becomes the voice for the call. Pass voice_random_seed= to keep the picks stable between runs.

Add handoffs (optional)

Handoffs work exactly as they do in text mode. Register your flows once and they will carry over to voice sessions.
When the concierge hands off, the specialist takes over the conversation with its own instructions and tools. The caller keeps hearing the concierge’s marin voice for the rest of the call, so give the specialists a different name or greeting if you want the switch to be obvious.

Next steps