Skip to content

fix(llminternal): keep grounding metadata on live responses - #2265

Open
VISHNU0906 wants to merge 1 commit into
google:mainfrom
VISHNU0906:fix/2262-live-grounding-metadata
Open

VISHNU0906 wants to merge 1 commit into
google:mainfrom
VISHNU0906:fix/2262-live-grounding-metadata

Conversation

@VISHNU0906

Copy link
Copy Markdown
Contributor

Linked issue

Problem:

In a live session the grounding metadata the Live API sends never reaches the events. LiveConnection.Recv copies the model turn, TurnComplete, Interrupted and the transcriptions from ServerContent, but not ServerContent.GroundingMetadata. So an agent with google_search (or another grounding tool) under RunLive gets no search queries, sources or supports, while the same agent under Runner.Run does.

Solution:

Recv now copies ServerContent.GroundingMetadata onto the response it builds. A message that carries only grounding becomes its own response, the same as in adk-python's gemini_llm_connection.py. The live flow already turns every response into an event, so nothing else needed to change.

adk-python also merges the grounding chunks of a turn. I left that out to keep this small, and can follow up if you want it.

Testing Plan

Unit Tests:

  • All unit tests pass locally.

New tests in internal/llminternal/googlellm/live_connection_test.go, going through a real genai Live session on the fake websocket server:

  • TestLiveConnectionRecvCarriesGroundingMetadata: grounding with a model turn, grounding only, and grounding on a turn-complete message.
  • TestLiveConnectionRecvKeepsGroundingOnBufferedTurnComplete: when a turn ends with buffered transcriptions, the grounding stays on the turn-complete response delivered after them.

With your source change reverted and your tests kept, which test fails?

Both tests fail (all four cases).

Gates on the branch (main 11f4e29): gofmt, go mod tidy -diff, go build ./..., go vet, go test -race -count=1 ./... (118 packages ok), golangci-lint v2.3.1: 0 issues.

Manual End-to-End (E2E) Tests:

I don't have Live API access with grounding, so this is covered by the wire-level tests above.

Checklist

  • I have read the CONTRIBUTING.md document.
  • I have performed a self-review of my own code.
  • I have commented my code, particularly in hard-to-understand areas.
  • I have added tests that prove my fix is effective or that my feature works.
  • New and existing unit tests pass locally with my changes.
  • I have manually tested my changes end-to-end.
  • Any dependent changes have been merged and published in downstream modules.

LiveConnection.Recv copied the model turn, turn and interruption flags
and transcriptions from ServerContent, but not GroundingMetadata. An
agent using a grounding tool such as google_search under RunLive got
events with no search queries, sources or supports, while the same agent
under Runner.Run got them.

Copy ServerContent.GroundingMetadata onto the response, including
messages that carry only grounding, as adk-python does.

Fixes google#2262

Signed-off-by: KVR Vishnu <[email protected]>

@caohy1988 caohy1988 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks right. Recv now copies the full GroundingMetadata value onto the response before it can land in the transcription buffer, so grounding-only messages become events and a buffered turn-complete still keeps its sources. The new websocket tests cover content-bearing, grounding-only, turn-complete, and delayed delivery after buffered transcription, and they fail if the assignment is reverted.

Leaving turn-level merging of grounding chunks for a follow-up, as you noted, is reasonable for this fix.

@indurireddy-TF

Copy link
Copy Markdown
Contributor

@VISHNU0906 Thanks for addressing this issue. The changes look good, and the added regression tests cover the relevant grounding metadata scenarios, including grounding-only messages and buffered turn completion.Keeping turn-level grounding chunk merging as a separate consideration helps keep this PR focused on the reported issue.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Live: grounding metadata from the Live API is dropped by LiveConnection.Recv

3 participants