File tree Expand file tree Collapse file tree 2 files changed +8
-1
lines changed Expand file tree Collapse file tree 2 files changed +8
-1
lines changed Original file line number Diff line number Diff line change 3232from ..plugins .plugin_manager import PluginManager
3333from ..sessions .base_session_service import BaseSessionService
3434from ..sessions .session import Session
35+ from ..tools .base_tool import BaseTool
3536from .active_streaming_tool import ActiveStreamingTool
3637from .base_agent import BaseAgent
3738from .base_agent import BaseAgentState
@@ -202,6 +203,9 @@ class InvocationContext(BaseModel):
202203 plugin_manager : PluginManager = Field (default_factory = PluginManager )
203204 """The manager for keeping track of plugins in this invocation."""
204205
206+ canonical_tools_cache : Optional [list [BaseTool ]] = None
207+ """The cache of canonical tools for this invocation."""
208+
205209 _invocation_cost_manager : _InvocationCostManager = PrivateAttr (
206210 default_factory = _InvocationCostManager
207211 )
Original file line number Diff line number Diff line change @@ -842,7 +842,10 @@ async def _maybe_add_grounding_metadata(
842842 response : Optional [LlmResponse ] = None ,
843843 ) -> Optional [LlmResponse ]:
844844 readonly_context = ReadonlyContext (invocation_context )
845- tools = await agent .canonical_tools (readonly_context )
845+ if (tools := invocation_context .canonical_tools_cache ) is None :
846+ tools = await agent .canonical_tools (readonly_context )
847+ invocation_context .canonical_tools_cache = tools
848+
846849 if not any (tool .name == 'google_search_agent' for tool in tools ):
847850 return response
848851 ground_metadata = invocation_context .session .state .get (
You can’t perform that action at this time.
0 commit comments