Skip to content

Commit 730ce3f

Browse files
committed
fix: Fall back to code_execution_result.output when merged_text is empty
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 #5481
1 parent 2343973 commit 730ce3f

1 file changed

Lines changed: 10 additions & 0 deletions

File tree

src/google/adk/tools/agent_tool.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,16 @@ async def run_async(
272272
merged_text = '\n'.join(
273273
p.text for p in last_content.parts if p.text and not p.thought
274274
)
275+
276+
# Fall back to code_execution_result output if merged_text is empty
277+
# This handles inner code-executor agents that return only
278+
# executable_code and code_execution_result (no text part)
279+
if not merged_text or not merged_text.strip():
280+
for p in last_content.parts:
281+
if p.code_execution_result and p.code_execution_result.output:
282+
merged_text = p.code_execution_result.output
283+
break
284+
275285
output_schema = _get_output_schema(self.agent)
276286
if output_schema:
277287
tool_result = validate_schema(output_schema, merged_text)

0 commit comments

Comments
 (0)