feat(openrouter): pass OpenRouter server tools through bind_tools#38161
feat(openrouter): pass OpenRouter server tools through bind_tools#38161Mason Daugherty (mdrxy) wants to merge 2 commits into
bind_tools#38161Conversation
OpenRouter server tools (e.g. openrouter:fusion) are identified by a type like openrouter:* and run entirely server-side. They are not OpenAI-style function tools, so convert_to_openai_tool mangled them. bind_tools now forwards such dicts to the API unchanged so callers can use Fusion and other server tools alongside their own function tools. Co-authored-by: open-swe[bot] <open-swe@users.noreply.github.com>
| if _is_openrouter_server_tool(tool) | ||
| else convert_to_openai_tool(tool, strict=strict) |
There was a problem hiding this comment.
🟠 Fusion tool fails SDK validation
This branch forwards {"type": "openrouter:fusion"} unchanged, but the installed openrouter SDK still validates tools against a discriminated union that only includes function, openrouter:datetime, openrouter:web_search, and the web-search shorthands. As a result, the documented bind_tools([{"type": "openrouter:fusion"}]).invoke(...) path raises a local pydantic_core.ValidationError before any request is sent (Input tag 'openrouter:fusion' ... does not match any of the expected tags). The new unit tests only inspect bound.kwargs, so they miss that the advertised fusion tool remains unusable at runtime. This needs either an SDK path/version that accepts fusion or a request path that bypasses the SDK's current tool validation.
(Refers to lines 862-863)
Your feedback helps Open SWE learn. React with 👍 or 👎 to tell us if this review comment was useful.
Today,
ChatOpenRouter.bind_toolsruns every tool throughconvert_to_openai_tool, which only passes a fixed allowlist of OpenAI tool types through untouched. OpenRouter's server tools — identified by atypelikeopenrouter:fusionoropenrouter:web_search— aren't on that list, so they get routed throughconvert_to_openai_functionand mangled/rejected. A user who wants theopenrouter:fusionserver tool (e.g. to combine multi-model deliberation with their own function tools) currently has to drop down to the raw.bind(tools=...)escape hatch.This teaches
bind_toolsto recognize OpenRouter server-tool dicts (any dict whosetypestarts withopenrouter:) and forward them to the API unchanged, so they can be mixed with regular function tools.tool_choice=Truecan't target a server tool, so that combination now raises a clear error pointing users totool_choice="required".A brief note: this contribution was made with the help of an AI agent.
Release Note
ChatOpenRouter.bind_toolsnow supports OpenRouter server tools (e.g.{"type": "openrouter:fusion"}), forwarding them to the API unchanged.Made by Open SWE