Skip to content

fix(llminternal): keep responses that carry only grounding metadata - #2310

Merged
jjsasha63 merged 2 commits into
google:mainfrom
jjsasha63:fix/grounding-only-responses
Nov 13, 2026
Merged

jjsasha63 merged 2 commits into
google:mainfrom
jjsasha63:fix/grounding-only-responses

Conversation

@jjsasha63

Copy link
Copy Markdown
Contributor

Please ensure you have read the contribution guide before creating a pull request.

Linked issue

None.

2. Describe the change:

Problem:

Grounding metadata from a search tool can arrive on a model response that has no content. The non-live flow skips any response with no content, no error code and no interruption. A grounding-only response therefore never becomes an event. Callers that render citations or search suggestions see nothing for these respones. adk-python keeps them.

Solution:

  • Flow.runOneStep keeps a response that has no content when it carries GroundingMetadata, matching the skip condition in BaseLlmFlow._postprocess_async.
  • An agent with IncludeContents: none no longer starts its current turn at an event that gives the model nothing to read. Such an event has no content with a role and parts, no transcription and no compaction summary. It never reaches the request,so starting the turn there cut the user input out of it. A grounding-only event saved by the first change would often be that event, for example in a SequentialAgent whose second agent has IncludeContents: none. adk-python's _get_current_turn_contents only starts a turn at an event that passes _should_include_event_in_context, which rejects empty events. The emptiness check is the one the contents processor already used to drop events, moved into isEmptyEvent so both places share it.

Behavior change

  • A run whose model returns a response with only grounding metadata now yields an event with that metadata in Event.GroundingMetadata. The event is saved to the session. Before, the response was dropped.
  • An agent with IncludeContents: none that runs after another agent's event with no content now gets the user input that came before that event. Before, its turn started at the empty event, which left the user input out of the request. Besides grounding-only events, this applies to error responses and responses with no parts, which could already be saved before this change.

Testing Plan

Unit Tests:

  • All unit tests pass locally.

I added these tests:

  • TestRunKeepsGroundingOnlyResponse (internal/llminternal/base_flow_test.go): a grounding-only response yields one event with the metadata, and an empty response still yields no event.
  • TestContentsRequestProcessor_IncludeContentsNone_SkipsEmptyPivot (internal/llminternal/contents_processor_test.go): after a user message and another agent's grounding-only, error or part-less reply, an IncludeContents: none agent's request holds the user message.

No existing test pinned the old behavior.

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

  • TestRunKeepsGroundingOnlyResponse/grounding_metadata_only: the event list is nil where one event with the metadata is expected.
  • TestContentsRequestProcessor_IncludeContentsNone_SkipsEmptyPivot, all three subtests: the request contents are nil where the user message is expected.

Inverting the new guard (resp.GroundingMetadata != nil) fails TestRunKeepsGroundingOnlyResponse/empty_response. In isEmptyEvent, dropping the zero-parts condition fails the part-less subtest; dropping the role, transcription or compaction condition fails existing tests (TestBuildContents_ResponseInSuffixToOtherAgentCallBeforeIt, TestContentsRequestProcessor/TranscriptionAggregation, TestContentsRequestProcessor_Compaction).

go build ./... succeeds. go test -race -count=1 ./internal/llminternal/... ./agent/workflowagents/... passes. go test -count=1 ./... passes in all 119 packages that have tests. golangci-lint run --new-from-rev=origin/main ./... reports 0 issues, and go mod tidy -diff prints nothing.

Parity:

  • I read flows/llm_flows/base_llm_flow.py (_postprocess_async) and flows/llm_flows/context/_contents.py (_get_current_turn_contents, lines 656 to 749, and _contains_empty_content, lines 256 to 285) from adk-python 2.12.0. The non-live skip condition now matches, including not llm_response.grounding_metadata, and so does the rule that an empty event cannot start the current turn.
  • Diverges: _contains_empty_content also counts content whose parts are all thoughts as empty. adk-go keeps its existing rule for that case: another agent's thought-only event is already skipped as a turn start, because foreign conversion discards it.

