[responses] add multi-agent-aware beta output_text#3528
[responses] add multi-agent-aware beta output_text#3528wendyjiao-openai wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 8e89d7321f
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if output.type != "message" or output.agent is None: | ||
| continue |
There was a problem hiding this comment.
Treat missing agent metadata as the root coordinator
When the coordinator message omits agent—the established convention in examples/responses/multi_agent_streaming.py:12-13 and multi_agent_websocket.py:12-13, where missing metadata maps to /root—this condition skips the actual root final_answer. If a child message has metadata, has_agent_metadata becomes true and output_text returns an empty string; otherwise it falls back to aggregating root commentary with the final answer. Consequently, the new property does not select the coordinator's answer for normal multi-agent output.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Pull request overview
Adds a convenience output_text property to BetaResponse to make it easier to extract user-facing text, with multi-agent-aware behavior that selects the last /root final_answer message when agent metadata is present.
Changes:
- Add
BetaResponse.output_textproperty with multi-agent-aware selection logic (last rootfinal_answer, otherwise aggregate). - Add unit tests covering multi-agent last-root selection, empty output when no terminal root answer exists, and non-multi-agent aggregation behavior.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
src/openai/types/beta/beta_response.py |
Adds BetaResponse.output_text property with multi-agent-aware behavior. |
tests/lib/responses/test_beta_responses.py |
Adds tests validating the new output_text behavior. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| """Convenience property that returns the response's output text. | ||
|
|
||
| For multi-agent responses, this returns text from the last root | ||
| `final_answer` message. Otherwise, it aggregates all `output_text` content | ||
| blocks from the `output` list. | ||
| """ |
Changes being requested
Add an
output_textconvenience property toBetaResponse. For multi-agent responses, the property returns text from the last/rootfinal_answermessage instead of concatenating root commentary, child-agent output, and earlier root answers. If agent metadata is absent, it preserves the existing response-wide aggregation behavior.Tests cover last-root selection, missing terminal root output, and the non-multi-agent fallback under both supported Pydantic generations.
Additional context & links
Companion docs PR: https://github.com/openai/developers-website/pull/2094
Validation:
ruff format --check .ruff check .scripts/run-pyrightmypy .