@@ -403,29 +403,30 @@ from function_toolset import weather_toolset, datetime_toolset
403
403
404
404
from pydantic_ai import Agent, RunContext
405
405
from pydantic_ai.models.test import TestModel
406
- from pydantic_ai.toolsets import WrapperToolset, FunctionToolset
406
+ from pydantic_ai.toolsets import WrapperToolset
407
407
408
408
togglable_toolset = WrapperToolset(weather_toolset)
409
409
410
+ test_model = TestModel() # (1)!
411
+ agent = Agent(
412
+ test_model,
413
+ deps_type = WrapperToolset # (2)!
414
+ )
415
+
416
+ @agent.tool
410
417
def toggle (ctx : RunContext[WrapperToolset]):
411
418
if ctx.deps.wrapped == weather_toolset:
412
419
ctx.deps.wrapped = datetime_toolset
413
420
else :
414
421
ctx.deps.wrapped = weather_toolset
415
422
416
- test_model = TestModel() # (1)!
417
- agent = Agent(
418
- test_model,
419
- deps_type = WrapperToolset, # (2)!
420
- toolsets = [togglable_toolset, FunctionToolset([toggle])]
421
- )
422
- result = agent.run_sync(' Toggle the toolset' , deps = togglable_toolset)
423
+ result = agent.run_sync(' Toggle the toolset' , deps = togglable_toolset, toolsets = [togglable_toolset])
423
424
print ([t.name for t in test_model.last_model_request_parameters.function_tools]) # (3)!
424
- # > ['now ', 'toggle ']
425
+ # > ['toggle ', 'now ']
425
426
426
- result = agent.run_sync(' Toggle the toolset' , deps = togglable_toolset)
427
+ result = agent.run_sync(' Toggle the toolset' , deps = togglable_toolset, toolsets = [togglable_toolset] )
427
428
print ([t.name for t in test_model.last_model_request_parameters.function_tools])
428
- # > ['temperature_celsius ', 'temperature_fahrenheit ', 'conditions ', 'toggle ']
429
+ # > ['toggle ', 'temperature_celsius ', 'temperature_fahrenheit ', 'conditions ']
429
430
```
430
431
431
432
1 . We're using [ ` TestModel ` ] [ pydantic_ai.models.test.TestModel ] here because it makes it easy to see which tools were available on each run.
0 commit comments