File tree Expand file tree Collapse file tree 4 files changed +18
-4
lines changed
Expand file tree Collapse file tree 4 files changed +18
-4
lines changed Original file line number Diff line number Diff line change @@ -82,6 +82,7 @@ def __init__(
8282 self .tool_name_prefix = tool_name_prefix
8383 self ._cached_invocation_id : Optional [str ] = None
8484 self ._cached_prefixed_tools : Optional [list [BaseTool ]] = None
85+ self ._use_invocation_cache = True
8586
8687 @abstractmethod
8788 async def get_tools (
@@ -117,7 +118,8 @@ async def get_tools_with_prefix(
117118 invocation_id = readonly_context .invocation_id if readonly_context else None
118119
119120 if (
120- self ._cached_prefixed_tools is not None
121+ self ._use_invocation_cache
122+ and self ._cached_prefixed_tools is not None
121123 and self ._cached_invocation_id == invocation_id
122124 ):
123125 return self ._cached_prefixed_tools
Original file line number Diff line number Diff line change @@ -700,6 +700,7 @@ def __init__(
700700 self ._skills = {skill .name : skill for skill in skills }
701701 self ._code_executor = code_executor
702702 self ._script_timeout = script_timeout
703+ self ._use_invocation_cache = False
703704
704705 self ._provided_tools_by_name = {}
705706 self ._provided_toolsets = []
Original file line number Diff line number Diff line change @@ -438,3 +438,13 @@ async def test_get_tools_with_prefix_caching():
438438 assert len (tools3 ) == 1
439439 assert tools3 is not tools1 # Should be a new list instance
440440 assert tools3 [0 ].name == 'test_tool1'
441+
442+ # Test disabling caching
443+ toolset ._use_invocation_cache = False
444+ tools4 = await toolset .get_tools_with_prefix (
445+ readonly_context = readonly_context2
446+ )
447+ tools5 = await toolset .get_tools_with_prefix (
448+ readonly_context = readonly_context2
449+ )
450+ assert tools4 is not tools5
Original file line number Diff line number Diff line change @@ -1340,16 +1340,17 @@ def my_func():
13401340
13411341 ctx = _make_tool_context_with_agent ()
13421342 # Initial tools (only core)
1343- tools = await toolset .get_tools (readonly_context = ctx )
1344- assert len (tools ) == 4
1343+ tools1 = await toolset .get_tools_with_prefix (readonly_context = ctx )
1344+ assert len (tools1 ) == 4
13451345
13461346 # Activate skills
13471347 load_tool = skill_toolset .LoadSkillTool (toolset )
13481348 await load_tool .run_async (args = {"name" : "skill1" }, tool_context = ctx )
13491349 await load_tool .run_async (args = {"name" : "skill2" }, tool_context = ctx )
13501350
13511351 # Dynamic tools should now be resolved
1352- tools = await toolset .get_tools (readonly_context = ctx )
1352+ tools = await toolset .get_tools_with_prefix (readonly_context = ctx )
1353+ assert tools is not tools1
13531354 tool_names = {t .name for t in tools }
13541355
13551356 # Core tools
You can’t perform that action at this time.
0 commit comments