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 摘要。