Skip to content

Commit 3877efc

Browse files
committed
Throw to yield
1 parent 2de5f84 commit 3877efc

File tree

3 files changed

+19
-4
lines changed

3 files changed

+19
-4
lines changed

samples-v2/openai_agents/durable_model_stub.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ def make_tool_info(tool: Tool) -> ToolInput:
124124
activity_input
125125
)
126126

127-
return activity_output
127+
raise OrchestratorYielded(activity_output)
128128

129129
def stream_response(
130130
self,

samples-v2/openai_agents/function_app.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,12 @@ async def hello_orchestration_starter(req: func.HttpRequest, client):
2020
def basic_hello_world_orchestrator(context):
2121
set_default_agent_runner(DurableOpenAIRunner(durable_orchestration_context=context))
2222

23-
from basic.hello_world import main
24-
result = main()
25-
return result
23+
try:
24+
from basic.hello_world import main
25+
result = main()
26+
return result
27+
except OrchestratorYielded as e:
28+
yield e.activity_output
2629

2730
@app.activity_trigger(input_name="input")
2831
def invoke_model_activity(input: Any):
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
"""Exceptions related to durable orchestrator operations."""
2+
3+
4+
class OrchestratorYielded(Exception):
5+
"""Exception raised when the orchestrator yields to an activity.
6+
7+
This exception stores the activity output for later processing.
8+
"""
9+
10+
def __init__(self, activity_output):
11+
self.activity_output = activity_output
12+
super().__init__("Orchestrator yielded to activity")

0 commit comments

Comments
 (0)