fix: forward tools through OpenRouter engine#511
Open
tjelite1986 wants to merge 1 commit into
Open
Conversation
The OpenRouter chat completion path built the request from only `model`, `messages`, `max_tokens`, and `temperature`. `tools` and `tool_choice` passed via `kwargs` were silently dropped, so function definitions never reached the model. Symptom on a managed deep_research agent: the model answered every query from its own prior knowledge and never invoked `knowledge_search`, `knowledge_sql`, etc. The same path also discarded `choice.message.tool_calls` from the response — when a model did return a tool call (verified directly against OpenRouter with `google/gemma-4-31b-it:free` and `nvidia/nemotron-3-ultra-550b-a55b:free`), the agent loop never saw it. This patch: - forwards `tools` and `tool_choice` into the OpenAI-compatible request in both `_generate_openrouter` (sync) and `_stream_openrouter` (async stream), - extracts `tool_calls` from the response in `_generate_openrouter` in the same shape used by the OpenAI / Anthropic paths. Verified end-to-end against a `deep_research` managed agent using an OpenRouter preset with Gemma 4 31B + Nemotron 3 Ultra fallback: before, the agent stated "I don't have access to your vault"; after, it calls `knowledge_search`, cites results, and produces a structured answer.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The OpenRouter chat completion path silently dropped
toolsandtool_choicewhen building the request, and discarded
tool_callsfrom the response.A managed
deep_researchagent configured with an OpenRouter model(e.g.
openrouter/google/gemma-4-31b-it:free) therefore never invokedits configured tools (
knowledge_search,knowledge_sql,scan_chunks,think)and answered from prior knowledge only.
Equivalent code paths for Anthropic and Google engines convert and forward tools
correctly — only the OpenRouter path was missing the forwarding.
Repro
deep_researchagent withmodel = openrouter/google/gemma-4-31b-it:freeand tools enabled (default for that agent type).
The same prompt sent directly to OpenRouter with
toolsin the request bodyreturns a proper
tool_callsarray — so the underlying capability is there;the engine just wasn't sending or reading it.
Change
In
src/openjarvis/engine/cloud.py:_generate_openrouternow forwardstoolsandtool_choicefrom kwargsinto
create_kwargs, and extractschoice.message.tool_callsfrom theresponse in the same OpenAI-compatible shape used elsewhere.
_stream_openrouterforwardstoolsandtool_choiceas well (thestreaming path keeps its existing text-only yield surface; the change just
unblocks future streaming tool-call handlers).
Verification
Verified end-to-end against a managed
deep_researchagent using anOpenRouter preset with Gemma 4 31B + Nemotron 3 Ultra fallback.
"Jag har ingen information i mitt vault…"(~2s).knowledge_search, cites[[wiki/questions/Elite shorts18 category move debrief]]etc., and producesa structured answer (~30s).