@@ -403,29 +403,30 @@ from function_toolset import weather_toolset, datetime_toolset
403403
404404from pydantic_ai import Agent, RunContext
405405from pydantic_ai.models.test import TestModel
406- from pydantic_ai.toolsets import WrapperToolset, FunctionToolset
406+ from pydantic_ai.toolsets import WrapperToolset
407407
408408togglable_toolset = WrapperToolset(weather_toolset)
409409
410+ test_model = TestModel() # (1)!
411+ agent = Agent(
412+ test_model,
413+ deps_type = WrapperToolset # (2)!
414+ )
415+
416+ @agent.tool
410417def toggle (ctx : RunContext[WrapperToolset]):
411418 if ctx.deps.wrapped == weather_toolset:
412419 ctx.deps.wrapped = datetime_toolset
413420 else :
414421 ctx.deps.wrapped = weather_toolset
415422
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])
423424print ([t.name for t in test_model.last_model_request_parameters.function_tools]) # (3)!
424- # > ['now ', 'toggle ']
425+ # > ['toggle ', 'now ']
425426
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] )
427428print ([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 ']
429430```
430431
4314321 . 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