Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
DouweM merged 162 commits intomainfromtoolsets
Jul 16, 2025
Merged
Show file tree
Hide file tree
Changes from1 commit
Commits
Show all changes
162 commits
Select commitHold shift + click to select a range
e290951
WIP: Output modes
DouweMJun 3, 2025
2056539
WIP: More output modes
DouweMJun 3, 2025
bceba19
Merge remote-tracking branch 'origin/main' into output-modes
DouweMJun 3, 2025
0cb25c4
Fix tests
DouweMJun 3, 2025
933b74e
Remove syntax invalid before Python 3.12
DouweMJun 3, 2025
7974df0
Fix tests
DouweMJun 3, 2025
9cc19e2
Add TextOutput marker
DouweMJun 9, 2025
bc6bb65
Merge remote-tracking branch 'origin/main' into output-modes
DouweMJun 9, 2025
0e356a3
Add VCR recording of new test
DouweMJun 9, 2025
81312dc
Implement additional output modes in GeminiModel and GoogleModel
DouweMJun 10, 2025
52ef4d5
Fix prompted_json on OpenAIResponses
DouweMJun 10, 2025
fe05956
Test output modes on Gemini and Anthropic
DouweMJun 10, 2025
94421f3
Add VCR recordings of Gemini output mode tests
DouweMJun 10, 2025
1902d00
Remove some old TODO comments
DouweMJun 10, 2025
1f53c9b
Add missing VCR recording of Gemini output mode test
DouweMJun 10, 2025
a4c2877
Add more missing VCR recordings
DouweMJun 10, 2025
56e58f9
Fix OpenAI tools
DouweMJun 10, 2025
a5234e1
Improve test coverage
DouweMJun 10, 2025
40def08
Update unsupported output mode error message
DouweMJun 10, 2025
837d305
Improve test coverage
DouweMJun 10, 2025
3598bef
Merge branch 'main' into output-modes
DouweMJun 10, 2025
5f71ba8
Test streaming with structured text output
DouweMJun 10, 2025
cfc2749
Make TextOutputFunction Python 3.9 compatible
DouweMJun 10, 2025
a137641
Properly merge JSON schemas accounting for defs
DouweMJun 11, 2025
f495d46
Refactor output schemas and modes: more 'isinstance(output_schema, ..…
DouweMJun 12, 2025
449ed0d
Merge branch 'main' into output-modes
DouweMJun 12, 2025
e70d249
Clean up some variable names
DouweMJun 12, 2025
4592b0b
Improve test coverage
DouweMJun 12, 2025
db1c628
Merge branch 'main' into output-modes
DouweMJun 13, 2025
f57d078
Combine JsonSchemaOutput and PromptedJsonOutput into StructuredTextOu…
DouweMJun 13, 2025
5112455
Add missing cassettes
DouweMJun 13, 2025
416cc7d
Can't use dataclass kw_only on 3.9
DouweMJun 13, 2025
4b0e5cf
Improve test coverage
DouweMJun 13, 2025
094920f
Improve test coverage
DouweMJun 13, 2025
9f61706
Improve test coverage
DouweMJun 13, 2025
9f51387
Remove unnecessary coverage ignores
DouweMJun 13, 2025
9a1e628
Remove unnecessary coverage ignore
DouweMJun 13, 2025
2b5fa81
Add docs
DouweMJun 13, 2025
6c4662b
Fix docs refs
DouweMJun 13, 2025
3ed3431
Fix nested list in docs
DouweMJun 13, 2025
3d77818
Merge branch 'main' into output-modes
DouweMJun 17, 2025
a86d7d4
Split StructuredTextOutput into ModelStructuredOutput and PromptedStr…
DouweMJun 17, 2025
ce985a0
Merge branch 'main' into output-modes
DouweMJun 17, 2025
71d1655
Fix WrapperModel.profile
DouweMJun 17, 2025
8c04144
Update output modes docs
DouweMJun 17, 2025
d78b5f7
Add examples to output mode marker docstrings
DouweMJun 17, 2025
70d1197
Fix mypy type inference
DouweMJun 17, 2025
2eb7fd1
Improve test coverage
DouweMJun 17, 2025
25ccb54
Merge branch 'main' into output-modes
DouweMJun 17, 2025
9e00c32
Import cast and RunContext in _function_schema
DouweMJun 17, 2025
7de3c0d
Move RunContext and AgentDepsT into their own module to solve circula…
DouweMJun 17, 2025
4029fac
Make _run_context module private, RunContext can be accessed through …
DouweMJun 17, 2025
98bccf2
Merge branch 'main' into output-modes
DouweMJun 19, 2025
8041cf3
Fix thinking part related tests
DouweMJun 19, 2025
9bfed04
Implement Toolset
DouweMJun 20, 2025
0f8da74
Make MCPServer a Toolset
DouweMJun 20, 2025
8a29836
--no-edit
DouweMJun 21, 2025
3d2012c
Add MappedToolset
DouweMJun 21, 2025
901267d
Import Never from typing_extensions instead of typing
DouweMJun 21, 2025
b9258d7
from __future__ import annotations
DouweMJun 21, 2025
27ccbd1
Update client.md
DouweMJun 21, 2025
3031e55
Pass only RunToolset to agent graph
DouweMJun 21, 2025
ebd0b57
Make WrapperToolset abstract
DouweMJun 21, 2025
867bf68
Introduce ToolDefinition.kind == 'pending'
DouweMJun 21, 2025
c1115ae
Rename pending tools to deferred tools
DouweMJun 21, 2025
6abd603
Merge branch 'main' into toolsets
DouweMJun 24, 2025
a2f69df
Fix retries
DouweMJun 24, 2025
0e0bf35
Remove duplicate cassettes
DouweMJun 24, 2025
735df29
Merge branch 'main' into toolsets
DouweMJun 26, 2025
8745a7a
Pass just one toolset into the run
DouweMJun 26, 2025
05aa972
WIP
DouweMJun 26, 2025
ad6e826
Fix streaming tool calls
DouweMJun 27, 2025
84cd954
Stop double counting retries and reset on success
DouweMJun 27, 2025
74a56ae
Fix retry error wrapping
DouweMJun 27, 2025
0360e77
Make DeferredToolCalls work with streaming
DouweMJun 30, 2025
6607b00
Merge branch 'main' into toolsets
DouweMJun 30, 2025
8a3febb
Let toolsets be overridden in run/iter/run_stream/run_sync
DouweMJun 30, 2025
2e200ac
Add DeferredToolset
DouweMJun 30, 2025
1cb7f32
Add LangChainToolset
DouweMJun 30, 2025
a6eba43
Add Agent.prepare_output_tools
DouweMJun 30, 2025
0c96126
Require WrapperToolset subclasses to implement their own prepare_for_run
DouweMJul 1, 2025
2348f45
Require DeferredToolCalls to be used with other output type
DouweMJul 1, 2025
9dc684e
Merge branch 'main' into toolsets
DouweMJul 1, 2025
f3124c0
Lots of cleanup
DouweMJul 1, 2025
f660cc1
Some more tweaks
DouweMJul 2, 2025
64dacbb
Merge branch 'main' into toolsets
DouweMJul 2, 2025
5ca305e
Fix docs example
DouweMJul 2, 2025
c5ef5f6
Address some feedback
DouweMJul 2, 2025
badbe23
Merge branch 'main' into toolsets
DouweMJul 2, 2025
acddb8d
Add sampling_model to Agent __init__, iter, run (etc), and override, …
DouweMJul 2, 2025
89fc266
Turn RunContext.retries from a defaultdict into a dict again as the 0…
DouweMJul 2, 2025
7e3331b
Remove unnecessary if TYPE_CHECKING
DouweMJul 2, 2025
ebf6f40
Remove Agent sampling_model field (and method argument) in favor of A…
DouweMJul 3, 2025
f7db040
Allow OutputSpec to be nested
DouweMJul 3, 2025
fe07149
Document Agent.__aenter__
DouweMJul 3, 2025
a0f4678
Import Self from typing_extensions instead of typing
DouweMJul 3, 2025
db82d00
Actually use Agent.prepare_output_tools
DouweMJul 4, 2025
dea8050
Update test to account for fact that text output with early end_strat…
DouweMJul 4, 2025
131a325
Improve test coverage
DouweMJul 4, 2025
8203732
Merge branch 'main' into toolsets
DouweMJul 4, 2025
778962c
Make Agent MCP-related tests only run when mcp can be imported
DouweMJul 4, 2025
e6575a9
Add tests
DouweMJul 4, 2025
9f9ee55
AbstractToolset.call_tool now takes a ToolCallPart
DouweMJul 4, 2025
a3c9a59
Fix MCP process_tool_call example
DouweMJul 4, 2025
6eae653
Fix test coverage
DouweMJul 4, 2025
2b3a9e5
Merge branch 'main' into toolsets
DouweMJul 4, 2025
b2aa894
Improve coverage
DouweMJul 4, 2025
ecf6f75
Merge branch 'main' into toolsets
DouweMJul 8, 2025
1c2d221
Address feedback
DouweMJul 8, 2025
ca4915b
Make test_docs_examples an async test so Python 3.9 lets us instantia…
DouweMJul 8, 2025
972e4a7
Merge branch 'main' into toolsets
DouweMJul 8, 2025
93bb682
Fix test snapshots
DouweMJul 8, 2025
8a986be
Revert "Make test_docs_examples an async test so Python 3.9 lets us i…
DouweMJul 8, 2025
9c399c7
Make asyncio.Lock work in Python 3.9 when there is no event loop yet
DouweMJul 8, 2025
a4f8c48
Address feedback, fix docs test
DouweMJul 8, 2025
3e1847f
Give the A2A task some more time to complete
DouweMJul 8, 2025
4daa152
Branch is OK to not be covered
DouweMJul 8, 2025
c5c6f00
agent.iter(toolsets=...) is now additional, while new agent.override(…
DouweMJul 9, 2025
f9ba559
Respect overridden toolsets in Agent.__aenter__ and Agent.set_mcp_sam…
DouweMJul 9, 2025
b165503
Fix tool conflict error message
DouweMJul 9, 2025
4baa710
Rename FunctionToolset.register_{tool,function} to add_{tool,function}
DouweMJul 9, 2025
39e0353
Branch is OK to not be covered
DouweMJul 9, 2025
18fcdf7
Add test to ensure tools can be added during a run
DouweMJul 9, 2025
af6ce7d
Make CallableToolset public as we're going to want to let people defi…
DouweMJul 9, 2025
93e6691
Make it easier to override tool call behavior by subclassing WrapperT…
DouweMJul 10, 2025
3a4c4c8
Start writing docs
DouweMJul 10, 2025
87aaa6c
Make WrapperToolset easier to subclass with new _rewrap_for_run method
DouweMJul 10, 2025
8b81e65
Add classes I forget to add and push
DouweMJul 10, 2025
e72548e
Make all public toolsets importable from pydantic_ai.toolsets
DouweMJul 10, 2025
b8c93f1
Add ACIToolset
DouweMJul 10, 2025
f87319c
Document LangChainToolset and ACIToolset
DouweMJul 10, 2025
8136441
Merge branch 'main' into toolsets
DouweMJul 10, 2025
239fc3d
Toolset._call_tool is always async
DouweMJul 10, 2025
febbd08
A WrapperToolset subclass with no additional fields does not need to …
DouweMJul 10, 2025
cfa9ccc
Add some more docs
DouweMJul 10, 2025
50a72a0
Merge branch 'main' into toolsets
DouweMJul 10, 2025
0151e20
Mostly finish docs
DouweMJul 11, 2025
d27b4ec
Fix FunctionToolset.max_retries
DouweMJul 11, 2025
692898e
Fix docs example output
DouweMJul 11, 2025
06838e2
Make AbstractToolset overridable methods public
DouweMJul 15, 2025
215eaae
Merge branch 'main' into toolsets
DouweMJul 15, 2025
8018600
Merge remote-tracking branch 'origin/toolsets' into toolsets
DouweMJul 15, 2025
b2637f8
WIP
DouweMJul 15, 2025
a25df7f
WIP
DouweMJul 15, 2025
13d9c03
Remove AbstractToolset.for_run_step
DouweMJul 15, 2025
ac5f77d
Rename AbstractToolset.accept to apply
DouweMJul 15, 2025
0c8b25a
Fix toolsets docs
DouweMJul 15, 2025
6046a1c
Fix example for 3.9
DouweMJul 15, 2025
70d24da
Update docs
DouweMJul 15, 2025
a4dedb3
Improve coverage
DouweMJul 15, 2025
f48bd73
Improve docstrings
DouweMJul 15, 2025
a4e0c04
Improve docstrings
DouweMJul 16, 2025
fef897d
Fix docs link
DouweMJul 16, 2025
9d3d240
Fix docs links
DouweMJul 16, 2025
f3d1ae0
Add filtered, prefixed, prepared, renamed and wrap convenience method…
DouweMJul 16, 2025
f756132
Merge branch 'main' into toolsets
DouweMJul 16, 2025
57b0720
Move tool call tracing to ToolManager
DouweMJul 16, 2025
e2e0f58
Merge branch 'main' into toolsets
DouweMJul 16, 2025
7830c73
Fix huggingface_hub.AsyncInferenceClient link in docs
DouweMJul 16, 2025
c9c8873
Add huggingface doc to nav
DouweMJul 16, 2025
7e4629e
Fix coverage
DouweMJul 16, 2025
28c753d
Fix coverage
DouweMJul 16, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
PrevPrevious commit
NextNext commit
Add LangChainToolset
  • Loading branch information
@DouweM
DouweM committedJun 30, 2025
commit1cb7f324b499240315b70de2de61849af4f00a28
10 changes: 9 additions & 1 deletionpydantic_ai_slim/pydantic_ai/ext/langchain.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -3,6 +3,7 @@
from pydantic.json_schema import JsonSchemaValue

from pydantic_ai.tools import Tool
from pydantic_ai.toolset import FunctionToolset


class LangChainTool(Protocol):
Expand All@@ -23,7 +24,7 @@ def description(self) -> str: ...
def run(self, *args: Any, **kwargs: Any) -> str: ...


__all__ = ('tool_from_langchain',)
__all__ = ('tool_from_langchain', 'LangChainToolset')


def tool_from_langchain(langchain_tool: LangChainTool) -> Tool:
Expand DownExpand Up@@ -59,3 +60,10 @@ def proxy(*args: Any, **kwargs: Any) -> str:
description=function_description,
json_schema=schema,
)


