Skip to main content
This example builds a HierarchicalSwarm (director + worker agents) where every agent gets its own StreamingTTSCallback with a different voice. The result is an audible org chart: you can hear the director delegating, the research analyst gathering, the data analyst crunching, and the strategy consultant recommending — each in their own voice.

Step 1: Install dependencies

Step 2: Create one TTS callback per agent

Distinct voices are the whole point — pick a different OpenAI voice for each role. Available voices: alloy, echo, fable, onyx, nova, shimmer.

Step 3: Build the worker agents

Each agent gets its own callback through the streaming_callback parameter, and streaming_on=True so the LLM streams tokens into the callback in real time.

Step 4: Assemble the hierarchical swarm

planning_enabled=True makes the director draft an explicit plan before delegating work.

Step 5: Run, then flush every callback

The TTS callbacks each buffer their last sentence — flush them all at the end (and on errors) so nothing gets cut off.

Why this pattern works well

  • Clarity: in a multi-agent swarm, output that’s text-only mixes everyone’s responses together. Distinct voices make role attribution effortless.
  • Real-time feedback: streaming callbacks deliver each sentence as soon as it’s complete — you don’t wait for the whole swarm to finish before any audio plays.
  • Per-agent customisation: voices, models, even TTS providers can vary per agent if you build each callback differently.

See also