Prerequisites
- An Azure OpenAI resource in a region that supports the Responses API.
- A GPT-5.6 model deployment. Check model availability before you create the deployment.
- Python 3.10 or later.
-
For Microsoft Entra ID authentication, the
Cognitive Services OpenAI Userrole assigned to your identity. - For REST requests, cURL and the Azure CLI signed in to your Azure subscription.
-
The latest OpenAI and Azure Identity packages:
Choose when to use multi-agent orchestration
Use multi-agent orchestration when a task can be divided into concrete, independent workstreams.
Adding subagents can increase token usage. It might not improve tasks that require an ordered chain of reasoning, frequent writes to shared state, or one slow external operation.
Create a multi-agent response
Use the beta Responses client withapi-version=preview. Set multi_agent.enabled to true to let the root agent create subagents. In Azure OpenAI requests, model contains your deployment name, which doesn’t have to match the underlying model name.
The following example asks three subagents to evaluate separate disaster-recovery proposals. Each proposal includes enough information for a subagent to work independently, and the root agent reconciles their findings against shared requirements.
- Replace
YOUR-RESOURCE-NAMEwith your Azure OpenAI resource name. - If your deployment name isn’t
gpt-5.6-sol, replace the value ofmodelwith your deployment name. - Run the code, and confirm that the output contains one consolidated review from
/root.
AZURE_OPENAI_API_KEY, and create the client as follows:
Send a REST request
For REST requests, use the Azure OpenAI v1 endpoint and addapi-version=preview.
Microsoft Entra ID
SetAZURE_OPENAI_AUTH_TOKEN to an access token for the Azure AI audience:
API key
SetAZURE_OPENAI_API_KEY to a key from your Azure OpenAI resource:
max_concurrent_subagents limits how many subagents can be active at the same time across the entire agent tree. The limit includes children, grandchildren, and deeper descendants, but excludes the root agent. The default is 3, which is recommended for most workloads.
Control delegation
The model decides whether delegation is useful. Make the workstreams explicit in the input when the task requires parallel work. Add developer instructions to control when the root model delegates. For example:Do not create subagents unless the user explicitly asks for delegation or parallel work.Use subagents when parallel work would materially improve speed or quality.
Understand agent coordination
The agent that receives the original request is the root agent and is named/root. Subagents use hierarchical names that show their position in the agent tree:
multi_agent_call items. Your application must not execute these actions or submit outputs for them.
Handle function calls
Any agent can call developer-defined functions included in the request. Execute every returnedfunction_call, and submit a matching function_call_output. Don’t handle hosted multi_agent_call items as developer-defined functions because the service manages them.
With HTTP, a response completes after every active agent finishes or pauses for a client-executed function call. Run all pending function calls, preserve the output items, and submit their outputs in the next request so the paused agents can continue. For the base tool execution pattern, see Function calling.
Inspect multi-agent output
Multi-agent responses can include these additional output item types:multi_agent_call: A hosted collaboration action, such asspawn_agent.multi_agent_call_output: The result of a hosted collaboration action.agent_message: An encrypted message sent from one agent to another.
call_id field links each multi_agent_call to its corresponding multi_agent_call_output. Each item also has an agent property. For an agent_message, use author and recipient to trace the message direction.
Choose HTTP or WebSocket mode
HTTP and WebSocket transports support the same multi-agent orchestration capabilities, but their function-call behavior differs.
In WebSocket mode, send a
response.inject event for each function output:
response.inject.created or response.inject.failed. If an injection fails with response_already_completed, send the returned input in a new response that continues from the completed response. For connection and recovery guidance, see Use the Responses API in WebSocket mode.
Apply security controls
Every agent in the tree has access to the tools configured in the original request. Apply the same controls to calls from subagents that you apply to calls from the root agent.- Grant tools and calling identities only the permissions required for the task.
- Validate function arguments and authorize each action in application code.
- Require user approval before write, destructive, financial, or other high-impact actions.
- Treat content returned by external tools as untrusted input, and protect against prompt injection.
- Log the agent name, tool name, arguments, approval decision, and result for auditing.
- Bound delegated work, and monitor token usage because subagents can increase consumption.
Review limitations
- The
/responses/compactendpoint isn’t supported when multi-agent orchestration is enabled. - Automatic server-side compaction is enabled when
multi_agent.enabledistrue, even if the request doesn’t definecontext_management. Compaction runs independently for the root agent and each subagent. - You can override the compaction threshold by setting
context_management.compact_threshold. reasoning.summaryisn’t supported when multi-agent orchestration is enabled.max_tool_callsisn’t supported when multi-agent orchestration is enabled.max_concurrent_subagentsdefaults to3, which is recommended for most workloads.- Multi-agent orchestration has no fixed limit on tree depth or the total number of subagents created during a run. Control concurrency and bound delegated work to manage latency and token usage.