Files
google__adk-docs/docs/integrations/agent-search.md
Zyan 3e6ee758f2 VertexAiSearchTool dynamic config according to issue #1227 - 7 (#1968)
* 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>
2026-07-16 07:08:41 -05:00

58 lines
2.3 KiB
Markdown

---
catalog_title: Agent Search
catalog_description: Search across your private, configured data stores in Agent Search
catalog_icon: /integrations/assets/agent-platform.svg
catalog_tags: ["search","google"]
---
# Agent Search tool for ADK
<div class="language-support-tag">
<span class="lst-supported">Supported in ADK</span><span class="lst-python">Python v0.1.0</span>
</div>
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](/grounding/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).
```py
--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.
```python
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
```