16
16
from pydantic_ai .messages import ToolCallPart
17
17
from pydantic_ai .models .test import TestModel
18
18
from pydantic_ai .tools import ToolDefinition
19
- from pydantic_ai .toolsets ._dynamic import _DynamicToolset as DynamicToolset
19
+ from pydantic_ai .toolsets ._dynamic import _DynamicToolset as DynamicToolset # pyright: ignore[reportPrivateUsage]
20
20
from pydantic_ai .toolsets .abstract import AbstractToolset , ToolsetTool
21
21
from pydantic_ai .toolsets .combined import CombinedToolset
22
22
from pydantic_ai .toolsets .filtered import FilteredToolset
@@ -500,6 +500,25 @@ async def test_context_manager_failed_initialization():
500
500
assert server1 .is_running is False
501
501
502
502
503
+
504
+ async def test_tool_manager_reuse_self ():
505
+ """Test the retry logic with failed_tools and for_run_step method."""
506
+
507
+ run_context = build_run_context (None , run_step = 1 )
508
+
509
+ tool_manager = ToolManager [None ](run_context , FunctionToolset [None ](), tools = {})
510
+
511
+ same_tool_manager = await tool_manager .for_run_step (ctx = run_context )
512
+
513
+ assert tool_manager is same_tool_manager
514
+
515
+ step_2_context = build_run_context (None , run_step = 2 )
516
+
517
+ updated_tool_manager = await tool_manager .for_run_step (ctx = step_2_context )
518
+
519
+ assert tool_manager != updated_tool_manager
520
+
521
+
503
522
async def test_tool_manager_retry_logic ():
504
523
"""Test the retry logic with failed_tools and for_run_step method."""
505
524
@@ -654,7 +673,7 @@ async def get_tools(self, ctx: RunContext[None]) -> dict[str, ToolsetTool[None]]
654
673
async def call_tool (
655
674
self , name : str , tool_args : dict [str , Any ], ctx : RunContext [None ], tool : ToolsetTool [None ]
656
675
) -> Any :
657
- return None
676
+ return None # pragma: no cover
658
677
659
678
def toolset_factory (ctx : RunContext [None ]) -> AbstractToolset [None ]:
660
679
return EnterableToolset ()
@@ -686,8 +705,8 @@ def visitor(toolset: AbstractToolset[None]) -> None:
686
705
687
706
assert tools == {}
688
707
689
- async def test_dynamic_toolset_empty ():
690
708
709
+ async def test_dynamic_toolset_empty ():
691
710
def no_toolset_func (ctx : RunContext [None ]) -> None :
692
711
return None
693
712
@@ -697,4 +716,4 @@ def no_toolset_func(ctx: RunContext[None]) -> None:
697
716
698
717
tools = await toolset .get_tools (run_context )
699
718
700
- assert tools == {}
719
+ assert tools == {}
0 commit comments