Skip to content

gateway: honor allowed-tool subsets from Gemini ANY and Responses allowed_tools - #164

Merged
yetone merged 4 commits into
yetone:mainfrom
charan-rathore:gateway-allowed-tool-subsets
Sep 28, 2026
Merged

yetone merged 4 commits into
yetone:mainfrom
charan-rathore:gateway-allowed-tool-subsets

Conversation

@charan-rathore

Copy link
Copy Markdown
Contributor

Summary

Two request formats can restrict which tools the model may call, but the gateway used to forward every offered tool:

  • Gemini functionCallingConfig with mode: "ANY" and a nonempty allowedFunctionNames list now forwards only the named declarations. One allowed name keeps its forced-choice behavior.
  • OpenAI Responses tool_choice: {"type":"allowed_tools", ...} now reads mode and the allowed function list, forwarding only those functions. It also keeps a namespaced function's mapping when that function is allowed, and does not forward an unlisted web search tool.

String and named-function choices keep their previous behavior. Table-driven offline tests cover restricted and unrestricted choices, a namespaced function, and what Chat, Responses, Anthropic, and Code Assist send upstream.

Instinct assisted with the change and tests. No cloud keys or model calls were used.

Tests

  • go test ./internal/gateway -run '^(TestParseResponsesAllowed|TestParseGeminiAllowed)' -count=1
  • go test ./internal/gateway -count=1
  • git diff --check

@yetone
yetone merged commit 995edc1 into yetone:main Sep 28, 2026
4 checks passed
@yetone

yetone commented Sep 28, 2026

Copy link
Copy Markdown
Owner

@charan-rathore 感谢!我把 35c8d45 拉下来逐行看过,也实际跑过了:构建、vet、gateway 测试都通过,新测试在去掉修复后会失败。另外我通过网关对着假上游端到端跑了 22 个场景:Responses allowed_tools(auto / required,混有 web_search、mcp、custom)转 Chat 和 Anthropic,Gemini ANY 多名和单名(强制选择保留)转 Chat 和 Anthropic,以及同协议透传逐字节不变,结果都正确。已合并。

两个不阻塞的后续建议,欢迎再提 PR:

  1. required / ANY 的名单过滤后一个可调用的工具都不剩时(例如只列了 mcp,或写了不存在的函数名),现在会去掉 tools 和 tool_choice 照常转发,上游只回纯文本,违背了“必须调用工具”;对 Anthropic、历史里又有 tool_use 时可能会被拒。返回一个明确的 400 会更好。
  2. Gemini 的 VALIDATED 模式同样带 allowedFunctionNames,目前还是全部声明加 auto,没有按名单过滤。

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.

2 participants