Skip to content

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

Draft
wants to merge 91 commits into
base: main
Choose a base branch
from
Draft

Toolsets #2024

wants to merge 91 commits into from

Conversation

DouweM
Copy link
Contributor

@DouweM DouweM commented Jun 19, 2025

To fix:

  • MCPToolset
  • Retry counting
  • Streaming tool calls

To improve:

  • Name conflict error messages and logic
  • Performance, caching when possible
  • Considering making MCPServer a toolset, instead of needing MCPServer.as_toolset()
  • Various other TODO comments
  • How output tools are handled
  • DeferredToolCalls with run_stream

To add:

DouweM added 30 commits June 3, 2025 03:20
# 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
# 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
DouweM added 2 commits July 2, 2025 00:10
# Conflicts:
#	pydantic_ai_slim/pydantic_ai/tools.py
@DouweM DouweM requested review from dmontagu and Copilot July 2, 2025 00:19
Copy link

@Copilot Copilot AI left a 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.

@DouweM
Copy link
Contributor Author

DouweM commented Jul 2, 2025

@claude Review please

Edit: GHA is not installed yet 😄

DouweM added 4 commits July 2, 2025 22:43
# 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Make output_type be conditionally available Toolset, take 3
2 participants