Skip to content

mistral:7b (Ollama path) tool-calling reliability degrades sharply past ~6 concurrently-offered tools #1634

Closed

Description

@malibio

Overview

During investigation of #1632 (ollama_integration test suite failures), found that mistral:7b via the Ollama provider path reliably fails to emit structured tool_calls once roughly 6 or more tools are offered in the same turn. Instead of using Ollama's structured tool-calling field, the model narrates the intended call as prose or JSON-in-markdown (e.g. "To get the details of a specific node, you can use the get_node function...").

This is not test flakiness — it reproduces deterministically (verified via raw Ollama /api/chat calls that bypass all NodeSpace code, 3-5 repeated runs each, temperature 0.0-0.1).

Relationship to existing decisions

This does not reverse or contradict ADR-038 (skill-mediated tool routing) or ADR-046 (Ministral 8B locked as the native path model). Both ADRs' evidence and agent tool-call matrix (#1370) evaluated only the native llama.cpp/GGUF path (Ministral 8B, Gemma 4 12B, Ornith 1.0 9B). Mistral 7B via Ollama — a separate, real, user-selectable provider path per #1370's own model-picker design (Ollama is auto-detected and its models, including "Mistral 7B", are shown as selectable) — has not been evaluated against either ADR's findings. This issue adds that missing evidence for the Ollama path specifically.

It's still relevant to ADR-038's Stage-2/routing design: GraphToolExecutor::available_tools() (packages/agent/src/local_agent/tools.rs) sends the full unscoped tool set (14 tools) on every turn regardless of provider path — the routing pipeline described in ADR-038 (retrieval-bounded top-K candidates, not full-registry enumeration) is not wired up yet for the Ollama path either (Implementation Notes step 4, "depends on 1" — the engine upgrade — is scoped to the native path only per ADR-046's Related issues). Real mistral:7b-via-Ollama users can hit this narration failure on ordinary requests today, not just in tests.

Evidence

Direct Ollama API testing (http://127.0.0.1:11434/api/chat), varying tool count with the same message ("Show me the full content of node task-abc123", expects a get_node call):

Tool count Result
2 tool_calls returned correctly
3 tool_calls returned correctly
5 tool_calls returned correctly
7 narrated as prose, no tool_calls
10 narrated as prose, no tool_calls

Holds regardless of system prompt content — tested with no system prompt, the bare EMERGENCY_FALLBACK_PROMPT, and the full production-assembled prompt (PromptAssembler::assemble_static, 7800 chars). None rescue tool-calling at 7-10 tools.

Adding search_skills itself as one of 11 offered tools does not help — the model doesn't even reach for search_skills; it still narrates a direct call to the target tool.

Model comparison at the same 10-tool case via Ollama (identical tools/prompt/message):

Model Params Result
ministral-3:3b 3B Fails — claims it "cannot access" the tool (worse failure mode)
mistral:7b 7B Fails — narrates as prose
ornith:9b 9B Succeeds reliably (3/3)
mistral-nemo:12b 12B Succeeds reliably (3/3)

Tool-calling reliability at this tool count scales with model size within the tested range, but neither larger Ollama-hosted model is a clearly better default:

  • ornith:9b has the same multi-step ReAct-loop KV-cache slowdown documented for the native path in Re-enable Ornith 1.0 9B in Settings UI once multi-step tool-calling slowdown is addressed #1477 (recurrent/SSM layers can't reuse KV-cache across iterations — a confirmed upstream ggml-org/llama.cpp limitation, not path-specific).
  • mistral-nemo:12b needs ~12GB and CPU-spills (9%/91% CPU/GPU split) at num_ctx=32768 on a 16GB machine (this project's documented minimum target per the A/B test Gemma 4 12B (Q4_K_M) vs E4B for the local ai-chat agent #1329 A/B trial) — GPU OOM risk under concurrent load. Independently reproduced during this investigation: ggml_metal_synchronize: error... Insufficient Memory (kIOGPUCommandBufferCallbackErrorOutOfMemory) when Ollama allocated a 32768-token KV cache for mistral:7b under memory pressure from concurrent processes on the same machine.

Problem Statement

For the Ollama path, there is currently no mechanism to reduce the tool count the model sees per turn, regardless of which Ollama model the user picks. GraphToolExecutor::available_tools() sends the full unscoped tool list on every iteration; the search_skills retrieval-based routing ADR-038 specifies is not wired into a real scoping path for any provider yet.

Candidate Fixes (not prescribed — for future investigation)

  • Extend ADR-038's routing pipeline (retrieval + LLM judgment, bounded top-K, scoped follow-up tool list) to the Ollama path, not just whatever native-path work lands first.
  • Reduce the always-offered baseline tool count for the Ollama path specifically, independent of the native-path routing work.
  • Document a recommended/tested Ollama model list in Settings (the Lock llama.cpp path to Ministral 8B only; expose Ollama + OpenAI-compatible as open paths #1370 model-picker UI already lists specific Ollama models as examples) informed by this tool-count ceiling finding, so users aren't silently steered toward a model that will narrate instead of calling tools.

Related

Acceptance Criteria

  • Decide on an approach for the Ollama path (extend ADR-038 routing to Ollama, reduce baseline tool count, document a tested/recommended Ollama model list, or some combination)
  • If tool scoping: wire real skill-matched tool narrowing into agent_loop.rs/GraphToolExecutor for the Ollama provider path
  • Re-enable the #[ignore]d tests in ollama_integration.rs (packages/agent/tests/ollama_integration.rs) once the fix is validated against them, or replace them with tests matching the new architecture
  • Verify fix holds under this project's 16GB memory target (no OOM/CPU-spill regression)

Activity

  1. added
    bug
    on Jul 11, 2026
  2. malibio commented on Jul 17, 2026

    @malibio
    CollaboratorAuthor

    Closing as won't-fix.

    Decision: the external (non-native) agent option is the OpenAI protocol — a single BYO-endpoint path that includes Ollama (mode 2b) and any OpenAI-compatible endpoint (mode 2c) per ADR-034. This path is explicitly use-at-your-own-risk: we do not commit to making any particular external model tool-call reliably, and we will not scope/route the tool set specifically for the Ollama path.

    That removes this issue's premise:

    • Making mistral:7b (or any specific external model) emit structured tool_calls past ~6 tools is not a goal. Model/tool-count ceilings are the user's risk when they BYO an external endpoint.
    • Wiring ADR-038 retrieval-bounded tool routing into the Ollama path specifically is not planned. ADR-038 routing remains scoped to the native path (Gemma 4 E4B, per ADR-046 as superseded).

    Durable evidence preserved here for the record: within Ollama, tool-calling at ~10 offered tools scales with model size — mistral:7b/ministral-3:3b narrate instead of calling; ornith:9b and mistral-nemo:12b succeed but neither is a viable 16GB default (KV-cache slowdown / GPU OOM respectively). Anyone selecting an external model can consult this.

    The #[ignore]d tests in packages/agent/tests/ollama_integration.rs stay ignored — they assert reliability guarantees we are not making for the external path.

    Native local agent remains Gemma 4 E4B (ADR-046).

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    backendbug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions