@@ -107,42 +107,92 @@ async def run_weather_agent(user_input: str):
107107 )
108108 return result .final_output
109109
110+
110111from agents import trace
111112from multi_agents import triage_agent
113+
114+
112115# with trace (group_id and metadata)
113116async def main1 ():
114- with trace (workflow_name = "test_workflow_1" , group_id = "test_group_id_1" , metadata = {"test_metadata_1" : "test_metadata_1" }):
117+ with trace (
118+ workflow_name = "test_workflow_1" ,
119+ group_id = "test_group_id_1" ,
120+ metadata = {"test_metadata_1" : "test_metadata_1" },
121+ ):
115122 user_query = "What's the weather like in London today?"
116- response_1 = await Runner .run (triage_agent , "Hola, ¿cómo estás?" , metric_collection = "test_collection_1" , thread_id = "test" )
117- response_2 = await Runner .run (weather_agent , user_query , metric_collection = "test_collection_1" )
123+ response_1 = await Runner .run (
124+ triage_agent ,
125+ "Hola, ¿cómo estás?" ,
126+ metric_collection = "test_collection_1" ,
127+ thread_id = "test" ,
128+ )
129+ response_2 = await Runner .run (
130+ weather_agent , user_query , metric_collection = "test_collection_1"
131+ )
118132 update_current_trace (input = "initial input" , output = "final output" )
119133
134+
120135# without trace (group_id and metadata not present)
121136async def main2 ():
122137 user_query = "What's the weather like in London today?"
123- response_1 = await Runner .run (triage_agent , "Hola, ¿cómo estás?" , metric_collection = "test_collection_1" , thread_id = "test" )
124- response_2 = await Runner .run (weather_agent , user_query , metric_collection = "test_collection_1" )
125-
138+ response_1 = await Runner .run (
139+ triage_agent ,
140+ "Hola, ¿cómo estás?" ,
141+ metric_collection = "test_collection_1" ,
142+ thread_id = "test" ,
143+ )
144+ response_2 = await Runner .run (
145+ weather_agent , user_query , metric_collection = "test_collection_1"
146+ )
147+
126148
127149async def main3 ():
128150 user_query = "What's the weather like in London today?"
129- with trace (workflow_name = "test_workflow_1" , group_id = "test_group_id_1" , metadata = {"test_metadata_1" : "test_metadata_1" }):
130- response_2 = await Runner .run (weather_agent , user_query , metric_collection = "test_collection_1" )
131- with trace (workflow_name = "test_workflow_2" , group_id = "test_group_id_2" , metadata = {"test_metadata_2" : "test_metadata_2" }):
132- response_1 = await Runner .run (triage_agent , "Hola, ¿cómo estás?" , metric_collection = "test_collection_1" , thread_id = "test" )
151+ with trace (
152+ workflow_name = "test_workflow_1" ,
153+ group_id = "test_group_id_1" ,
154+ metadata = {"test_metadata_1" : "test_metadata_1" },
155+ ):
156+ response_2 = await Runner .run (
157+ weather_agent , user_query , metric_collection = "test_collection_1"
158+ )
159+ with trace (
160+ workflow_name = "test_workflow_2" ,
161+ group_id = "test_group_id_2" ,
162+ metadata = {"test_metadata_2" : "test_metadata_2" },
163+ ):
164+ response_1 = await Runner .run (
165+ triage_agent ,
166+ "Hola, ¿cómo estás?" ,
167+ metric_collection = "test_collection_1" ,
168+ thread_id = "test" ,
169+ )
170+
133171
134172async def main4 ():
135173 user_query = "What's the weather like in London today?"
136- with trace (workflow_name = "test_workflow_1" , group_id = "test_group_id_1" , metadata = {"test_metadata_1" : "test_metadata_1" }):
137- run_streamed_1 = Runner .run_streamed (weather_agent , user_query , metric_collection = "test_collection_1" )
174+ with trace (
175+ workflow_name = "test_workflow_1" ,
176+ group_id = "test_group_id_1" ,
177+ metadata = {"test_metadata_1" : "test_metadata_1" },
178+ ):
179+ run_streamed_1 = Runner .run_streamed (
180+ weather_agent , user_query , metric_collection = "test_collection_1"
181+ )
138182 async for chunk in run_streamed_1 .stream_events ():
139183 print (chunk , end = "" , flush = True )
140184 print ("=" * 50 )
141- run_streamed_2 = Runner .run_streamed (triage_agent , "Hola, ¿cómo estás?" , metric_collection = "test_collection_1" , thread_id = "test" )
185+ run_streamed_2 = Runner .run_streamed (
186+ triage_agent ,
187+ "Hola, ¿cómo estás?" ,
188+ metric_collection = "test_collection_1" ,
189+ thread_id = "test" ,
190+ )
142191 async for chunk in run_streamed_2 .stream_events ():
143192 print (chunk , end = "" , flush = True )
144193 print ("=" * 50 )
145194
195+
146196def execute_agent ():
147197 asyncio .run (main1 ())
148198 # asyncio.run(main2())
0 commit comments