class LangChainToolset(FunctionToolset):
"""A toolset that wraps LangChain tools."""

def __init__(self, tools: list[LangChainTool]):
super().__init__([tool_from_langchain(tool) for tool in tools])
6 changes: 1 addition & 5 deletionspydantic_ai_slim/pydantic_ai/toolset.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -46,7 +46,7 @@ class AbstractToolset(ABC, Generic[AgentDepsT]):

@property
def name(self) -> str:
return self.__class__.__name__
return self.__class__.__name__.replace('Toolset', ' toolset')

@property
def name_conflict_hint(self) -> str:
Expand DownExpand Up@@ -110,10 +110,6 @@ class FunctionToolset(AbstractToolset[AgentDepsT]):
max_retries: int = field(default=1)
tools: dict[str, Tool[Any]] = field(default_factory=dict)

@property
def name(self) -> str:
return 'FunctionToolset'

def __init__(self, tools: Sequence[Tool[AgentDepsT] | ToolFuncEither[AgentDepsT, ...]] = [], max_retries: int = 1):
self.max_retries = max_retries
self.tools = {}
Expand Down
45 changes: 27 additions & 18 deletionstests/ext/test_langchain.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -6,7 +6,7 @@
from pydantic.json_schema import JsonSchemaValue

from pydantic_ai import Agent
from pydantic_ai.ext.langchain import tool_from_langchain
from pydantic_ai.ext.langchain importLangChainToolset,tool_from_langchain


