fix(result): support Pydantic model_rebuild for RunResultStreaming #2455
+24
−1
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
Fixes Pydantic undefined-annotation errors when
RunResultStreamingis used as a field type in a Pydantic model andmodel_rebuild()is called.What changed
RunResultBase.__get_pydantic_core_schema__so run-result objects are treated as runtime instance types during Pydantic schema generation.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 likeAgentin 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.pyuv run pytest tests/test_result_cast.py -quv run pytest tests/test_source_compat_constructors.py -qMyModel.model_rebuild()no longer raises).Fixes #2127