@@ -318,6 +318,10 @@ async def run(self, question: str) -> str:
318318 ActivityWeatherService .get_weather_method ,
319319 start_to_close_timeout = timedelta (seconds = 10 ),
320320 ),
321+ openai_agents .workflow .activity_as_tool (
322+ get_weather_failure ,
323+ start_to_close_timeout = timedelta (seconds = 10 ),
324+ ),
321325 ],
322326 )
323327 result = await Runner .run (
@@ -462,6 +466,53 @@ async def test_tool_workflow(client: Client, use_local_model: bool):
462466 )
463467
464468
469+ @activity .defn
470+ async def get_weather_failure (city : str ) -> Weather :
471+ """
472+ Get the weather for a given city.
473+ """
474+ raise ApplicationError ("No weather" , non_retryable = True )
475+
476+
477+ class TestWeatherFailureModel (StaticTestModel ):
478+ responses = [
479+ ResponseBuilders .tool_call ('{"city":"Tokyo"}' , "get_weather_failure" ),
480+ ]
481+
482+
483+ async def test_tool_failure_workflow (client : Client ):
484+ new_config = client .config ()
485+ new_config ["plugins" ] = [
486+ openai_agents .OpenAIAgentsPlugin (
487+ model_params = ModelActivityParameters (
488+ start_to_close_timeout = timedelta (seconds = 30 )
489+ ),
490+ model_provider = TestModelProvider (TestWeatherFailureModel ()),
491+ )
492+ ]
493+ client = Client (** new_config )
494+
495+ async with new_worker (
496+ client ,
497+ ToolsWorkflow ,
498+ activities = [
499+ get_weather_failure ,
500+ ],
501+ ) as worker :
502+ workflow_handle = await client .start_workflow (
503+ ToolsWorkflow .run ,
504+ "What is the weather in Tokio?" ,
505+ id = f"tools-failure-workflow-{ uuid .uuid4 ()} " ,
506+ task_queue = worker .task_queue ,
507+ execution_timeout = timedelta (seconds = 2 ),
508+ )
509+ with pytest .raises (WorkflowFailureError ) as e :
510+ result = await workflow_handle .result ()
511+ cause = e .value .cause
512+ assert isinstance (cause , ApplicationError )
513+ assert "Workflow failure exception in Agents Framework" in cause .message
514+
515+
465516@pytest .mark .parametrize ("use_local_model" , [True , False ])
466517async def test_nexus_tool_workflow (
467518 client : Client , env : WorkflowEnvironment , use_local_model : bool
@@ -1909,20 +1960,14 @@ async def run(self, question: str) -> str:
19091960 return result .final_output
19101961
19111962
1912- @pytest .mark .parametrize ("use_local_model" , [True , False ])
1913- async def test_code_interpreter_tool (client : Client , use_local_model ):
1914- if not use_local_model and not os .environ .get ("OPENAI_API_KEY" ):
1915- pytest .skip ("No openai API key" )
1916-
1963+ async def test_code_interpreter_tool (client : Client ):
19171964 new_config = client .config ()
19181965 new_config ["plugins" ] = [
19191966 openai_agents .OpenAIAgentsPlugin (
19201967 model_params = ModelActivityParameters (
19211968 start_to_close_timeout = timedelta (seconds = 60 )
19221969 ),
1923- model_provider = TestModelProvider (CodeInterpreterModel ())
1924- if use_local_model
1925- else None ,
1970+ model_provider = TestModelProvider (CodeInterpreterModel ()),
19261971 )
19271972 ]
19281973 client = Client (** new_config )
@@ -1939,8 +1984,7 @@ async def test_code_interpreter_tool(client: Client, use_local_model):
19391984 execution_timeout = timedelta (seconds = 60 ),
19401985 )
19411986 result = await workflow_handle .result ()
1942- if use_local_model :
1943- assert result == "Over 9000"
1987+ assert result == "Over 9000"
19441988
19451989
19461990class HostedMCPModel (StaticTestModel ):
@@ -2011,20 +2055,14 @@ def approve(_: MCPToolApprovalRequest) -> MCPToolApprovalFunctionResult:
20112055 return result .final_output
20122056
20132057
2014- @pytest .mark .parametrize ("use_local_model" , [True , False ])
2015- async def test_hosted_mcp_tool (client : Client , use_local_model ):
2016- if not use_local_model and not os .environ .get ("OPENAI_API_KEY" ):
2017- pytest .skip ("No openai API key" )
2018-
2058+ async def test_hosted_mcp_tool (client : Client ):
20192059 new_config = client .config ()
20202060 new_config ["plugins" ] = [
20212061 openai_agents .OpenAIAgentsPlugin (
20222062 model_params = ModelActivityParameters (
20232063 start_to_close_timeout = timedelta (seconds = 120 )
20242064 ),
2025- model_provider = TestModelProvider (HostedMCPModel ())
2026- if use_local_model
2027- else None ,
2065+ model_provider = TestModelProvider (HostedMCPModel ()),
20282066 )
20292067 ]
20302068 client = Client (** new_config )
@@ -2041,8 +2079,7 @@ async def test_hosted_mcp_tool(client: Client, use_local_model):
20412079 execution_timeout = timedelta (seconds = 120 ),
20422080 )
20432081 result = await workflow_handle .result ()
2044- if use_local_model :
2045- assert result == "Some language"
2082+ assert result == "Some language"
20462083
20472084
20482085class AssertDifferentModelProvider (ModelProvider ):
0 commit comments