Skip to content

Commit 1f2e59b

Browse files
wukathcopybara-github
authored andcommitted
fix: Only send grounding_metadata for 3.1 live at the end of each turn
Co-authored-by: Kathy Wu <wukathy@google.com> PiperOrigin-RevId: 930043971
1 parent 03671c6 commit 1f2e59b

2 files changed

Lines changed: 7 additions & 12 deletions

File tree

src/google/adk/models/gemini_llm_connection.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -205,8 +205,7 @@ def __build_full_text_response(
205205
part = types.Part.from_text(text=text)
206206
if is_thought:
207207
part.thought = True
208-
if grounding_metadata is None and self._is_gemini_3_1_flash_live:
209-
grounding_metadata = types.GroundingMetadata()
208+
210209
return LlmResponse(
211210
content=types.Content(
212211
role='model',
@@ -281,8 +280,6 @@ async def receive(self) -> AsyncGenerator[LlmResponse, None]:
281280
llm_response.grounding_metadata = (
282281
message.server_content.grounding_metadata
283282
)
284-
elif self._is_gemini_3_1_flash_live:
285-
llm_response.grounding_metadata = types.GroundingMetadata()
286283
if content.parts[0].text:
287284
current_is_thought = getattr(content.parts[0], 'thought', False)
288285
if text and current_is_thought != is_thought:
@@ -471,7 +468,6 @@ async def receive(self) -> AsyncGenerator[LlmResponse, None]:
471468
content=types.Content(role='model', parts=tool_call_parts),
472469
model_version=self._model_version,
473470
live_session_id=live_session_id,
474-
grounding_metadata=types.GroundingMetadata(),
475471
)
476472
tool_call_parts = []
477473
if message.session_resumption_update:

tests/unittests/models/test_gemini_llm_connection.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1645,23 +1645,22 @@ async def mock_receive_generator():
16451645
responses = [resp async for resp in conn.receive()]
16461646

16471647
# Expected:
1648-
# responses[0] -> partial content response for msg1 (has grounding_metadata)
1649-
# responses[1] -> full text response for msg1 (has grounding_metadata)
1650-
# responses[2] -> tool call response for msg2 (has grounding_metadata)
1648+
# responses[0] -> partial content response for msg1 (has no grounding_metadata)
1649+
# responses[1] -> full text response for msg1 (has no grounding_metadata)
1650+
# responses[2] -> tool call response for msg2 (has no grounding_metadata)
16511651
# responses[3] -> turn_complete response for msg3 (has grounding_metadata)
16521652
assert len(responses) == 4
16531653

16541654
assert responses[0].content.parts[0].text == 'hello'
1655-
assert isinstance(responses[0].grounding_metadata, types.GroundingMetadata)
1656-
assert responses[0].grounding_metadata.web_search_queries is None
1655+
assert responses[0].grounding_metadata is None
16571656
assert responses[0].partial is True
16581657

16591658
assert responses[1].content.parts[0].text == 'hello'
1660-
assert isinstance(responses[1].grounding_metadata, types.GroundingMetadata)
1659+
assert responses[1].grounding_metadata is None
16611660
assert responses[1].partial is False
16621661

16631662
assert responses[2].content.parts[0].function_call.name == 'foo'
1664-
assert isinstance(responses[2].grounding_metadata, types.GroundingMetadata)
1663+
assert responses[2].grounding_metadata is None
16651664

16661665
assert responses[3].turn_complete is True
16671666
assert isinstance(responses[3].grounding_metadata, types.GroundingMetadata)

0 commit comments

Comments
 (0)