3
3
from durable_decorators import durable_openai_agent_orchestrator
4
4
from model_activity import create_invoke_model_activity
5
5
6
- import basic .hello_world
7
-
8
6
app = func .FunctionApp (http_auth_level = func .AuthLevel .FUNCTION )
9
7
10
8
9
+ # Regular HTTP trigger
11
10
@app .route (route = "orchestrators/{functionName}" )
12
11
@app .durable_client_input (client_name = "client" )
13
12
async def orchestration_starter (req : func .HttpRequest , client ):
14
13
function_name = req .route_params .get ('functionName' )
14
+ # Starting a new orchestration instance in the most regular way
15
15
instance_id = await client .start_new (function_name )
16
16
response = client .create_check_status_response (req , instance_id )
17
17
return response
18
18
19
19
20
- @app .orchestration_trigger (context_name = "context" )
21
- @durable_openai_agent_orchestrator
20
+ @app .orchestration_trigger (context_name = "context" ) # Regular orchestrator function
21
+ @durable_openai_agent_orchestrator # This is what turns the magic on!
22
22
def haiku (context ):
23
+ # Regular OpenAI Agent code, straight from the most basic sample
23
24
agent = Agent (
24
25
name = "Assistant" ,
25
26
instructions = "You only respond in haikus." ,
@@ -51,12 +52,13 @@ def haiku_judge(context):
51
52
52
53
@app .orchestration_trigger (context_name = "context" )
53
54
@durable_openai_agent_orchestrator
54
- def hello_cities (context ):
55
+ def human_in_the_loop (context ):
55
56
writer = Agent (
56
57
name = "Writer" ,
57
58
instructions = "You only respond in haikus." ,
58
59
)
59
60
61
+ # You can invoke Durable Functions activities, like you normally would
60
62
topic = yield context .call_activity ("hello" , "Seattle" )
61
63
62
64
haiku = Runner .run_sync (writer , f"Tell me about '{ topic } '" )
@@ -68,39 +70,20 @@ def hello_cities(context):
68
70
69
71
evaluation = Runner .run_sync (judge , f"Is this a good haiku? { haiku .final_output } " )
70
72
71
- return [haiku .final_output , "\n \n " + evaluation .final_output ]
72
-
73
-
74
- @app .activity_trigger (input_name = "name" )
75
- async def hello (name : str ):
76
- return f"Hello { name } !"
77
-
78
-
79
-
80
- @app .orchestration_trigger (context_name = "context" )
81
- @durable_openai_agent_orchestrator
82
- def human_in_the_loop (context ):
83
- writer = Agent (
84
- name = "Writer" ,
85
- instructions = "You only respond in haikus." ,
86
- )
87
-
88
- haiku = Runner .run_sync (writer , "Tell me about recursion in programming." )
89
-
90
- judge = Agent (
91
- name = "Judge" ,
92
- instructions = "You judge haikus." ,
93
- )
94
-
95
- evaluation = Runner .run_sync (judge , f"Is this a good haiku? { haiku .final_output } " )
96
-
73
+ # You can set custom orchestration status, like you normally would
97
74
context .set_custom_status (f"Haiku:\n { haiku .final_output } \n \n Evaluation:\n { evaluation .final_output } \n \n Waiting for approval..." )
75
+
76
+ # You can wait for external events, like you normally would
98
77
event_data = yield context .wait_for_external_event ("Approve" )
99
- context .set_custom_status ("" )
100
78
101
79
reaction = Runner .run_sync (writer , f"Your haiku is considered { event_data } . React emotionally." )
102
80
103
- return reaction .final_output
81
+ return reaction .final_output
82
+
83
+
84
+ @app .activity_trigger (input_name = "name" )
85
+ async def hello (name : str ):
86
+ return f"Hello { name } !"
104
87
105
88
106
89
#region Implementation details
0 commit comments