Skip to content

fix(tools): add fallback to code_execution_result.output in AgentTool.run_async when text parts are empty#5496

Open
ilyesJammouci wants to merge 3 commits intogoogle:mainfrom
ilyesJammouci:fix/agenttool-missing-code-execution-output-5481
Open

fix(tools): add fallback to code_execution_result.output in AgentTool.run_async when text parts are empty#5496
ilyesJammouci wants to merge 3 commits intogoogle:mainfrom
ilyesJammouci:fix/agenttool-missing-code-execution-output-5481

Conversation

@ilyesJammouci
Copy link
Copy Markdown

@ilyesJammouci ilyesJammouci commented Apr 26, 2026

Fixes #5481

Summary

AgentTool currently extracts tool output from text parts only.
When an inner agent finishes with code_execution_result parts and no text part, AgentTool returns an empty result string to the parent agent.

This causes silent output loss and prevents parent-level recovery logic.


Changes

Updated agent_tool.py in AgentTool.run_async:

  • Kept existing text merge behavior as the primary path
  • Added a fallback path when merged text is empty:
    • Collect output from code_execution_result parts
    • Join collected outputs into the final merged text
  • Preserve empty string behavior when neither text nor code execution output exists

Before

  • Extraction logic only used text parts

After

  • Text-first extraction with fallback to code_execution_result.output

Big thanks to @Number531 for the clear bug report and for proposing the fix


Motivation

In multi-agent workflows using AgentTool with code execution, inner model responses may contain:

  • executable_code
  • code_execution_result without a textual summary.

Returning an empty result in this case drops valid computation output and can derail long-running optimization or orchestration flows.

This change makes AgentTool robust to that response shape and avoids silent failures.


Test Plan

Manual E2E verification

Reproduced the issue with the local runner flow:

python -m google.adk.agent.my_agent.run_repro --offline --runs 30

Before the fix

  • Parent tool result was empty when the inner response contained only code_execution_result parts

After the fix

  • Parent tool result contains code_execution_result.output for the same response shape
  • The empty-result failure mode is no longer observed in this path

Unit tests

  • Added regression test in test_agent_tool.py:
    • test_run_async_uses_code_execution_result_output_when_no_text

@adk-bot adk-bot added the tools [Component] This issue is related to tools label Apr 26, 2026
@adk-bot
Copy link
Copy Markdown
Collaborator

adk-bot commented Apr 26, 2026

Response from ADK Triaging Agent

Hello @ilyesJammouci, thank you for creating this PR!

To help reviewers verify the fix, could you please provide a manual end-to-end (E2E) test as described in our contribution guidelines? This could be a screenshot from adk web or logs from the runner tool demonstrating that the issue is resolved.

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

@rohityan rohityan self-assigned this Apr 27, 2026
@rohityan rohityan added the request clarification [Status] The maintainer need clarification or more information from the author label Apr 27, 2026
@rohityan
Copy link
Copy Markdown
Collaborator

Hi @ilyesJammouci , Thank you for your contribution! We appreciate you taking the time to submit this pull request. Can you please fix the failing test before we can proceed with the review.

@ilyesJammouci
Copy link
Copy Markdown
Author

Hi @rohityan, thank you for the feedback! I've fixed the failing test. Please let me know if anything else needs to be addressed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

request clarification [Status] The maintainer need clarification or more information from the author tools [Component] This issue is related to tools

Projects

None yet

Development

Successfully merging this pull request may close these issues.

AgentTool.run_async extracts only p.text, loses code_execution_result.output from inner code-executor agents

3 participants