Repository navigation
fix(llminternal): keep grounding metadata on live responses - #2265
VISHNU0906 wants to merge 1 commit into
Conversation
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
left a comment
There was a problem hiding this comment.
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.
|
@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. |
Linked issue
Problem:
In a live session the grounding metadata the Live API sends never reaches the events.
LiveConnection.Recvcopies the model turn,TurnComplete,Interruptedand the transcriptions fromServerContent, but notServerContent.GroundingMetadata. So an agent withgoogle_search(or another grounding tool) underRunLivegets no search queries, sources or supports, while the same agent underRunner.Rundoes.Solution:
Recvnow copiesServerContent.GroundingMetadataonto the response it builds. A message that carries only grounding becomes its own response, the same as in adk-python'sgemini_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:
New tests in
internal/llminternal/googlellm/live_connection_test.go, going through a realgenaiLive 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-lintv2.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