Skip to content

Commit bcce208

Browse files
authored
docs: updates for hosted multi-agent support (openai#3789)
1 parent 41e79f1 commit bcce208

2 files changed

Lines changed: 72 additions & 0 deletions

File tree

docs/models/index.md

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ Start with the simplest path that fits your setup:
1313
| --- | --- | --- |
1414
| Use OpenAI models only | Use the default OpenAI provider with the Responses model path | [OpenAI models](#openai-models) |
1515
| Use OpenAI Responses API over websocket transport | Keep the Responses model path and enable websocket transport | [Responses WebSocket transport](#responses-websocket-transport) |
16+
| Use OpenAI-hosted subagents | Use the experimental hosted multi-agent model | [Hosted multi-agent](#hosted-multi-agent-experimental) |
1617
| Use one non-OpenAI provider | Start with the built-in provider integration points | [Non-OpenAI models](#non-openai-models) |
1718
| Mix models or providers across agents | Select providers per run or per agent and review feature differences | [Mixing models in one workflow](#mixing-models-in-one-workflow) and [Mixing models across providers](#mixing-models-across-providers) |
1819
| Tune advanced OpenAI Responses request settings | Use `ModelSettings` on the OpenAI Responses path | [Advanced OpenAI Responses settings](#advanced-openai-responses-settings) |
@@ -231,6 +232,74 @@ If you use a custom OpenAI-compatible endpoint or proxy, websocket transport als
231232
- For long reasoning turns or networks with latency spikes, customize websocket keepalive behavior with `responses_websocket_options`. Increase `ping_timeout` to tolerate delayed pong frames, or set `ping_timeout=None` to disable heartbeat timeouts while keeping pings enabled. Prefer HTTP/SSE transport when reliability is more important than websocket latency.
232233
- By default the SDK disables the incoming message-size limit (`max_size=None`). For long-lived agent processes behind proxies or in memory-constrained containers, set `responses_websocket_options={"max_size": 8 * 1024 * 1024}` to bound per-message memory usage.
233234

235+
### Hosted multi-agent (experimental)
236+
237+
The OpenAI Responses API hosted multi-agent beta lets a GPT-5.6 root model create and coordinate server-hosted subagents. The Agents SDK can keep using its normal `Runner`: hosted orchestration stays on the service, while developer-defined function tools execute in your application.
238+
239+
This integration is experimental and uses the Responses WebSocket transport so local function outputs can be returned to an active hosted agent with `response.inject`. It requires `openai[realtime]>=2.45.0`, including a beta build that exposes `client.beta.responses.connect`. The interface and beta item schemas may change before general availability.
240+
241+
#### Configure the model
242+
243+
Import the model from the experimental module and assign it to an SDK `Agent`:
244+
245+
```python
246+
from agents import Agent
247+
from agents.extensions.experimental.hosted_multi_agent import OpenAIHostedMultiAgentModel
248+
249+
agent = Agent(
250+
name="Research coordinator",
251+
instructions="Delegate independent research tasks, then synthesize the findings.",
252+
model=OpenAIHostedMultiAgentModel(model="gpt-5.6-sol", config={"max_concurrent_subagents": 3}),
253+
)
254+
```
255+
256+
Constructing `OpenAIHostedMultiAgentModel` enables `multi_agent.enabled` and sends the `OpenAI-Beta: responses_multi_agent=v1` WebSocket header. The model uses the default OpenAI client unless `openai_client` is provided. If `max_concurrent_subagents` is omitted, the service default is used.
257+
258+
#### Local function tools
259+
260+
All hosted agents share the model and tools configured for the request. The Responses API decides which hosted agent calls a function. The normal SDK Runner executes the function locally and injects a `function_call_output` with the same call ID into the active WebSocket response, which lets the service resume the original hosted caller. Function execution still passes through the Runner's normal guardrails, hooks, and failure conversion. SDK tool approval interruptions are not supported: any function tool whose `needs_approval` setting is not `False` is rejected before the request is sent.
261+
262+
Use `get_hosted_agent_metadata()` when a tool needs caller-aware logging or authorization:
263+
264+
```python
265+
from typing import Any
266+
267+
from agents import function_tool
268+
from agents.extensions.experimental.hosted_multi_agent import get_hosted_agent_metadata
269+
from agents.tool_context import ToolContext
270+
271+
@function_tool
272+
def lookup_document(ctx: ToolContext[Any], section: str) -> str:
273+
metadata = get_hosted_agent_metadata(ctx)
274+
caller = metadata.agent_name if metadata else "unknown"
275+
print(f"tool caller: {caller}; call ID: {ctx.tool_call_id}")
276+
return f"Contents for {section}"
277+
```
278+
279+
Hosted agent names are observational metadata, not a local routing mechanism. Route outputs with the call ID supplied by the SDK. For side-effecting tools, use that call ID as an idempotency key and enforce any required authorization in application code before or during tool execution; do not use `needs_approval` with this model. Tool arguments and outputs cross the Responses API boundary.
280+
281+
#### Output and streaming behavior
282+
283+
Only a message attributed to `/root` with phase `final_answer` becomes a normal final message. The experimental adapter filters subagent messages and hosted orchestration records out of the high-level `RunResult`; the SDK never executes those records as local functions.
284+
285+
Raw streaming continues to expose beta Responses events, including hosted output items and `response.inject.created` acknowledgements. The adapter divides one active provider response into SDK-visible logical model turns when a function call is ready, then resumes that same provider response after the Runner produces an output. Use `get_hosted_agent_metadata()` with a raw hosted item or a `ToolContext` to inspect attribution.
286+
287+
#### Relationship to SDK orchestration
288+
289+
Hosted multi-agent is separate from SDK handoffs and agents-as-tools:
290+
291+
- Hosted multi-agent creates subagents on the OpenAI service. Your application does not create or schedule those subagents.
292+
- SDK handoffs change the active local SDK `Agent`. They are rejected when this experimental model is used because every hosted agent receives the same handoff tools, which would create conflicting ownership.
293+
- Agents-as-tools remain available, but using them creates nested client-side and server-side orchestration. Evaluate the additional latency, cost, and tool exposure deliberately.
294+
295+
#### Current limitations
296+
297+
The experimental model rejects `reasoning.summary`, `max_tool_calls`, and caller-supplied `multi_agent` or `betas` overrides. The Responses `/compact` endpoint is not supported by the beta, although an explicit `context_management.compact_threshold` may be used because the service automatically compacts each hosted agent context independently.
298+
299+
One `OpenAIHostedMultiAgentModel` instance owns at most one active hosted response at a time. If a run is abandoned while waiting for local function output, call `await model.close()` to release its WebSocket. Restoring an in-flight hosted response in a different process or event loop is not currently supported.
300+
301+
See the [OpenAI Multi-agent guide](https://developers.openai.com/api/docs/guides/tools-multi-agent) for the underlying Responses API beta behavior. See [`examples/agent_patterns/hosted_multi_agent_beta.py`](https://github.com/openai/openai-agents-python/tree/main/examples/agent_patterns/hosted_multi_agent_beta.py) for non-streaming and streaming SDK usage.
302+
234303
## Non-OpenAI models
235304

236305
If you need a non-OpenAI provider, start with the SDK's built-in provider integration points. In many setups, this is enough without adding a third-party adapter. Examples for each pattern live in [examples/model_providers](https://github.com/openai/openai-agents-python/tree/main/examples/model_providers/).
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# `Model`
2+
3+
::: agents.extensions.experimental.hosted_multi_agent.model

0 commit comments

Comments
 (0)