Skip to content

fix: forward tools through OpenRouter engine#511

Open
tjelite1986 wants to merge 1 commit into
open-jarvis:mainfrom
tjelite1986:fix-openrouter-tools-forwarding
Open

fix: forward tools through OpenRouter engine#511
tjelite1986 wants to merge 1 commit into
open-jarvis:mainfrom
tjelite1986:fix-openrouter-tools-forwarding

Conversation

@tjelite1986

Copy link
Copy Markdown

Summary

The OpenRouter chat completion path silently dropped tools and tool_choice
when building the request, and discarded tool_calls from the response.
A managed deep_research agent configured with an OpenRouter model
(e.g. openrouter/google/gemma-4-31b-it:free) therefore never invoked
its 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

  1. Create a managed deep_research agent with model = openrouter/google/gemma-4-31b-it:free
    and tools enabled (default for that agent type).
  2. Ask the agent any vault-related question.
  3. Observe response latency ~2s (no tool call) and a generic refusal from the model.

The same prompt sent directly to OpenRouter with tools in the request body
returns a proper tool_calls array — so the underlying capability is there;
the engine just wasn't sending or reading it.

Change

In src/openjarvis/engine/cloud.py:

  • _generate_openrouter now forwards tools and tool_choice from kwargs
    into create_kwargs, and extracts choice.message.tool_calls from the
    response in the same OpenAI-compatible shape used elsewhere.
  • _stream_openrouter forwards tools and tool_choice as well (the
    streaming 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_research agent using an
OpenRouter preset with Gemma 4 31B + Nemotron 3 Ultra fallback.

  • Before: "Jag har ingen information i mitt vault…" (~2s).
  • After: agent calls knowledge_search, cites
    [[wiki/questions/Elite shorts18 category move debrief]] etc., and produces
    a structured answer (~30s).

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

1 participant