fix: preserve empty-string text parts in A2A converter#5343
Open
voidborne-d wants to merge 1 commit intogoogle:mainfrom
Open
fix: preserve empty-string text parts in A2A converter#5343voidborne-d wants to merge 1 commit intogoogle:mainfrom
voidborne-d wants to merge 1 commit intogoogle:mainfrom
Conversation
Part(text='') is valid — it is produced by code_execution_utils.py when code execution returns None, and by interactions_utils.py when the Interactions API returns None text. Gemini 2.5 Flash thinking mode also emits empty text parts. The truthiness check `if part.text:` treats '' as falsy, causing the converter to skip the part entirely. When all parts in a response are empty the A2A message ends up with zero parts and the client sees "broken thinking" with no content. Change the check to `if part.text is not None:` so that empty strings are correctly wrapped as TextPart while None is still skipped. Add a regression test for the empty-string case. Fixes google#5341
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #5341 —
convert_genai_part_to_a2a_part()dropsPart(text='')because the truthiness checkif part.text:treats empty strings as falsy.Root Cause
Part(text='')is valid and is produced in at least two places in the ADK:code_executors/code_execution_utils.py— when code execution completes withNoneoutputmodels/interactions_utils.py— when the Interactions API returnsNonetext contentGemini 2.5 Flash (thinking mode) also emits empty text parts.
When the converter drops all parts the A2A message ends up with zero parts and the client sees "broken thinking" with no content.
Fix
Change line 182 from
if part.text:toif part.text is not None:so that empty strings are correctly wrapped asTextPartwhileNoneis still skipped.Test
Added
test_convert_empty_text_part— verifies thatPart(text='')produces a validTextPart(text='')instead of returningNone.