feat(agents): [1/n] return typed answers from session streams - #4007
Conversation
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
Castiron custom code✅ No new custom-code files detected. 49 mixed files remain; 1 existing customization changed. Compared
48 existing customizations unchanged
8 more in the full report. A changed generated baseline means this report cannot reliably identify which handwritten lines changed. Inspect the custom-code diffDownload the exact patch produced by this run (requires repository access): gh run download 36885089720 --repo openai/openai-python \
--name castiron-custom-code-36885089720-1 --dir /tmp/castiron-custom-code-36885089720-1
git apply --stat /tmp/castiron-custom-code-36885089720-1/custom-code.patch
cat /tmp/castiron-custom-code-36885089720-1/custom-code.patchOr reproduce it from an SDK checkout containing the vendored reporter: git fetch --no-tags origin f219c5581661408688195659ab0137927ba9a033 e8c9c5490afad52ec1c060d028c65217c98a5d8a
python3 scripts/castiron/custom_code_report.py report \
--base f219c5581661408688195659ab0137927ba9a033 \
--head e8c9c5490afad52ec1c060d028c65217c98a5d8a --fetch --require-head-hash --public \
--out /tmp/castiron-custom-code-e8c9c5490afa
cat /tmp/castiron-custom-code-e8c9c5490afa/custom-code.patchThis is the current full custom patch for mixed files, not an attribution of only the handwritten lines changed by this PR. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: bf09b00004
ℹ️ 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".
|
@codex review pls |
🛡️ Codex Security Review · Automatically triggeredSecurity review completed. No security issues were found in this pull request. Reviewed commit: Only the user who started this review can view the report in Codex. ℹ️ About Codex security reviews in GitHubThis is an experimental Codex feature. Security reviews are triggered when:
Once complete, Codex will leave suggestions, or a comment if no findings are found. |
|
Codex Review: Didn't find any major issues. Swish! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: ab9c333705
ℹ️ 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".
|
@codex review pls |
🛡️ Codex Security Review · Automatically triggeredSecurity review completed. No security issues were found in this pull request. Reviewed commit: Only the user who started this review can view the report in Codex. ℹ️ About Codex security reviews in GitHubThis is an experimental Codex feature. Security reviews are triggered when:
Once complete, Codex will leave suggestions, or a comment if no findings are found. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 36c00973e5
ℹ️ 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".
|
@codex review pls |
|
Codex Review: Didn't find any major issues. Bravo. Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
🛡️ Codex Security Review · Automatically triggeredSecurity review completed. No security issues were found in this pull request. Reviewed commit: Only the user who started this review can view the report in Codex. ℹ️ About Codex security reviews in GitHubThis is an experimental Codex feature. Security reviews are triggered when:
Once complete, Codex will leave suggestions, or a comment if no findings are found. |
|
@codex review pls |
🛡️ Codex Security Review · Automatically triggeredSecurity review completed. No security issues were found in this pull request. Reviewed commit: Only the user who started this review can view the report in Codex. ℹ️ About Codex security reviews in GitHubThis is an experimental Codex feature. Security reviews are triggered when:
Once complete, Codex will leave suggestions, or a comment if no findings are found. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 5dbb92aee7
ℹ️ 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".
|
@codex review pls |
🛡️ Codex Security Review · Automatically triggeredSecurity review completed. No security issues were found in this pull request. Reviewed commit: Only the user who started this review can view the report in Codex. ℹ️ About Codex security reviews in GitHubThis is an experimental Codex feature. Security reviews are triggered when:
Once complete, Codex will leave suggestions, or a comment if no findings are found. |
|
Codex Review: Didn't find any major issues. Breezy! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
8984cd6 to
eea0329
Compare
jbeckwith-oai
left a comment
There was a problem hiding this comment.
Approved at eea0329cc8a922349695a88cbbcb2c6047e189fb against f219c5581661408688195659ab0137927ba9a033. No actionable findings in the current diff.
Reviewed all ten changed files and traced creation/follow-up streams through result collection and the shared Pydantic parsing/schema helpers. The creation-only schema normalization, parser-only follow-up behavior, copied model schemas, Pydantic v1 nullability handling, sync/async binding, raw-result recovery, and sanitized parse errors are consistent. The current tests cover the previously reported schema and error-handling cases, repeated result access, recursive/nullable models, and using the same model for tools and output without mutating its input schema.
Hosted lint, build, Python 3.10/3.14 and HTTPX2 tests, compatibility detection, and CodeQL passed; the linked OkTest report shows 236/236 passing at this head. I reviewed the test source but did not execute contributor code or live API calls locally.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: a97921a67f
ℹ️ 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".
|
@codex review pls |
|
Codex Review: Didn't find any major issues. Chef's kiss. Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
🛡️ Codex Security Review · Automatically triggeredSecurity review completed. No security issues were found in this pull request. Reviewed commit: Only the user who started this review can view the report in Codex. ℹ️ About Codex security reviews in GitHubThis is an experimental Codex feature. Security reviews are triggered when:
Once complete, Codex will leave suggestions, or a comment if no findings are found. |
dpiet-oai
left a comment
There was a problem hiding this comment.
One verified Medium correctness finding is inline.
| """Beta: build the Agents JSON-schema format for a Pydantic model.""" | ||
| validate_output_type(output_type) | ||
| if is_basemodel_type(output_type): | ||
| schema = model_schema(output_type, strict=True) |
There was a problem hiding this comment.
[Medium] Preserve Pydantic v1 nullable fields in the output schema
Under Pydantic v1, BaseModel.schema() omits null from Optional field schemas because optionality is represented by the field not being required. The strict-schema pass then marks every property required, so after removing the v1 restoration a model such as reason: str | None = None is sent as a required string. In a real typed Agents request, a legitimate null answer is therefore excluded even though the bound model accepts it, forcing a different value or an API-generation failure.
Suggested fix: Restore the Pydantic v1 nullability pass after model_schema(...), or move that correction into the shared strict-schema helper, and keep a v1 regression assertion that nested/list/union optional fields include a null branch.
There was a problem hiding this comment.
Agreed, this looks like a real Pydantic v1 nullability gap. I reproduced reason: str | None = None: the model accepts None, but both the existing Responses helper and this Agents helper emit a required string without a null branch. Pydantic v2 includes the null branch in both paths.
For now we're keeping the Agents helper aligned with existing Responses behavior, rather than restoring an Agents-only correction. A shared, model-aware Pydantic v1 conversion fix would be a better follow-up; the API cannot recover nullability that the submitted schema omits. Leaving this thread unresolved to track the gap.
There was a problem hiding this comment.
Tracking the shared Pydantic v1 nullability gap in SDK-1129, with the reproduction and this discussion linked there. Agents continues matching existing Responses behavior for now; leaving this thread unresolved.
markstuart-oai
left a comment
There was a problem hiding this comment.
Reviewed e8c9c5490afad52ec1c060d028c65217c98a5d8a. The per-text-part parsing, raw-result preservation, schema isolation and synchronous/asynchronous stream lifecycle look sound. Reusing the existing strict-schema normalizer keeps this API consistent with Responses. The existing Pydantic v1 nullability finding is a shared-helper limitation worth addressing there, rather than introducing a separate Agents schema policy.
Hosted checks passed on this head. No local SDK tests or live API calls were run.
## Summary
Stage selected local files and read an artifact from the exact completed
turn, either in memory or streamed to a local path. The helpers keep
upload IDs available for explicit cleanup and stream downloads to a
caller-chosen path.
Before:
```python
uploaded = client.files.create(file=Path("source.pdf"), purpose="user_data")
inputs = [{"type": "file_id", "file_id": uploaded.id, "path": "/workspace/source.pdf"}]
# Pass inputs when creating the hosted environment, then run the session.
artifact = next(a for a in client.beta.agents.sessions.artifacts.list(result.session_id)
if a.turn_id == result.turn_id and a.path == "/workspace/outputs/report.md")
with client.beta.agents.sessions.artifacts.with_streaming_response.content(
artifact.id, session_id=result.session_id,
) as content:
content.stream_to_file("report.md")
```
After:
```python
prepared = client.beta.agents.environments.files.prepare({
"/workspace/source.pdf": Path("source.pdf"),
})
# Pass prepared.files when creating the hosted environment, then run the session.
artifacts = client.beta.agents.sessions.artifacts.for_result(result)
report_bytes = artifacts.content("/workspace/outputs/report.md").content
# Or stream to an application-owned path:
artifact = artifacts.download("/workspace/outputs/report.md", to=Path("report.md"))
```
`prepare_directory(..., include=[...])` selects a directory snapshot;
`files.upload(...)` uploads and stages one file in an existing
environment. Sync and async helpers live under the beta Agents
namespace. They preflight selected files before uploading, preserve
partial upload ownership on errors, and detect missing or ambiguous
artifacts across all pages.
Local path selection is intended for static application-owned files and
stable directories; it is not a filesystem sandbox for untrusted paths
or hostile local writers.
This PR now targets `main` directly. Reattachment/result recovery is
deferred: a silent attachment cannot reliably distinguish pending work
from an already-completed turn, so these helpers do not depend on
SDK-side recovery heuristics.
### Stack
- openai#4004 (merged
prerequisite)
- openai#4007 (merged
prerequisite)
- openai#4008 (closed/deferred;
not a dependency)
- openai#4009 👈 this PR
Automated Release PR --- ## [3.23.0](openai/openai-python@v3.22.1...v3.23.0) (2026-10-01) ### Features * **agents:** [1/n] return typed answers from session streams ([openai#4007](openai#4007)) ([10f8816](openai@10f8816)) * **agents:** stage files and download turn artifacts ([openai#4009](openai#4009)) ([4fc2438](openai@4fc2438)) * **api:** Add session traces and Realtime translations ([openai#4001](openai#4001)) ([138e3d1](openai@138e3d1)) * **beta:** expose typed application actions as agent tools ([openai#4006](openai#4006)) ([f219c55](openai@f219c55)) * collect final output from beta Agents streams ([157ac4c](openai@157ac4c)) ### Bug Fixes * **api:** allow original image detail in Chat Completions ([openai#4005](openai#4005)) ([8a136c2](openai@8a136c2)) * **api:** correct the eval run cancellation endpoint ([openai#4003](openai#4003)) ([28c5c9a](openai@28c5c9a)) * **api:** retain WebSocket endpoint paths and query parameters ([openai#3999](openai#3999)) ([7f203fd](openai@7f203fd)) * keep Castiron budget results valid when main advances ([openai#4012](openai#4012)) ([73f189b](openai@73f189b)) * **responses:** avoid replaying uncertain typed sends on reconnect ([openai#4011](openai#4011)) ([1dbbf61](openai@1dbbf61)) * **responses:** respect send queue limits during reconnect ([openai#4000](openai#4000)) ([50f95ac](openai@50f95ac)) * use monotonic clock for file processing timeout ([openai#3748](openai#3748)) ([58aca1d](openai@58aca1d)) ### Chores * **api:** retain WebRTC Live session transport types ([openai#4002](openai#4002)) ([5c9ace9](openai@5c9ace9)) * **deps-dev:** bump pyright from 1.1.413 to 1.1.414 ([openai#3902](openai#3902)) ([a91d779](openai@a91d779)) * **deps:** bump astral-sh/setup-uv from 10.0.1 to 10.1.0 ([openai#3976](openai#3976)) ([f15f43c](openai@f15f43c)) * **deps:** bump CodeQL actions to 4.38.1 ([openai#3974](openai#3974)) ([fb70d66](openai@fb70d66)) --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please). Co-authored-by: openai-sdks[bot] <284451331+openai-sdks[bot]@users.noreply.github.com>
Summary
Bind a Pydantic output model to the Agents request and its completed result, so applications can use a typed answer without maintaining separate schema and parsing code.
Before:
After:
The same
output_typeworks on follow-up streams as a local parser for an already-configured session.output_parsedreturns the first parsed final text part; all final text parts are validated. Raw output remains available; parsing failures expose the completed result throughAgentOutputParseError.result. Sync and async helpers share the existing Pydantic schema normalization and result collection.Schema conversion follows the existing Responses helper; API errors report unsupported schema features. Typed tools and outputs can reuse the same model without output normalization changing its tool argument schema.
Stack