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,24 @@ async def test_context_manager_failed_initialization():
500
500
assert server1 .is_running is False
501
501
502
502
503
+ async def test_tool_manager_reuse_self ():
504
+ """Test the retry logic with failed_tools and for_run_step method."""
505
+
506
+ run_context = build_run_context (None , run_step = 1 )
507
+
508
+ tool_manager = ToolManager [None ](run_context , FunctionToolset [None ](), tools = {})
509
+
510
+ same_tool_manager = await tool_manager .for_run_step (ctx = run_context )
511
+
512
+ assert tool_manager is same_tool_manager
513
+
514
+ step_2_context = build_run_context (None , run_step = 2 )
515
+
516
+ updated_tool_manager = await tool_manager .for_run_step (ctx = step_2_context )
517
+
518
+ assert tool_manager != updated_tool_manager
519
+
520
+
503
521
async def test_tool_manager_retry_logic ():
504
522
"""Test the retry logic with failed_tools and for_run_step method."""
505
523
@@ -654,7 +672,7 @@ async def get_tools(self, ctx: RunContext[None]) -> dict[str, ToolsetTool[None]]
654
672
async def call_tool (
655
673
self , name : str , tool_args : dict [str , Any ], ctx : RunContext [None ], tool : ToolsetTool [None ]
656
674
) -> Any :
657
- return None
675
+ return None # pragma: no cover
658
676
659
677
def toolset_factory (ctx : RunContext [None ]) -> AbstractToolset [None ]:
660
678
return EnterableToolset ()
@@ -686,8 +704,8 @@ def visitor(toolset: AbstractToolset[None]) -> None:
686
704
687
705
assert tools == {}
688
706
689
- async def test_dynamic_toolset_empty ():
690
707
708
+ async def test_dynamic_toolset_empty ():
691
709
def no_toolset_func (ctx : RunContext [None ]) -> None :
692
710
return None
693
711
@@ -697,4 +715,4 @@ def no_toolset_func(ctx: RunContext[None]) -> None:
697
715
698
716
tools = await toolset .get_tools (run_context )
699
717
700
- assert tools == {}
718
+ assert tools == {}
0 commit comments