Manual End-to-End (E2E) Tests:

I did not run an end-to-end test against a live model. adk-go now matches the adk-python unit test tests/unittests/flows/llm_flows/test_base_llm_flow.py::test_postprocess_async_yields_grounding_metadata_only, where a response with only grounding_metadata yields exactly one event carrying it. TestRunKeepsGroundingOnlyResponse checks the same thing through Flow.Run.

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.

Additional context

The live connection drops grounding metadata too. #2265 copies it in LiveConnection.Recv, so this PR leaves the live path alone.

#2309 changes the postprocess call just above the skip condition in runOneStep. The two PRs touch neighboring lines, so whichver lands second needs a small rebase.

The non-live flow dropped a model response with no content, no error
code and no interruption. A response that carried only grounding
metadata matched that check, so its metadata never reachd an event.

adk-python keeps such responses. BaseLlmFlow._postprocess_async skips
an empty response only when it also has no grounding_metadata. The
flow now does the same.

A saved grounding-only event has no content. An agent with
IncludeContents none starts its request at the latest user or
other-agent event, and it accepted such an empty event as that start.
The event never reaches the request, so the user input before it was
cut out. Error responses and responses with no parts could already do
this. adk-python's _get_current_turn_contents only starts a turn at an
event that passes _should_include_event_in_context, which rejects empty
events. The turn-start search now skips them the same way, with the
emptiness check the contents processor already used to drop events.
@jjsasha63 jjsasha63 self-assigned this Nov 13, 2026
@jjsasha63
jjsasha63 requested a review from wojtas000 November 13, 2026 11:23

@wojtas000 wojtas000 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I compared both changes with adk-python's _postprocess_async and _get_current_turn_contents, and followed the new content-less event through Flow.Run, the runner and the code that consumes events. I also ran the two new tests on main. Each one fails without its own source change and passes with it.

None of my notes block, and all of them are optional. The behavior-change section leaves out two cases that users will see after upgrading:

  • In streaming mode, a chunk that carries only grounding metadata now reaches callers as a partial event with no content. The final aggregated event still carries the metadata, as it did before.
  • An agent with IncludeContents: none, run with a user message that has no parts, now gets the previous user turn, its own earlier reply and the "Continue processing" prompt. Before this change the request had no contents. This matches adk-python.

@jjsasha63
jjsasha63 merged commit fc6de07 into google:main Nov 13, 2026
15 checks passed
@jjsasha63
jjsasha63 deleted the fix/grounding-only-responses branch November 13, 2026 13:08
@jjsasha63

Copy link
Copy Markdown
Contributor Author

Both hold, and the description of #2319 lists them. In streaming mode, a grounding-only chunk now reachs callers as a partial event with no content, and the final aggregated event keeps the metadata. An IncludeContents: none agent given a user message with no parts now gets the previous user turn, its own reply and the "Continue processing" prompt. Before, that request had no contents, and the new behavior matches adk-python.

wolo-lab added a commit that referenced this pull request Nov 16, 2026
…2071, #1249, #2070, #2190, #2301, #2310, #2308) (#2350)

* fix(llminternal): keep a streamed text chunk's thought signature on the merged part (#2071)

(cherry picked from commit 28201d6)

* test(llminternal): pin keep-last semantics for streaming usage metadata (#1249)

(cherry picked from commit afe6c86)

* fix(llminternal): keep ModelVersion on the aggregated streaming response (#2070)

(cherry picked from commit 8be9129)

* fix(llminternal): drop nil parts in the streaming aggregator (#2190)

(cherry picked from commit 46ff99b)

* fix(llminternal): skip live responses that carry nothing (#2301)

(cherry picked from commit 8cddb9d)

* fix(llminternal): keep responses that carry only grounding metadata (#2310)

(cherry picked from commit fc6de07)

* fix(llminternal): keep streamed function-call and event ids stable (#2308)

(cherry picked from commit 3188db9)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants