feat(agents): [1/n] return typed answers from session streams (#4007)
## 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:
```python
with client.beta.agents.sessions.create(
agent={"model": MODEL, "text": {"format": {
"type": "json_schema", "schema": schema,
}}},
environment={"type": "none"}, input=QUESTION, stream=True,
) as stream:
result = stream.get_final_result()
report = Report.model_validate_json(result.output_text)
```
After:
```python
with client.beta.agents.sessions.create(
agent={"model": MODEL}, environment={"type": "none"},
input=QUESTION, stream=True, output_type=Report,
) as stream:
result = stream.get_final_result()
report = result.output_parsed
```
The same `output_type` works on follow-up streams as a local parser for
an already-configured session. `output_parsed` returns the first parsed
final text part; all final text parts are validated. Raw output remains
available; parsing failures expose the completed result through
`AgentOutputParseError.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
- https://github.com/openai/openai-python/pull/4004 (merged
prerequisite)
- https://github.com/openai/openai-python/pull/4007 👈 this PR
- https://github.com/openai/openai-python/pull/4008
- https://github.com/openai/openai-python/pull/4009 A
Alex Chang committed
10f88169b0f3929b4e2528aad7a825df31163156
Parent: f219c55
Committed by GitHub <noreply@github.com>
on 10/1/2026, 4:13:41 PM