Fix empty agent response in ADK agent when tools are used#62
Merged
Conversation
Capture text from all events with text content, not just events marked as final response. When ADK agent uses tools, the response text may come in events that are not marked as final, causing empty response strings.
When the agent returns an empty response, have the synthetic user ask for clarification instead of passing empty content to the LLM which would confuse it and cause it to return empty, triggering the fallback "Thanks" message that masks the bug.
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
Two-part fix for empty agent responses:
ADK Agent: Capture text from all events with text content, not just events marked as
is_final_response(). When tools are used, the response text may come in earlier events.Synthetic User: When agent returns empty response, ask for clarification ("I didn't receive a response. Could you try again?") instead of passing empty content to the LLM - which would confuse it and trigger the fallback "Thanks" message that masks the bug.
Root Cause
Part 1: ADK Agent
The ADK agent's
send_messagemethod checkedevent.is_final_response()before extracting text. When an ADK agent calls tools, the actual response text may NOT be in the final event.Part 2: Synthetic User
When the synthetic user LLM received an empty agent message, it got confused and returned an empty response. The code then defaulted to "Thanks, that answers my question." - masking the bug.
Test plan
ruff check)mypy)