* VertexAiSearchTool dynamic config according to issue #1227 - 7 Added dynamic configuration per the bot's suggestion, but I improved snippet and description. * Update agent-search.md * Align snippet param name with SDK signature (readonly_context) --------- Co-authored-by: Kristopher Overholt <koverholt@google.com>
2.3 KiB
catalog_title, catalog_description, catalog_icon, catalog_tags
| catalog_title | catalog_description | catalog_icon | catalog_tags | ||
|---|---|---|---|---|---|
| Agent Search | Search across your private, configured data stores in Agent Search | /integrations/assets/agent-platform.svg |
|
Agent Search tool for ADK
The vertex_ai_search_tool uses Google Cloud Agent Search, enabling the
agent to search across your private, configured data stores (e.g., internal
documents, company policies, knowledge bases). This built-in tool requires you
to provide the specific data store ID during configuration. For further details
of the tool, see
Understanding Grounding with Search.
!!! warning "Warning: Single tool per agent limitation"
This tool can only be used ***by itself*** within an agent instance.
For more information about this limitation and workarounds, see
[Limitations for ADK tools](/tools/limitations/#one-tool-one-agent).
--8<-- "examples/python/snippets/tools/built-in-tools/agent_search.py"
Dynamic configuration
You can create a subclass of VertexAiSearchTool and override the
_build_vertex_ai_search_config method to dynamically configure the search
settings based on the conversation context. This approach is useful for
implementing features such as per-user data filtering.
The _build_vertex_ai_search_config method receives the conversation
readonly_context as an argument. You can use this context to access state
information and adjust the search configuration at runtime.
from google.genai import types
from google.adk.agents.readonly_context import ReadonlyContext
from google.adk.tools import VertexAiSearchTool
class MyVertexAISearchTool(VertexAiSearchTool):
def _build_vertex_ai_search_config(
self, readonly_context: ReadonlyContext
) -> types.VertexAISearch:
"""Builds the VertexAISearch configuration, adding a user-specific filter."""
config = super()._build_vertex_ai_search_config(readonly_context)
if "user_id" in readonly_context.state:
user_id = readonly_context.state["user_id"]
config.filter = f'user_id: ANY("{user_id}")'
return config