Skip to content

[responses] add multi-agent-aware beta output_text#3528

Open
wendyjiao-openai wants to merge 1 commit into
mainfrom
personal/wendyjiao/select-final-root-output-text
Open

[responses] add multi-agent-aware beta output_text#3528
wendyjiao-openai wants to merge 1 commit into
mainfrom
personal/wendyjiao/select-final-root-output-text

Conversation

@wendyjiao-openai

Copy link
Copy Markdown
  • I understand that this repository is auto-generated and my pull request may not be merged

Changes being requested

Add an output_text convenience property to BetaResponse. For multi-agent responses, the property returns text from the last /root final_answer message 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-pyright
  • mypy .
  • Full pytest suite: 5,749 passed, 1,231 skipped
  • Pydantic v1 focused suite: 3 passed

@wendyjiao-openai
wendyjiao-openai requested a review from a team as a code owner July 22, 2026 20:47
Copilot AI review requested due to automatic review settings July 22, 2026 20:47
@openai-sdks

openai-sdks Bot commented Jul 22, 2026

Copy link
Copy Markdown

OkTest Summary

237/237 SDK tests passed in 12.926s for Python SDK PR #3528.

Test results — 42 files
Test Result Time
tests/chat-completions-complex-body.test.ts ✅ Passed 232ms
tests/chat-completions-create.test.ts ✅ Passed 366ms
tests/chat-completions-stream.test.ts ✅ Passed 160ms
tests/files-content-binary.test.ts ✅ Passed 275ms
tests/files-create-multipart.test.ts ✅ Passed 257ms
tests/files-list-pagination.test.ts ✅ Passed 204ms
tests/initialize-config.test.ts ✅ Passed 189ms
tests/instance-isolation.test.ts ✅ Passed 215ms
tests/models-list.test.ts ✅ Passed 152ms
tests/responses-background-lifecycle.test.ts ✅ Passed 269ms
tests/responses-body-method-errors.test.ts ✅ Passed 393ms
tests/responses-cancel-timeout.test.ts ✅ Passed 268ms
tests/responses-cancel.test.ts ✅ Passed 264ms
tests/responses-compact-retries.test.ts ✅ Passed 378ms
tests/responses-compact.test.ts ✅ Passed 239ms
tests/responses-create-advanced-stream.test.ts ✅ Passed 160ms
tests/responses-create-advanced.test.ts ✅ Passed 282ms
tests/responses-create-disconnect.test.ts ✅ Passed 1.447s
tests/responses-create-errors.test.ts ✅ Passed 286ms
tests/responses-create-malformed-api-responses.test.ts ✅ Passed 286ms
tests/responses-create-retries.test.ts ✅ Passed 382ms
tests/responses-create-stream-failures.test.ts ✅ Passed 160ms
tests/responses-create-stream-timeout.test.ts ✅ Passed 287ms
tests/responses-create-stream-wire.test.ts ✅ Passed 4.14s
tests/responses-create-stream.test.ts ✅ Passed 159ms
tests/responses-create-terminal-states.test.ts ✅ Passed 280ms
tests/responses-create-timeout.test.ts ✅ Passed 314ms
tests/responses-create.test.ts ✅ Passed 282ms
tests/responses-delete.test.ts ✅ Passed 261ms
tests/responses-input-items-errors.test.ts ✅ Passed 362ms
tests/responses-input-items-list.test.ts ✅ Passed 369ms
tests/responses-input-items-options.test.ts ✅ Passed 400ms
tests/responses-input-tokens-count-timeout.test.ts ✅ Passed 286ms
tests/responses-input-tokens-count.test.ts ✅ Passed 302ms
tests/responses-malformed-inputs.test.ts ✅ Passed 3.221s
tests/responses-not-found-errors.test.ts ✅ Passed 324ms
tests/responses-parse.test.ts ✅ Passed 532ms
tests/responses-retrieve-retries.test.ts ✅ Passed 320ms
tests/responses-retrieve.test.ts ✅ Passed 376ms
tests/responses-stored-method-errors.test.ts ✅ Passed 812ms
tests/retry-behavior.test.ts ✅ Passed 3.375s
tests/sdk-error-shape.test.ts ✅ Passed 371ms

View OkTest run #29956568236

SDK merge (554373e6ea53) · head (8e89d7321f40) · base (e67afa88433d) · OkTest (d2b5921fc22a)

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment on lines +631 to +632
if output.type != "message" or output.agent is None:
continue

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge 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 👍 / 👎.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_text property with multi-agent-aware selection logic (last root final_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.

Comment on lines +621 to +626
"""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.
"""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants