File tree Expand file tree Collapse file tree 2 files changed +11
-1
lines changed Expand file tree Collapse file tree 2 files changed +11
-1
lines changed Original file line number Diff line number Diff line change 2424from pydantic import Field
2525from pydantic import PrivateAttr
2626
27+ from google .adk .tools .base_tool import BaseTool
28+
2729from ..apps .app import ResumabilityConfig
2830from ..artifacts .base_artifact_service import BaseArtifactService
2931from ..auth .credential_service .base_credential_service import BaseCredentialService
@@ -202,6 +204,9 @@ class InvocationContext(BaseModel):
202204 plugin_manager : PluginManager = Field (default_factory = PluginManager )
203205 """The manager for keeping track of plugins in this invocation."""
204206
207+ canonical_tools_cache : Optional [list [BaseTool ]] = None
208+ """The cache of canonical tools for this invocation."""
209+
205210 _invocation_cost_manager : _InvocationCostManager = PrivateAttr (
206211 default_factory = _InvocationCostManager
207212 )
Original file line number Diff line number Diff line change @@ -842,7 +842,12 @@ 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 invocation_context .canonical_tools_cache is None :
846+ tools = await agent .canonical_tools (readonly_context )
847+ invocation_context .canonical_tools_cache = tools
848+ else :
849+ tools = invocation_context .canonical_tools_cache
850+
846851 if not any (tool .name == 'google_search_agent' for tool in tools ):
847852 return response
848853 ground_metadata = invocation_context .session .state .get (
You can’t perform that action at this time.
0 commit comments