feat(tools): Add debug logging to VertexAiSearchTool

Merge https://github.com/google/adk-python/pull/3284

**Problem:**
When debugging agents that utilize the `VertexAiSearchTool`, it's currently difficult to inspect the specific configuration parameters (datastore ID, engine ID, filter, max_results, etc.) being passed to the underlying Vertex AI Search API via the `LlmRequest`. This lack of visibility can hinder troubleshooting efforts related to tool configuration.

**Solution:**
This PR enhances the `VertexAiSearchTool` by adding a **debug-level log statement** within the `process_llm_request` method. This log precisely records the parameters being used for the Vertex AI Search configuration just before it's appended to the `LlmRequest`.

This provides developers with crucial visibility into the tool's runtime behavior when debug logging is enabled, significantly improving the **debuggability** of agents using this tool. Corresponding unit tests were updated to rigorously verify this new logging output using `caplog`. Additionally, minor fixes were made to the tests to resolve Pydantic validation errors.

Co-authored-by: Xuan Yang <xygoogle@google.com>
COPYBARA_INTEGRATE_REVIEW=https://github.com/google/adk-python/pull/3284 from omkute10:feat/add-logging-vertex-search-tool 199c12bf00a57abe202401591088c0423b39b928
PiperOrigin-RevId: 836419886
This commit is contained in:
Om Kute
2025-11-24 17:29:50 -08:00
committed by Copybara-Service
parent b331d97dfb
commit c6e7d6b16a
2 changed files with 170 additions and 12 deletions
@@ -14,6 +14,7 @@
from __future__ import annotations
import logging
from typing import Optional
from typing import TYPE_CHECKING
@@ -25,6 +26,8 @@ from ..utils.model_name_utils import is_gemini_model
from .base_tool import BaseTool
from .tool_context import ToolContext
logger = logging.getLogger('google_adk.' + __name__)
if TYPE_CHECKING:
from ..models import LlmRequest
@@ -102,6 +105,30 @@ class VertexAiSearchTool(BaseTool):
)
llm_request.config = llm_request.config or types.GenerateContentConfig()
llm_request.config.tools = llm_request.config.tools or []
# Format data_store_specs concisely for logging
if self.data_store_specs:
spec_ids = [
spec.data_store.split('/')[-1] if spec.data_store else 'unnamed'
for spec in self.data_store_specs
]
specs_info = (
f'{len(self.data_store_specs)} spec(s): [{", ".join(spec_ids)}]'
)
else:
specs_info = None
logger.debug(
'Adding Vertex AI Search tool config to LLM request: '
'datastore=%s, engine=%s, filter=%s, max_results=%s, '
'data_store_specs=%s',
self.data_store_id,
self.search_engine_id,
self.filter,
self.max_results,
specs_info,
)
llm_request.config.tools.append(
types.Tool(
retrieval=types.Retrieval(