@dataclass
Expand DownExpand Up@@ -49,31 +49,40 @@ def get_input_jsonschema(self) -> JsonSchemaValue:
}


def test_langchain_tool_conversion():
langchain_tool = SimulatedLangChainTool(
name='file_search',
description='Recursively search for files in a subdirectory that match the regex pattern',
args={
'dir_path': {
'default': '.',
'description': 'Subdirectory to search in.',
'title': 'Dir Path',
'type': 'string',
},
'pattern': {
'description': 'Unix shell regex, where * matches everything.',
'title': 'Pattern',
'type': 'string',
},
langchain_tool = SimulatedLangChainTool(
name='file_search',
description='Recursively search for files in a subdirectory that match the regex pattern',
args={
'dir_path': {
'default': '.',
'description': 'Subdirectory to search in.',
'title': 'Dir Path',
'type': 'string',
},
)
'pattern': {
'description': 'Unix shell regex, where * matches everything.',
'title': 'Pattern',
'type': 'string',
},
},
)


def test_langchain_tool_conversion():
pydantic_tool = tool_from_langchain(langchain_tool)

agent = Agent('test', tools=[pydantic_tool], retries=7)
result = agent.run_sync('foobar')
assert result.output == snapshot("{\"file_search\":\"I was called with {'dir_path': '.', 'pattern': 'a'}\"}")


def test_langchain_toolset():
toolset = LangChainToolset([langchain_tool])
agent = Agent('test', toolsets=[toolset], retries=7)
result = agent.run_sync('foobar')
assert result.output == snapshot("{\"file_search\":\"I was called with {'dir_path': '.', 'pattern': 'a'}\"}")


def test_langchain_tool_no_additional_properties():
langchain_tool = SimulatedLangChainTool(
name='file_search',
Expand Down
2 changes: 1 addition & 1 deletiontests/test_tools.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -589,7 +589,7 @@ def test_tool_return_conflict():
# this raises an error
with pytest.raises(
UserError,
match="FunctionToolset defines a tool whose name conflicts with existing tool from OutputToolset: 'ctx_tool'. Consider renaming the tool or wrapping the toolset in a `PrefixedToolset` to avoid name conflicts.",
match="Function toolset defines a tool whose name conflicts with existing tool from OutputToolset: 'ctx_tool'. Consider renaming the tool or wrapping the toolset in a `PrefixedToolset` to avoid name conflicts.",
):
Agent('test', tools=[ctx_tool], deps_type=int, output_type=ToolOutput(int, name='ctx_tool'))

Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp