Skip to content

Conversation

@OiPunk
Copy link
Contributor

@OiPunk OiPunk commented Feb 10, 2026

Summary

Fixes Pydantic undefined-annotation errors when RunResultStreaming is used as a field type in a Pydantic model and model_rebuild() is called.

What changed

  • Added RunResultBase.__get_pydantic_core_schema__ so run-result objects are treated as runtime instance types during Pydantic schema generation.
  • Added a regression test for the reported pattern (RunResultStreaming | None + ConfigDict(arbitrary_types_allowed=True) + model_rebuild()).

Why this works

Pydantic was recursively traversing internal dataclass annotations from RunResultStreaming, which triggers unresolved forward references like Agent in nested runtime types. Treating run results as instance types avoids recursive traversal while preserving normal runtime usage.

Validation

  • uv run ruff check src/agents/result.py tests/test_result_cast.py
  • uv run pytest tests/test_result_cast.py -q
  • uv run pytest tests/test_source_compat_constructors.py -q
  • Manual repro script from the issue now succeeds (MyModel.model_rebuild() no longer raises).

Fixes #2127

@seratch seratch merged commit f1f88f8 into openai:main Feb 10, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

RunResultStreaming type not compatible with Pydantic model_rebuild()

2 participants