Skip to content

Commit 8b727e5

Browse files
authored
Add argument validation for the types of provided tools (#985)
* Add argument validation for the types of provided tools * Specifically check if it is a callable, as Union isn't supported in isinstance * Fix type check with typing.get_args * Fix check
1 parent fe82b07 commit 8b727e5

File tree

1 file changed

+18
-10
lines changed

1 file changed

+18
-10
lines changed

temporalio/contrib/openai_agents/_openai_runner.py

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import typing
12
from dataclasses import replace
23
from typing import Any, Union
34

@@ -7,6 +8,7 @@
78
RunResult,
89
RunResultStreaming,
910
TContext,
11+
Tool,
1012
TResponseInputItem,
1113
)
1214
from agents.run import DEFAULT_AGENT_RUNNER, DEFAULT_MAX_TURNS, AgentRunner
@@ -42,6 +44,13 @@ async def run(
4244
**kwargs,
4345
)
4446

47+
tool_types = typing.get_args(Tool)
48+
for t in starting_agent.tools:
49+
if not isinstance(t, tool_types):
50+
raise ValueError(
51+
"Provided tool is not a tool type. If using an activity, make sure to wrap it with openai_agents.workflow.activity_as_tool."
52+
)
53+
4554
context = kwargs.get("context")
4655
max_turns = kwargs.get("max_turns", DEFAULT_MAX_TURNS)
4756
hooks = kwargs.get("hooks")
@@ -63,16 +72,15 @@ async def run(
6372
),
6473
)
6574

66-
with workflow.unsafe.imports_passed_through():
67-
return await self._runner.run(
68-
starting_agent=starting_agent,
69-
input=input,
70-
context=context,
71-
max_turns=max_turns,
72-
hooks=hooks,
73-
run_config=updated_run_config,
74-
previous_response_id=previous_response_id,
75-
)
75+
return await self._runner.run(
76+
starting_agent=starting_agent,
77+
input=input,
78+
context=context,
79+
max_turns=max_turns,
80+
hooks=hooks,
81+
run_config=updated_run_config,
82+
previous_response_id=previous_response_id,
83+
)
7684

7785
def run_sync(
7886
self,

0 commit comments

Comments
 (0)