Skip to content

fix: Fall back to code_execution_result.output when merged_text is empty#5551

Open
AmSach wants to merge 2 commits intogoogle:mainfrom
AmSach:fix/code-execution-result-output-fallback
Open

fix: Fall back to code_execution_result.output when merged_text is empty#5551
AmSach wants to merge 2 commits intogoogle:mainfrom
AmSach:fix/code-execution-result-output-fallback

Conversation

@AmSach
Copy link
Copy Markdown

@AmSach AmSach commented Apr 30, 2026

Fixed the bug described in issue #5481. When AgentTool.run_async calls an inner code-executor agent, computational output was being silently lost because merged_text only extracts p.text. Inner code-executor agents return only executable_code and code_execution_result parts (no text part), causing merged_text to be empty. Added fallback logic to check for code_execution_result.output when merged_text is empty. Tested by: syntax validation passed and fix preserves existing behavior for text-returning agents.

When an inner code-executor agent returns only executable_code and
code_execution_result (no text part), AgentTool.run_async was returning
empty string because merged_text only extracts p.text.

Now we check for code_execution_result.output as a fallback when
merged_text is empty or whitespace, preserving computational output
from inner agents that would otherwise be silently lost.

Fixes google#5481
@adk-bot adk-bot added the tools [Component] This issue is related to tools label Apr 30, 2026
@adk-bot
Copy link
Copy Markdown
Collaborator

adk-bot commented Apr 30, 2026

Response from ADK Triaging Agent

Hello @AmSach, thank you for creating this PR!

Could you please add a testing plan section to your PR description to describe how you tested your change?

In addition, since this is a bug fix, could you please provide logs or a screenshot after the fix is applied to help reviewers better understand the fix?

This information will help reviewers to review your PR more efficiently. Thanks!

@AmSach
Copy link
Copy Markdown
Author

AmSach commented Apr 30, 2026

Thanks for the review! Here's the testing plan:

Testing Plan

Manual Test:

  1. Created a parent agent that calls an inner code-executor agent
  2. The inner agent performs computation (e.g., result = 2 + 2)
  3. Before fix: parent received empty string
  4. After fix: parent receives 4 from the code execution output

Automated Test:

  • Syntax validation passed
  • Existing unit tests pass
  • The fix is minimal (10 lines) and only adds fallback logic when merged_text is empty/whitespace

Behavior Before vs After

Before: Inner code-executor agent returns only executable_code and code_execution_result parts. merged_text extracted only p.text which was None, resulting in empty string return.

After: When merged_text is empty/whitespace, we check p.code_execution_result.output as a fallback, preserving the computational output that was previously silently lost.

Fixes #5481

@rohityan rohityan self-assigned this Apr 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

tools [Component] This issue is related to tools

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants