Media in a tool result (FunctionResponse.parts) is dropped when another agent's turn is relayed as context

未关闭
#8,228 1 条评论 0 个 reaction 已指派 1 人 在 GitHub 查看

维护者通常 3 天内回复

@sanketpatil06 已经在做这个了。

开始于 2026年11月18日。

  • #8235 来自 @karthik-0306 —— 未关闭

评估

这个 Issue 还没有评估数据。

描述

tools

🔴 Required Information

Describe the Bug:
When a tool returns media (an image, audio or a document as a types.Part), ADK moves it into FunctionResponse.parts and leaves the JSON response without it (_extract_multimodal_parts in flows/llm_flows/tools/_caller.py). ComputerUseTool screenshots go through the same path.

When another agent later reads that event as context, _present_other_agent_message (flows/llm_flows/context/_fencing.py) renders the tool result as text with str(part.function_response.response) and never looks at function_response.parts. The media is lost. If the tool returned only media, the next agent sees an empty result:

[analyst_agent] `render_chart` tool returned result:
<<<BEGIN_QUOTED_AGENT_CONTENT>>>
{}
<<<END_QUOTED_AGENT_CONTENT>>>

So the receiving agent is told the tool returned nothing. The agent that called the tool still has the media in its own history. The same function already passes media through on its own part type for ordinary inline_data and file_data parts. Tool-result media is the case it misses.

Steps to Reproduce:

  1. pip install google-adk
  2. Run this script. It needs no API key and uses the same functions ADK uses to build the tool result and relay it:
from google.genai import types
from google.adk.events.event import Event
from google.adk.flows.llm_flows.context._fencing import _present_other_agent_message
from google.adk.flows.llm_flows.tools._caller import _build_function_response_content
from google.adk.tools.function_tool import FunctionTool

def render_chart(metric: str):
  """Renders a chart for a metric."""
  return types.Part.from_bytes(data=b"\x89PNG fake chart", mime_type="image/png")

tool = FunctionTool(render_chart)
content = _build_function_response_content(tool, render_chart("sales"), "call-1")
fr = content.parts[0].function_response
print("caller's history:", fr.response, "| media parts:", len(fr.parts or []))

relayed = _present_other_agent_message(Event(author="analyst_agent", content=content))
print("next agent sees:", relayed.content.parts[-1].text)
print("media reaches next agent:", any(p.inline_data or p.file_data for p in relayed.content.parts))

In a real app this happens in any multi-agent setup where one agent calls a media-returning tool and another agent runs later in the same session, for example after transfer_to_agent or in a sequential pipeline.

Expected Behavior:
The relayed context includes the tool's media as its own parts, next to the fenced text of the JSON result, the same way media in ordinary message parts is relayed.

Observed Behavior:

caller's history: {} | media parts: 1
next agent sees: [analyst_agent] `render_chart` tool returned result:
<<<BEGIN_QUOTED_AGENT_CONTENT>>>
{}
<<<END_QUOTED_AGENT_CONTENT>>>
media reaches next agent: False

Environment Details:

  • ADK Library Version: 2.14.1 (main @ c74df83c0)
  • Desktop OS: Windows 11 (the bug isn't OS-specific)
  • Python Version: 3.11

Model Information:

  • Are you using LiteLLM: No
  • Which model is being used: N/A (the context is built before any model call). This affects any model that receives the relayed history.

🟡 Optional Information

Regression:
Not that I know of. Related to #729, which reported image parts being lost at the AgentTool boundary.

Proposed fix:
In the function_response branch of _present_other_agent_message, after the fenced text part, add each entry of function_response.parts as its own part: inline_data becomes a types.Part(inline_data=...) and file_data becomes a types.Part(file_data=...). Run them through _elide_relayed_part_markers, as the existing media branch does, so text/* blobs can't forge quote markers. Add regression tests for a media-only result, a mixed JSON-and-media result, and a text/* blob containing a marker. I'm happy to send a PR.

主要语言
Python
星标
22.3k
派生
4.4k
平均合并
1 天 2 小时
30 天内合并 PR
6

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

google/adk-python 的其他 Issue

查看 google/adk-python 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。