Skip to content

Commit f8fd081

Browse files
committed
Implement wait_for_external_event
1 parent 14bc832 commit f8fd081

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

samples-v2/openai_agents/durable_ai_agent_context.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@ def call_activity(self, activity_name, input: str):
3131
self.activities_called += 1
3232
return task
3333

34+
def set_custom_status(self, status: str):
35+
self.context.set_custom_status(status)
36+
37+
def wait_for_external_event(self, event_name: str):
38+
return self.context.wait_for_external_event(event_name)
39+
3440
def yield_and_clear_tasks(self):
3541
"""Yield all accumulated tasks and clear the tasks list."""
3642
for task in self.tasks_to_yield:

samples-v2/openai_agents/function_app.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,3 +82,13 @@ def hello_cities(context):
8282
@app.activity_trigger(input_name="name")
8383
async def hello(name: str):
8484
return f"Hello {name}!"
85+
86+
87+
88+
@app.orchestration_trigger(context_name="context")
89+
@durable_openai_agent_orchestrator
90+
def human_in_the_loop(context):
91+
context.set_custom_status("Waiting for approval...")
92+
event_data = yield context.wait_for_external_event("Approve")
93+
context.set_custom_status("")
94+
return event_data

0 commit comments

Comments
 (0)