fix(agent): preserve tool metadata after skills-like requery#9220
fix(agent): preserve tool metadata after skills-like requery#9220Last-emo-boy wants to merge 2 commits into
Conversation
There was a problem hiding this comment.
Code Review
This pull request ensures that tools_call_extra_content is preserved during skills-like re-queries in tool_loop_agent_runner.py and updates the corresponding tests to verify this behavior. The review feedback points out that the token usage from the re-query response (requery_resp) is currently not accumulated, which leads to inaccurate token usage reporting, and suggests adding code to track it.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
| llm_resp.tools_call_extra_content = ( | ||
| requery_resp.tools_call_extra_content | ||
| ) |
There was a problem hiding this comment.
The token usage of the skills-like re-query response (requery_resp) is currently not tracked or accumulated into the agent's total token usage statistics (self.stats.token_usage) or the conversation's token usage (self.req.conversation.token_usage). This leads to inaccurate token usage reporting when the skills-like mode is active.
We should accumulate the token usage from requery_resp when it is available.
llm_resp.tools_call_extra_content = (
requery_resp.tools_call_extra_content
)
if requery_resp.usage:
self.stats.token_usage += requery_resp.usage
if self.req.conversation:
self.req.conversation.token_usage += requery_resp.usage.totalThere was a problem hiding this comment.
Hey - I've left some high level feedback:
- The usage accounting logic for
requery_respandrepair_respin_resolve_tool_execis duplicated; consider extracting a small helper (e.g.,_add_usage(usage)) to centralize theself.stats.token_usageandconversation.token_usageupdates and avoid divergence if the accounting rules change. - You currently update
llm_resp.tools_call_extra_contentinstep()when askills_likere-query happens and also reassignllm_respfromrequery_resp/repair_respinside_resolve_tool_exec; it might be clearer to keep all response-normalization (including tool call and extra content synchronization) in one place to reduce the chance of future inconsistencies between the two paths.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The usage accounting logic for `requery_resp` and `repair_resp` in `_resolve_tool_exec` is duplicated; consider extracting a small helper (e.g., `_add_usage(usage)`) to centralize the `self.stats.token_usage` and `conversation.token_usage` updates and avoid divergence if the accounting rules change.
- You currently update `llm_resp.tools_call_extra_content` in `step()` when a `skills_like` re-query happens and also reassign `llm_resp` from `requery_resp`/`repair_resp` inside `_resolve_tool_exec`; it might be clearer to keep all response-normalization (including tool call and extra content synchronization) in one place to reduce the chance of future inconsistencies between the two paths.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
Fixes #9217.
Gemini returns a thought signature with the function call produced by a
skills_likeparameter re-query. The runner replaced the selected tool call'sname, arguments, and ID with the re-query result, but kept the original
provider metadata map. When the call ID changed, the re-query signature was
therefore absent from the assistant history, and Gemini rejected the next turn.
This change follows Google's
thought-signature guidance,
which requires model-generated function-call signatures to be returned
unchanged in subsequent turns.
Modifications / 改动点
Keep
tools_call_extra_contentsynchronized with the name, arguments, and IDreturned by a
skills_likere-query.Preserve the real provider metadata associated with the final function call
instead of retaining metadata from the initial tool-selection response.
Add regression coverage using distinct initial and re-query call IDs and
signatures, verifying that the recorded assistant history contains the
re-query signature.
Leave non-
skills_likeexecution, Gemini serialization, shared messagemodels, configuration, and dependencies unchanged.
This is NOT a breaking change. / 这不是一个破坏性变更。
Screenshots or Test Results / 运行截图或测试结果
Checklist / 检查清单
😊 If there are new features added in the PR, I have discussed it with the authors through issues/emails, etc.
/ 如果 PR 中有新加入的功能,已经通过 Issue / 邮件等方式和作者讨论过。
👀 My changes have been well-tested, and "Verification Steps" and "Screenshots" have been provided above.
/ 我的更改经过了良好的测试,并已在上方提供了“验证步骤”和“运行截图”。
🤓 I have ensured that no new dependencies are introduced, OR if new dependencies are introduced, they have been added to the appropriate locations in
requirements.txtandpyproject.toml./ 我确保没有引入新依赖库,或者引入新依赖库的同时将其添加到
requirements.txt和pyproject.toml文件相应位置。😮 My changes do not introduce malicious code.
/ 我的更改没有引入恶意代码。
Summary by Sourcery
Ensure skills-like tool re-queries correctly preserve provider metadata and token usage accounting for Gemini tool calls.
Bug Fixes:
Enhancements:
Tests: