Skip to content

fix(chat): only leave agent mode when the model really has no tool support#5767

Open
MummIndia wants to merge 1 commit into
odysseus-dev:devfrom
MummIndia:fix-agent-mode-tool-error
Open

fix(chat): only leave agent mode when the model really has no tool support#5767
MummIndia wants to merge 1 commit into
odysseus-dev:devfrom
MummIndia:fix-agent-mode-tool-error

Conversation

@MummIndia

Copy link
Copy Markdown

Summary

Both checks in static/js/chat.js match a bare tool or auto anywhere in the error
text, which catches a great deal that has nothing to do with tool support: a tool
timing out, an MCP server dropping, any message containing "automatic".

At the first site the consequences are not cosmetic. The real error is replaced with
"This model doesn't support agent tools", so the actual cause is lost. The UI leaves
agent mode. And the choice is written to localStorage, so every later message in
that conversation also runs without tools, with nothing on screen explaining why. It
presents as "agent mode works in a new chat but not in this one", which sends you
looking at the model, the session or the endpoint rather than at a substring match in
the error path.

The second site is milder — it appends a hint rather than switching — but appending
"this model may not support tools" to an unrelated failure still points the user at
the wrong fix.

This matches the provider's actual wording instead. Ollama returns <model> does not support tools; the pattern also covers "doesn't support tools" and "tools are not
supported". The original error text is kept in both branches so a genuine failure
stays diagnosable.

Target branch

  • This PR targets dev, not main.

Linked Issue

Fixes #5766

Type of Change

  • Bug fix (non-breaking — fixes a confirmed issue)

Checklist

  • I searched open issues and open PRs — this is not a duplicate.
  • This PR targets dev
  • My changes are limited to the scope described above — no unrelated refactors or whitespace changes mixed in.
  • I actually ran the app (docker compose up) and verified the change works end-to-end.

How to Test

  1. In agent mode with a model that does support tools, trigger a failure whose message
    contains tool or auto — killing an MCP server mid-turn, or letting a tool time
    out, both work.

  2. Before the change — the message shown is "This model doesn't support agent
    tools", the mode toggle flips to Chat, and localStorage keeps it there. Sending a
    second message in the same conversation runs without tools.

  3. After the change — the real error text is displayed and agent mode stays on.

  4. Regression check on the strings that used to misfire — none of these demote any
    more, while the three real phrasings still do:

    const re = /does\s*n[o']?t\s+support\s+tools?|tools?\s+(?:are\s+)?not\s+supported/i;
    
    re.test('registry.ollama.ai/library/llama3.2 does not support tools'); // true
    re.test("this model doesn't support tools");                           // true
    re.test('Tools are not supported by this endpoint');                   // true
    
    re.test('Error 500: tool execution timed out');        // false
    re.test('MCP server not connected: builtin_browser');  // false
    re.test('automatic retry failed');                     // false
    re.test('tool_choice auto is invalid');                // false
    re.test('Error 502: peer closed connection');          // false

Visual / UI changes — REQUIRED if you touched anything that renders

This touches static/js/chat.js, so I want to be explicit rather than tick "none".

What changes on screen: an error message string, and the state of the mode
toggle
in the cases where it previously flipped by mistake. No styling, layout,
spacing, colour, font, icon, HTML structure or CSS is touched — the diff is a regular
expression and the two conditions that use it.

I have not attached a screenshot because producing one means provoking an artificial
backend failure, and the resulting image would show one arbitrary error string in a
message bubble — it would not illustrate the defect, which is which errors are
matched. The regression table above is a more faithful account of the change.

Happy to attach a before/after capture if you would rather have one — say the word and
I will provoke the failure and record it.

…pport

Both checks match a bare "tool" or "auto" anywhere in the error text,
which catches a lot that has nothing to do with tool support: a tool
timing out, an MCP server dropping, any message containing "automatic".

At the first site the consequences are not cosmetic. The real error is
replaced with "This model doesn't support agent tools", so the actual
cause is lost. The UI leaves agent mode. And the choice is written to
localStorage, so every later message in that conversation also runs
without tools, with nothing on screen explaining why.

It presents as "agent mode works in a new chat but not in this one",
which sends you looking at the model, the session, or the endpoint
rather than at a substring match in the error path. Diagnosing it took
a while precisely because the message you are shown is the one thing
that is not true.

The second site is milder -- it appends a hint rather than switching --
but appending "this model may not support tools" to an unrelated
failure still points the user at the wrong fix.

Match the provider's actual wording instead. Ollama returns
"<model> does not support tools"; the pattern also covers "doesn't
support tools" and "tools are not supported". The original error text
is kept in both cases so a genuine failure stays diagnosable.

Checked against the strings that used to misfire -- "tool execution
timed out", "MCP server not connected", "automatic retry failed",
"tool_choice auto is invalid", "peer closed connection" -- none of
which now demote, while the three real phrasings still do.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@github-actions github-actions Bot added the ready for review Description complete — ready for maintainer review label Jul 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready for review Description complete — ready for maintainer review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Any error containing 'tool' or 'auto' silently disables agent mode and persists it

1 participant