File tree Expand file tree Collapse file tree 2 files changed +24
-1
lines changed
Expand file tree Collapse file tree 2 files changed +24
-1
lines changed Original file line number Diff line number Diff line change 88from dataclasses import InitVar , dataclass , field
99from typing import Any , Literal , TypeVar , cast
1010
11+ from pydantic import GetCoreSchemaHandler
12+ from pydantic_core import core_schema
13+
1114from .agent import Agent
1215from .agent_output import AgentOutputSchemaBase
1316from .exceptions import (
@@ -124,6 +127,16 @@ class RunResultBase(abc.ABC):
124127 _trace_state : TraceState | None = field (default = None , init = False , repr = False )
125128 """Serialized trace metadata captured during the run."""
126129
130+ @classmethod
131+ def __get_pydantic_core_schema__ (
132+ cls ,
133+ _source_type : Any ,
134+ _handler : GetCoreSchemaHandler ,
135+ ) -> core_schema .CoreSchema :
136+ # RunResult objects are runtime values; schema generation should treat them as instances
137+ # instead of recursively traversing internal dataclass annotations.
138+ return core_schema .is_instance_schema (cls )
139+
127140 @property
128141 @abc .abstractmethod
129142 def last_agent (self ) -> Agent [Any ]:
Original file line number Diff line number Diff line change 77
88import pytest
99from openai .types .responses import ResponseOutputMessage , ResponseOutputText
10- from pydantic import BaseModel
10+ from pydantic import BaseModel , ConfigDict
1111
1212from agents import (
1313 Agent ,
@@ -45,6 +45,16 @@ class Foo(BaseModel):
4545 bar : int
4646
4747
48+ def test_run_result_streaming_supports_pydantic_model_rebuild () -> None :
49+ class StreamingRunContainer (BaseModel ):
50+ query_id : str
51+ run_stream : RunResultStreaming | None
52+
53+ model_config = ConfigDict (arbitrary_types_allowed = True )
54+
55+ StreamingRunContainer .model_rebuild ()
56+
57+
4858def _create_message (text : str ) -> ResponseOutputMessage :
4959 return ResponseOutputMessage (
5060 id = "msg" ,
You can’t perform that action at this time.
0 commit comments