Skip to main content
In this article, you create a Voice-based agent that uses a hosted text agent as its conversation engine. Voice Live provides speech recognition, turn-taking, speech synthesis, and interruption handling, while your hosted agent processes text input and produces text responses.
Voice-based agents are in preview. Requests to create a Voice-based agent must include the Foundry-Features: VoiceAgents=V1Preview header.
A Voice-based agent can use an existing hosted text agent for its conversation logic. The resulting voice experience follows this flow:

Prerequisites

  • Access to a Microsoft Foundry project.
  • A hosted text agent deployed in the Foundry project. The hosted agent must expose the invocations_ws protocol and implement Bridge Protocol version 1.0. For an implementation example, see the basic Voice-based target agent sample.
  • The name of the hosted agent and, optionally, a specific version to use.

Create the voice-based agent

Create the voice-based agent by using the project endpoint. Set conversation_engine.type to hosted_agent, and use name to identify the hosted agent that handles the conversation. Replace the project endpoint, hosted agent name, and optional hosted agent version with your project values.
To use the hosted agent’s latest version instead of pinning a version, set HOSTED_AGENT_VERSION to an empty string or remove version from the conversation_engine object. The conversation_engine object supports the following properties: For this type of voice-based agent, don’t specify model_type or model. Exactly one conversation selection form is allowed: a model-backed definition or an engine-backed definition. The presence of conversation_engine selects the engine-backed form. The hosted agent owns the conversation logic. Therefore, don’t configure instructions, reasoning_effort, tools, tool_choice, subagent_config, or handoff on the voice wrapper. You can configure voice-surface properties, including audio, avatar, output_modalities, greeting, structured_inputs, store, and rai_config. The create operation validates the conversation engine configuration but doesn’t verify the referenced hosted agent. The service resolves the target agent and checks its Voice Live and Bridge Protocol compatibility when a voice session starts.

Use the voice-based agent

Connect to the voice-based agent’s voice WebSocket endpoint to have an interactive conversation. The following Python sample captures 24-kHz PCM audio from your microphone, sends it to the agent, and plays the agent’s audio responses. Install the required packages:
PyAudio requires PortAudio. If the pyaudio installation fails, install the PortAudio development package for your operating system, and then run the pip install command again.
Replace the project endpoint and Voice-based agent name with your values:
Run the script, start speaking after the connection message appears, and listen for the agent’s response through your speakers or headphones. The server-side voice activity detector identifies the end of each turn and starts the agent’s response automatically. Press Ctrl+C to end the conversation.