22import azure .functions as func
33import logging
44
5- from agents .run import set_default_agent_runner
6- from durable_openai_runner import DurableOpenAIRunner
7- from orchestrator_exceptions import OrchestratorYielded
8-
95from agents import (
106 AgentOutputSchemaBase ,
117 CodeInterpreterTool ,
2622 WebSearchTool ,
2723)
2824
25+ from agents .run import set_default_agent_runner
26+ from durable_openai_runner import DurableOpenAIRunner
27+ from yield_exception import YieldException
28+ from activity_call_tracker import ActivityCallTracker
29+
2930app = func .FunctionApp (http_auth_level = func .AuthLevel .FUNCTION )
3031
3132@app .route (route = "orchestrators/{functionName}" )
@@ -39,14 +40,24 @@ async def hello_orchestration_starter(req: func.HttpRequest, client):
3940
4041@app .orchestration_trigger (context_name = "context" )
4142def basic_hello_world_orchestrator (context ):
42- set_default_agent_runner (DurableOpenAIRunner (durable_orchestration_context = context ))
43+ activity_call_tracker = ActivityCallTracker (context )
44+ durable_openai_runner = DurableOpenAIRunner (activity_call_tracker = activity_call_tracker )
45+ set_default_agent_runner (durable_openai_runner )
4346
4447 try :
4548 from basic .hello_world import main
4649 result = main ()
4750 return result
48- except OrchestratorYielded as e :
49- yield e .activity_output
51+ except YieldException as e :
52+ for task in activity_call_tracker .tasks_to_yield :
53+ yield task
54+ activity_call_tracker .tasks_to_yield .clear ()
55+ yield e .task
56+ finally :
57+ for task in activity_call_tracker .tasks_to_yield :
58+ yield task
59+ activity_call_tracker .tasks_to_yield .clear ()
60+
5061
5162@app .activity_trigger (input_name = "input" )
5263async def invoke_model_activity (input : str ):
0 commit comments