Skip to content

feat(openrouter): pass OpenRouter server tools through bind_tools#38161

Open
Mason Daugherty (mdrxy) wants to merge 2 commits into
masterfrom
mdrxy/openrouter/fusion-server-tool
Open

feat(openrouter): pass OpenRouter server tools through bind_tools#38161
Mason Daugherty (mdrxy) wants to merge 2 commits into
masterfrom
mdrxy/openrouter/fusion-server-tool

Conversation

@mdrxy

Copy link
Copy Markdown
Member

Today, ChatOpenRouter.bind_tools runs every tool through convert_to_openai_tool, which only passes a fixed allowlist of OpenAI tool types through untouched. OpenRouter's server tools — identified by a type like openrouter:fusion or openrouter:web_search — aren't on that list, so they get routed through convert_to_openai_function and mangled/rejected. A user who wants the openrouter:fusion server 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_tools to recognize OpenRouter server-tool dicts (any dict whose type starts with openrouter:) and forward them to the API unchanged, so they can be mixed with regular function tools. tool_choice=True can't target a server tool, so that combination now raises a clear error pointing users to tool_choice="required".

A brief note: this contribution was made with the help of an AI agent.

Release Note

ChatOpenRouter.bind_tools now supports OpenRouter server tools (e.g. {"type": "openrouter:fusion"}), forwarding them to the API unchanged.

Made by Open SWE

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>
@github-actions github-actions Bot added feature For PRs that implement a new feature; NOT A FEATURE REQUEST integration PR made that is related to a provider partner package integration internal openrouter `langchain-openrouter` package issues & PRs size: S 50-199 LOC labels Jun 15, 2026
@mdrxy Mason Daugherty (mdrxy) marked this pull request as ready for review June 15, 2026 20:52

@open-swe open-swe 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.

Open SWE Review found 1 potential issue.

Open in WebView Open SWE trace

Comment on lines +862 to +863
if _is_openrouter_server_tool(tool)
else convert_to_openai_tool(tool, strict=strict)

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.

🟠 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature For PRs that implement a new feature; NOT A FEATURE REQUEST integration PR made that is related to a provider partner package integration internal openrouter `langchain-openrouter` package issues & PRs size: S 50-199 LOC

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant