@@ -221,6 +221,14 @@ async def get_weather_object(input: WeatherInput) -> Weather:
221
221
)
222
222
223
223
224
+ @activity .defn
225
+ async def get_weather_context (ctx : RunContextWrapper [str ], city : str ) -> Weather :
226
+ """
227
+ Get the weather for a given city.
228
+ """
229
+ return Weather (city = city , temperature_range = "14-20C" , conditions = ctx .context )
230
+
231
+
224
232
class TestWeatherModel (TestModel ):
225
233
responses = [
226
234
ModelResponse (
@@ -265,6 +273,20 @@ class TestWeatherModel(TestModel):
265
273
usage = Usage (),
266
274
response_id = None ,
267
275
),
276
+ ModelResponse (
277
+ output = [
278
+ ResponseFunctionToolCall (
279
+ arguments = '{"city":"Tokyo"}' ,
280
+ call_id = "call" ,
281
+ name = "get_weather_context" ,
282
+ type = "function_call" ,
283
+ id = "id" ,
284
+ status = "completed" ,
285
+ )
286
+ ],
287
+ usage = Usage (),
288
+ response_id = None ,
289
+ ),
268
290
ModelResponse (
269
291
output = [
270
292
ResponseOutputMessage (
@@ -304,9 +326,14 @@ async def run(self, question: str) -> str:
304
326
activity_as_tool (
305
327
get_weather_country , start_to_close_timeout = timedelta (seconds = 10 )
306
328
),
329
+ activity_as_tool (
330
+ get_weather_context , start_to_close_timeout = timedelta (seconds = 10 )
331
+ ),
307
332
],
308
333
) # type: Agent
309
- result = await Runner .run (starting_agent = agent , input = question )
334
+ result = await Runner .run (
335
+ starting_agent = agent , input = question , context = "Stormy"
336
+ )
310
337
return result .final_output
311
338
312
339
@@ -337,6 +364,7 @@ async def test_tool_workflow(client: Client, use_local_model: bool):
337
364
get_weather ,
338
365
get_weather_object ,
339
366
get_weather_country ,
367
+ get_weather_context ,
340
368
],
341
369
interceptors = [OpenAIAgentsTracingInterceptor ()],
342
370
) as worker :
@@ -357,7 +385,7 @@ async def test_tool_workflow(client: Client, use_local_model: bool):
357
385
if e .HasField ("activity_task_completed_event_attributes" ):
358
386
events .append (e )
359
387
360
- assert len (events ) == 7
388
+ assert len (events ) == 9
361
389
assert (
362
390
"function_call"
363
391
in events [0 ]
@@ -395,11 +423,23 @@ async def test_tool_workflow(client: Client, use_local_model: bool):
395
423
.data .decode ()
396
424
)
397
425
assert (
398
- "Test weather result "
426
+ "function_call "
399
427
in events [6 ]
400
428
.activity_task_completed_event_attributes .result .payloads [0 ]
401
429
.data .decode ()
402
430
)
431
+ assert (
432
+ "Stormy"
433
+ in events [7 ]
434
+ .activity_task_completed_event_attributes .result .payloads [0 ]
435
+ .data .decode ()
436
+ )
437
+ assert (
438
+ "Test weather result"
439
+ in events [8 ]
440
+ .activity_task_completed_event_attributes .result .payloads [0 ]
441
+ .data .decode ()
442
+ )
403
443
404
444
405
445
class TestPlannerModel (OpenAIResponsesModel ):
0 commit comments