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
- A Foundry project with access to voice-based agents.
- Foundry User role on the project.
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 thevoice 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.
Set environment variables
Set the project endpoint and model deployment names. In Bash: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.Use the subagent in the Voice-based agent
Create the Voice-based agent by using the project endpoint. Insubagent_config, identify the poetry agent by name and describe when the
Voice-based agent delegates a request to it.
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 namedtalk_to_voice_agent.py:
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:
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:- Sign in to the Foundry portal.
- Open the project that contains the voice agent and subagent.
- Select Build > Agents.
- Select poetry-voice-agent, and then select Open in playground.
- Start a voice session.
- Ask the agent to write a short poem about the sea.
poetry-agent and speaks the returned
poem.
Configure subagent behavior
Thesubagent_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.