Skip to content

FirestoreSessionService crashes on GroundingMetadata from GoogleSearchTool - cannot serialize to Firestore #5840

@Tinnitussen

Description

@Tinnitussen

🔴 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:

  1. 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",
)
  1. Send a query that triggers Google Search (e.g., "Compare MacBook Air and MacBook Pro")
  2. The model delegates to google_search_agent, which returns results with grounding metadata
  3. 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

Metadata

Metadata

Labels

request clarification[Status] The maintainer need clarification or more information from the authorservices[Component] This issue is related to runtime services, e.g. sessions, memory, artifacts, etc

Type

No fields configured for Bug.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions