-
Notifications
You must be signed in to change notification settings - Fork 990
Toolsets #2024
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
# Conflicts: # tests/models/test_openai.py
# Conflicts: # pydantic_ai_slim/pydantic_ai/_output.py # pydantic_ai_slim/pydantic_ai/models/openai.py # tests/models/test_openai.py
….)', less 'output_schema.mode == ...'
# Conflicts: # pydantic_ai_slim/pydantic_ai/models/openai.py # pydantic_ai_slim/pydantic_ai/profiles/openai.py # tests/models/test_google.py # tests/models/test_openai_responses.py
# Conflicts: # pydantic_ai_slim/pydantic_ai/_utils.py # pydantic_ai_slim/pydantic_ai/agent.py # tests/models/test_anthropic.py # tests/test_utils.py
# Conflicts: # pydantic_ai_slim/pydantic_ai/tools.py
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR refactors and extends the toolsets mechanism, consolidating function, output, deferred, and MCP‐based tools under a unified AbstractToolset API, and adds support for:
- Custom per‐run preparation, prefixing, and processing of tool definitions
- Deferred tool calls and streaming tool invocation with retry/count tracking
- Passing toolsets to individual
run
/iter
/run_stream
calls, overriding agent‐level toolsets
Reviewed Changes
Copilot reviewed 36 out of 36 changed files in this pull request and generated 3 comments.
Show a summary per file
File | Description |
---|---|
pydantic_ai_slim/pydantic_ai/toolsets/function.py | Implements FunctionToolset for registering Python callables as LLM tools. |
pydantic_ai_slim/pydantic_ai/toolsets/combined.py | Adds CombinedToolset to merge multiple toolsets. |
pydantic_ai_slim/pydantic_ai/toolsets/prefixed.py | Prefixes tool names per run. |
pydantic_ai_slim/pydantic_ai/toolsets/deferred.py | Supports deferred tools that end a run. |
pydantic_ai_slim/pydantic_ai/mcp.py | Migrates MCPServer into the new toolset system. |
pydantic_ai_slim/pydantic_ai/output.py | Integrates output tools into the new toolset model. |
tests/test_toolset.py | Adds comprehensive tests for FunctionToolset. |
tests/test_tools.py | Updates expectations around function toolset lookup and call semantics. |
tests/test_streaming.py | Aligns streaming tests with the new toolset API. |
tests/test_mcp.py | Switches to toolsets and call_tool(ctx, …) API. |
tests/test_agent.py | Reconciles agent‐level toolset construction and naming. |
@claude Review please Edit: GHA is not installed yet 😄 |
# Conflicts: # pydantic_ai_slim/pydantic_ai/agent.py # pydantic_ai_slim/pydantic_ai/mcp.py
…pass sampling_model to MCPServer through RunContext, and make Agent an async contextmanager instead of run_toolsets
… being stored on read broke a test
Toolset
, take 3 #1973To fix:
MCPToolset
To improve:
MCPServer
a toolset, instead of needingMCPServer.as_toolset()
TODO
commentsDeferredToolCalls
withrun_stream
To add:
run
/iter
etc. Should overridetoolsets
passed toAgent
, but not output tools,@agent.tools
tools,Agent(tools=...)
tools, orAgent(mcp_servers=...)
tools. If you want those to be overridden, you should pass them asAgent(toolsets=FunctionToolset(...))
Toolset
, take 3 #1973 (comment)to_chat_completions
method #2041Agent(prepare_output_tools=...)
: Closes Make output_type be conditionally available #2042