Tool results posted together for calls from two turns are duplicated in later LLM requests
維護者通常 3 天內回覆
還沒有人認領這個 Issue。
評估
- 難度
- 3/5
- 預估耗時
- 1-2 天
- 新手友好度
- 42/100
- Issue 類型
- 缺陷
- 描述清晰度
- 描述清楚
- 活躍度
- 活躍
- 技術堆疊
- python
研究方向
Start with rearrange_events_for_async_function_responses_in_history in src/google/adk/flows/llm_flows/tools/_rearranger.py and compare it with rearrange_events_for_latest_function_response, which already splits a shared response event per call. Run the reproduction in the issue against _get_contents in src/google/adk/flows/llm_flows/context/_contents.py. Done means each function response appears once, directly after its own call, with the existing test_rearranger.py and test_contents.py suites still passing.
由索引模型根據 Issue 內容生成。
描述
Summary
A client can send the results of long-running tools that were called in different model turns in one user message (for example, posting back two pending tool results together). After that message, every LLM request repeats the whole response event after each call it answers. So the model sees each tool result twice, and sees one tool's result before that tool was called.
That wastes tokens, can confuse the model about which result belongs to which call, and can be rejected by providers that check strict call/response pairing. On the turn where this event is still the last one in history, ADK already splits it per call correctly. Once later events follow it, the history rearrangement re-appends the unsplit event after each call it answers.
Reproduction
Run on current main (3e322e9a):
from google.adk.events.event import Event
from google.adk.flows.llm_flows.context._contents import _get_contents
from google.genai import types
def call(cid, name, inv):
return Event(author="agent", invocation_id=inv, long_running_tool_ids={cid},
content=types.ModelContent([types.Part(function_call=types.FunctionCall(id=cid, name=name, args={}))]))
def text(author, s, inv):
c = types.UserContent(s) if author == "user" else types.ModelContent(s)
return Event(author=author, invocation_id=inv, content=c)
fr = Event(author="user", invocation_id="inv3", content=types.UserContent([
types.Part(function_response=types.FunctionResponse(id="c_a", name="tool_a", response={"a": 1})),
types.Part(function_response=types.FunctionResponse(id="c_b", name="tool_b", response={"b": 2})),
]))
events = [
text("user", "start A", "inv1"), call("c_a", "tool_a", "inv1"),
text("user", "also B", "inv2"), call("c_b", "tool_b", "inv2"),
fr, text("agent", "both done", "inv3"),
text("user", "thanks, next question", "inv4"), # later turn: fr is now in history
]
for c in _get_contents(None, events, "agent", preserve_function_call_ids=True):
print(c.role, [f"call:{p.function_call.id}" if p.function_call else
f"resp:{p.function_response.id}" if p.function_response else p.text for p in c.parts])
Actual
user ['start A']
model ['call:c_a']
user ['resp:c_a', 'resp:c_b'] <- c_b's result before c_b is called
user ['also B']
model ['call:c_b']
user ['resp:c_a', 'resp:c_b'] <- both results again
model ['both done']
user ['thanks, next question']
Expected
model ['call:c_a']
user ['resp:c_a']
user ['also B']
model ['call:c_b']
user ['resp:c_b']
Each response appears once, right after its own call.
Cause
rearrange_events_for_async_function_responses_in_history in src/google/adk/flows/llm_flows/tools/_rearranger.py maps each call to the latest response event that answers it, then appends that whole event after every call event it answers. It never narrows a shared event to the responses each call owns. rearrange_events_for_latest_function_response (the trailing-event case) already does this split, which is why the bug only appears from the next turn on.
Proposed fix
When a response event answers calls from more than one call event, give each call event only the function responses it owns, using the same nearest-preceding-call rule the function already uses. Other parts (for example a user note sent with the results) stay with the latest call that actually uses this event, so they are not lost when a later event updates one of the results. An event that answers only one call event is returned unchanged.
Regression tests: two in tests/unittests/flows/llm_flows/tools/test_rearranger.py and one end-to-end _get_contents test in tests/unittests/flows/llm_flows/context/test_contents.py. All of tests/unittests/flows/llm_flows passes (1232).
I used an AI coding assistant (Claude) to find and analyse this; I reproduced it and checked the fix myself.
I've tested a fix with a regression test: https://github.com/chaitanya0305/adk-python/compare/main...chaitanya0305:adk-python:fix/history-shared-response-split. If this is accepted, I'll open the PR straight away.
- 主要語言
- Python
- 星號
- 22.3k
- 分支
- 4.4k
- 平均合併
- 1 天 2 小時
- 30 天內合併 PR
- 6
環境準備
- 沒有 Dockerfile 或 Docker Compose 檔案
- 有 Pull Request 範本
- 閱讀貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
google/adk-python 的其他 Issue
-
難度 2/5 1-3 小時 新手友好度 72/100
google/adk-python#8360 ·
維護者通常 3 天內回覆
-
難度 2/5 1-3 小時 新手友好度 82/100
google/adk-python#8359 ·
維護者通常 3 天內回覆
-
Can pin to litellm version be changed?可能已有人在做 @llalitkumarrr 於 10 天前認領。 未關閉models
難度 1/5 1 小時以內 新手友好度 65/100
google/adk-python#8129 · 2 則留言 · 已指派 1 人 ·
維護者通常 3 天內回覆
-
OpenAPI tools ignore operation- and path-level server overrides可能已有人在做 @sanketpatil06 於 14 天前認領。 未關閉tools
難度 2/5 1-3 小時 新手友好度 75/100
google/adk-python#8064 · 4 則留言 · 已指派 1 人 ·
維護者通常 3 天內回覆
-
Two docstrings in openapi_tool document parameters the signatures do not accept可能已有人在做 @surajksharma07 於 17 天前認領。 未關閉
難度 1/5 1 小時以內 新手友好度 88/100
google/adk-python#8024 · 1 則留言 · 已指派 1 人 ·
維護者通常 3 天內回覆
查看 google/adk-python 的全部 Issue
相似的 Issue
-
難度 2/5 1-3 小時 新手友好度 72/100
vllm-project/vllm#70030 ·
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 78/100
TigreGotico/tugaphone#408 ·
維護者通常 1 天內回覆
-
needs-triage
難度 2/5 1-3 小時 新手友好度 74/100
gke-labs/kube-agents#7308 ·
維護者通常 1 天內回覆
-
t: bug
難度 2/5 1-3 小時 新手友好度 78/100
維護者通常 3 天內回覆
-
chore
難度 1/5 1-3 小時 新手友好度 88/100
lugassawan/swe-workbench#841 ·