Skip to content

Commit 9de388e

Browse files
committed
Use to_jsonable_python for inputs
1 parent 47027fc commit 9de388e

2 files changed

Lines changed: 11 additions & 11 deletions

File tree

temporalio/contrib/openai_agents/invoke_model_activity.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
WebSearchTool,
2525
)
2626
from agents.models.multi_provider import MultiProvider
27+
from pydantic_core import to_jsonable_python
2728
from typing_extensions import Required, TypedDict
2829

2930
from temporalio import activity, workflow
@@ -137,9 +138,7 @@ async def empty_on_invoke_handoff(
137138
) -> Any:
138139
return None
139140

140-
# workaround for https://github.com/pydantic/pydantic/issues/9541
141-
# ValidatorIterator returned
142-
input_json = json.dumps(input["input"], default=str)
141+
input_json = json.dumps(to_jsonable_python(input["input"]))
143142
input_input = json.loads(input_json)
144143

145144
def make_tool(tool: ToolInput) -> Tool:

tests/contrib/openai_agents/test_openai.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import uuid
33
from dataclasses import dataclass
44
from datetime import timedelta
5-
from typing import Any, Optional, Union, no_type_check
5+
from typing import Any, Optional, Union, no_type_check, cast
66

77
import pytest
88
from pydantic import ConfigDict, Field
@@ -64,8 +64,8 @@
6464
ResponseFunctionToolCall,
6565
ResponseFunctionWebSearch,
6666
ResponseOutputMessage,
67-
ResponseOutputText,
68-
)
67+
ResponseOutputText, EasyInputMessageParam,
68+
)
6969
from openai.types.responses.response_function_web_search import ActionSearch
7070
from openai.types.responses.response_prompt_param import ResponsePromptParam
7171

@@ -98,6 +98,7 @@ def __init__(
9898
) -> None:
9999
global response_index
100100
response_index = 0
101+
self.inputs: list[Union[str, list[TResponseInputItem]]] = []
101102
super().__init__(model, openai_client)
102103

103104
async def get_response(
@@ -115,6 +116,7 @@ async def get_response(
115116
global response_index
116117
response = self.responses[response_index]
117118
response_index += 1
119+
self.inputs.append(input)
118120
return response
119121

120122

@@ -805,12 +807,11 @@ async def test_agents_as_tools_workflow(client: Client, use_local_model: bool):
805807

806808
model_params = ModelActivityParameters(start_to_close_timeout=timedelta(seconds=30))
807809
with set_open_ai_agent_temporal_overrides(model_params):
808-
model_activity = ModelActivity(
809-
TestProvider(
810-
AgentAsToolsModel( # type: ignore
810+
model = AgentAsToolsModel( # type: ignore
811811
"", openai_client=AsyncOpenAI(api_key="Fake key")
812812
)
813-
)
813+
model_activity = ModelActivity(
814+
TestProvider(model)
814815
if use_local_model
815816
else None
816817
)
@@ -862,7 +863,7 @@ async def test_agents_as_tools_workflow(client: Client, use_local_model: bool):
862863
.activity_task_completed_event_attributes.result.payloads[0]
863864
.data.decode()
864865
)
865-
866+
assert isinstance(cast(EasyInputMessageParam, model.inputs[3][3])["content"], list)
866867

867868
class AirlineAgentContext(BaseModel):
868869
passenger_name: Optional[str] = None

0 commit comments

Comments
 (0)