Skip to content

Commit 4a31bb6

Browse files
authored
Mark some dataclasses as pydantic dataclasses (#1131)
This is the set of top level types used by Temporal for serialization across activity boundaries. In order to ensure that the models contained in these dataclasses are built prior to use, the dataclasses need to be `pydantic.dataclasses.dataclass` rather than `dataclasses.dataclass` This fixes issues where the types cannot be serialized if the contained types happen not to have been built. This happens particularly often when model logging is disabled, which happened to build the pydantic models as a side effect.
1 parent 4b8f40e commit 4a31bb6

File tree

3 files changed

+6
-3
lines changed

3 files changed

+6
-3
lines changed

src/agents/items.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from dataclasses import dataclass
66
from typing import TYPE_CHECKING, Any, Generic, Literal, TypeVar, Union
77

8+
import pydantic
89
from openai.types.responses import (
910
Response,
1011
ResponseComputerToolCall,
@@ -212,7 +213,7 @@ class MCPApprovalResponseItem(RunItemBase[McpApprovalResponse]):
212213
"""An item generated by an agent."""
213214

214215

215-
@dataclass
216+
@pydantic.dataclasses.dataclass
216217
class ModelResponse:
217218
output: list[TResponseOutputItem]
218219
"""A list of outputs (messages, tool calls, etc) generated by the model"""

src/agents/model_settings.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,15 @@
22

33
import dataclasses
44
from collections.abc import Mapping
5-
from dataclasses import dataclass, fields, replace
5+
from dataclasses import fields, replace
66
from typing import Annotated, Any, Literal, Union
77

88
from openai import Omit as _Omit
99
from openai._types import Body, Query
1010
from openai.types.responses import ResponseIncludable
1111
from openai.types.shared import Reasoning
1212
from pydantic import BaseModel, GetCoreSchemaHandler
13+
from pydantic.dataclasses import dataclass
1314
from pydantic_core import core_schema
1415
from typing_extensions import TypeAlias
1516

src/agents/usage.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
from dataclasses import dataclass, field
1+
from dataclasses import field
22

33
from openai.types.responses.response_usage import InputTokensDetails, OutputTokensDetails
4+
from pydantic.dataclasses import dataclass
45

56

67
@dataclass

0 commit comments

Comments
 (0)