🔴 Required Information
Describe the Bug:
When using GoogleSearchTool with FirestoreSessionService, the session service fails to persist the model's response event because it contains a GroundingMetadata protobuf object that cannot be converted to a Firestore value. This causes the agent response to never be delivered to the client — the SSE stream emits an error instead of the text response.
Steps to Reproduce:
- Configure an agent with
GoogleSearchTool and Firestore session service:
from google.adk.agents import LlmAgent
from google.adk.cli.fast_api import get_fast_api_app
from google.adk.tools.google_search_tool import GoogleSearchTool
root_agent = LlmAgent(
model="gemini-2.5-flash",
name="my_agent",
instruction="You are a helpful assistant.",
tools=[GoogleSearchTool()],
)
app = get_fast_api_app(
agents_dir=".",
session_service_uri="firestore://my-project",
)
- Send a query that triggers Google Search (e.g., "Compare MacBook Air and MacBook Pro")
- The model delegates to
google_search_agent, which returns results with grounding metadata
- The session service attempts to persist the event to Firestore and fails with:
('Cannot convert to a Firestore Value', GroundingMetadata(...), 'Invalid type', <class 'google.genai.types.GroundingMetadata'>)
Expected Behavior:
The FirestoreSessionService should serialize all objects in the model response (including GroundingMetadata) to Firestore-compatible types before writing. The agent's text response should be delivered to the client via SSE.
Observed Behavior:
The SSE stream emits an error event and the final text response is never delivered:
{"error": "('Cannot convert to a Firestore Value', GroundingMetadata(\n grounding_chunks=[...],\n grounding_supports=[...],\n search_entry_point=SearchEntryPoint(...),\n web_search_queries=[...]\n), 'Invalid type', <class 'google.genai.types.GroundingMetadata'>)"}
Environment Details:
- ADK Library Version: google-adk 2.1.0
- Desktop OS: Linux (Cloud Run container)
- Python Version: 3.12
Model Information:
- Are you using LiteLLM: No
- Which model is being used: gemini-2.5-flash (Vertex AI)
🟡 Optional Information
Regression:
Unknown — this is the first time the google_search_agent sub-agent returned results with GroundingMetadata for our queries. It may depend on whether the model decides to ground its response.
Logs:
data: {"error": "('Cannot convert to a Firestore Value', GroundingMetadata(\n grounding_chunks=[\n GroundingChunk(\n web=GroundingChunkWeb(\n domain='forbrukertest.no',\n title='forbrukertest.no',\n uri='https://vertexaisearch.cloud.google.com/grounding-api-redirect/...'\n )\n ),\n ...\n ],\n grounding_supports=[...],\n retrieval_metadata=RetrievalMetadata(),\n search_entry_point=SearchEntryPoint(rendered_content=\"...\"),\n web_search_queries=['MacBook Air vs MacBook Pro sammenligning', ...]\n), 'Invalid type', <class 'google.genai.types.GroundingMetadata'>)"}
Additional Context:
The issue occurs specifically when GoogleSearchTool is used as a sub-agent tool (the model emits a functionCall to google_search_agent). The GroundingMetadata object is attached to the sub-agent's response and then ADK tries to write it to Firestore as part of the session event. The object is a complex protobuf/Pydantic type that Firestore's Python client cannot natively serialize.
Using InMemorySessionService does not trigger this bug since no serialization is needed.
Minimal Reproduction Code:
from google.adk.agents import LlmAgent
from google.adk.cli.fast_api import get_fast_api_app
from google.adk.tools.google_search_tool import GoogleSearchTool
root_agent = LlmAgent(
model="gemini-2.5-flash",
name="test_agent",
instruction="Use Google Search to answer questions.",
tools=[GoogleSearchTool()],
)
app = get_fast_api_app(
agents_dir=".",
session_service_uri="firestore://my-project",
)
# Send: "Compare MacBook Air and MacBook Pro" → triggers grounding → crash
How often has this issue occurred?:
- Always (100%) — every time
google_search_agent returns grounded results
🔴 Required Information
Describe the Bug:
When using
GoogleSearchToolwithFirestoreSessionService, the session service fails to persist the model's response event because it contains aGroundingMetadataprotobuf object that cannot be converted to a Firestore value. This causes the agent response to never be delivered to the client — the SSE stream emits an error instead of the text response.Steps to Reproduce:
GoogleSearchTooland Firestore session service:google_search_agent, which returns results with grounding metadataExpected Behavior:
The
FirestoreSessionServiceshould serialize all objects in the model response (includingGroundingMetadata) to Firestore-compatible types before writing. The agent's text response should be delivered to the client via SSE.Observed Behavior:
The SSE stream emits an error event and the final text response is never delivered:
{"error": "('Cannot convert to a Firestore Value', GroundingMetadata(\n grounding_chunks=[...],\n grounding_supports=[...],\n search_entry_point=SearchEntryPoint(...),\n web_search_queries=[...]\n), 'Invalid type', <class 'google.genai.types.GroundingMetadata'>)"}Environment Details:
Model Information:
🟡 Optional Information
Regression:
Unknown — this is the first time the
google_search_agentsub-agent returned results withGroundingMetadatafor our queries. It may depend on whether the model decides to ground its response.Logs:
Additional Context:
The issue occurs specifically when
GoogleSearchToolis used as a sub-agent tool (the model emits afunctionCalltogoogle_search_agent). TheGroundingMetadataobject is attached to the sub-agent's response and then ADK tries to write it to Firestore as part of the session event. The object is a complex protobuf/Pydantic type that Firestore's Python client cannot natively serialize.Using
InMemorySessionServicedoes not trigger this bug since no serialization is needed.Minimal Reproduction Code:
How often has this issue occurred?:
google_search_agentreturns grounded results