Skip to main content
In this article, you use a subagent in a Voice-based agent, define when the agent delegates work to the subagent, and test the resulting voice experience.
Items marked (preview) in this article are currently in public preview. This preview is provided without a service-level agreement, and we don’t recommend it for production workloads. Certain features might not be supported or might have constrained capabilities. For more information, see Supplemental Terms of Use for Microsoft Azure Previews.

Introduction

When creating a Voice-based agent, you can add one or more subagents that handle specific tasks. The main agent delegates requests to the subagent when the request matches the subagent’s defined capabilities. The subagent can be Foundry prompt agents, or Foundry hosted agents. The following section shows how to create a prompt agent, and use it as a subagent for a Voice-based agent. You can also apply similar steps to a hosted agent.
Note: Subagents aren’t supported for voice-based agents in projects configured with virtual network (VNet) isolation.

Prerequisites

The Foundry RBAC roles were recently renamed. Foundry User, Foundry Owner, Foundry Account Owner, and Foundry Project Manager were previously named Azure AI User, Azure AI Owner, Azure AI Account Owner, and Azure AI Project Manager. You might still see the previous names in some places while the rename rolls out. The role IDs and core permissions are unchanged by the rename.
  • Python 3.10 or later.
  • The Azure CLI, signed in with az login.
  • A voice model and a text model available to your project.
  • A microphone and speakers or headphones.

Install the packages

Install the Microsoft Foundry SDK version 2.7.0 or later with the voice extra, Azure Identity client library, and PyAudio in the same Python environment. The voice extra supplies aiohttp for asynchronous connections. PyAudio handles microphone capture and speaker playback.
For Python SDK setup details, see Install the packages.

Set environment variables

Set the project endpoint and model deployment names. In Bash:
In PowerShell:
Find the project endpoint on the Overview page of your project in the Foundry portal.

Create a subagent

Create a prompt agent with one focused responsibility. The following example creates a subagent that writes poems based on a user’s requested topic and style.
Reference: Azure AI Projects client library for Python. You can also create a subagent in the Microsoft Foundry portal or deploy a code-based hosted agent.

Use the subagent in the Voice-based agent

Create the Voice-based agent by using the project endpoint. In subagent_config, identify the poetry agent by name and describe when the Voice-based agent delegates a request to it.
Reference: Azure AI Projects client library for Python.

Talk to the voice agent

Connect to the voice agent with the Microsoft Foundry SDK. The client streams microphone audio to the agent and plays the spoken response as it arrives. Use headphones to prevent the speaker output from feeding back into the microphone. Run the package installation command with the same Python environment that you use to run the client. Create a file named talk_to_voice_agent.py:
Reference: Azure AI Projects client library for Python. The client waits for session.created before streaming microphone audio. It uses the agent’s saved configuration, so it doesn’t send session.update or wait for session.updated. Run the client:
After the client connects, ask it to write a short poem about the sea. The voice agent delegates the request to poetry-agent and speaks the returned poem. Press Ctrl+C to disconnect.

Use the voice agent in the Foundry portal

Open the voice agent in the playground to have a spoken conversation:
  1. Sign in to the Foundry portal.
  2. Open the project that contains the voice agent and subagent.
  3. Select Build > Agents.
  4. Select poetry-voice-agent, and then select Open in playground.
  5. Start a voice session.
  6. Ask the agent to write a short poem about the sea.
The voice agent delegates the request to poetry-agent and speaks the returned poem.

Configure subagent behavior

The subagent_config object identifies the text agents that the Voice-based agent can consult. Each subagent must belong to the same Foundry project as the Voice-based agent. Configure at least one entry in the subagents array. Use the optional response_policy object to control what the voice agent says while it waits for a subagent: In Python, use datetime.timedelta for invoke_timeout_seconds, gap_filling_interval, and progress_update_interval. The SDK serializes these values as seconds.

Apply subagent best practices

  • Give each subagent one clearly defined capability.
  • Tune the agent’s instructions to delegate requests to the subagent when appropriate.