Skip to content

fix: preserve Gemini tool response function names - #10174

Open
Blueteemo wants to merge 2 commits into
AstrBotDevs:masterfrom
Blueteemo:patch-1
Open

Blueteemo wants to merge 2 commits into
AstrBotDevs:masterfrom
Blueteemo:patch-1

Conversation

@Blueteemo

@Blueteemo Blueteemo commented Sep 21, 2026

Copy link
Copy Markdown
Contributor

Summary / 摘要

  • Resolve opaque Gemini tool_call_id values back to their original function names when rebuilding conversation history.

  • Preserve explicit name fields and the existing legacy fallback behavior.

  • Add regression tests for opaque IDs and both fallback paths.

  • 在重建 Gemini 对话历史时,将不透明的 tool_call_id 正确映射回原始函数名。

  • 保留显式 name 字段及现有的旧格式回退行为。

  • 为不透明 ID 和两条回退路径补充回归测试。

Problem / 问题

Gemini requires functionResponse.name to match the preceding functionCall.name. Existing history often stores only an opaque ID such as call_xxx, causing rebuilt requests to fail with HTTP 400.

Gemini 要求 functionResponse.name 与前面的 functionCall.name 一致。现有历史记录通常只保存 call_xxx 形式的不透明 ID,导致重建后的请求因名称不匹配而返回 HTTP 400。

Testing / 测试

  • uv run ruff check astrbot/core/provider/sources/gemini_source.py tests/test_gemini_source.py
  • uv run ruff format --check astrbot/core/provider/sources/gemini_source.py tests/test_gemini_source.py
  • uv run pytest -q tests/test_gemini_source.py — 15 passed

Fixes #9876

Summary by Sourcery

Preserve Gemini function names when rebuilding tool responses so reconstructed conversations remain valid.

Bug Fixes:

  • Preserve the original Gemini function name when reconstructing tool responses from opaque tool call IDs.
  • Retain explicit tool response names and the legacy tool-call-ID fallback behavior.

Tests:

  • Add regression coverage for opaque tool-call ID mapping and both tool-name fallback paths.

Resolve opaque tool call IDs back to their original function names when rebuilding Gemini history.

Refs AstrBotDevs#9876

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've reviewed your changes and they look great!

Sourcery assessment

Approved.


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

Add regression coverage for opaque tool call IDs and preserve explicit or legacy function-name fallbacks.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug:Gemini Provider 重建工具消息时以 tool_call_id 充当 functionResponse.name,导致函数调用历史配对失败(400)

1 participant