Cannot use tools with qwen2.5-coder and Ollama #1792

Closed
opened 2026-02-16 17:32:38 -05:00 by yindo · 9 comments
Owner

Originally created by @leonardorame on GitHub (Sep 21, 2025).

Originally assigned to: @rekram1-node on GitHub.

Hi!, I'm using opencode v0.11.1 with the qwen2.5-coder:7b model via Ollama and it looks like cannot execute external operations, for example:

The task is:
create a file test.sh with one instruction: ls -lah

And the response is:

{ "name": "Write", "arguments": { "file_path": "test.sh", content: "..."}}

And the file wasn't created.

My config is this:

cat ~/.config/opencode/opencode.json 
{
  "$schema": "https://opencode.ai/config.json",
  "provider": {
    "ollama": {
      "npm": "@ai-sdk/openai-compatible",
      "name": "Ollama (local)",
      "options": {
        "baseURL": "http://localhost:11434/v1"
      },
      "models": {
        "qwen2.5-coder:7b-instruct": {
          "name": "qwen2.5-coder"
        }
      }
    }
  }
}
Originally created by @leonardorame on GitHub (Sep 21, 2025). Originally assigned to: @rekram1-node on GitHub. Hi!, I'm using opencode v0.11.1 with the qwen2.5-coder:7b model via Ollama and it looks like cannot execute external operations, for example: The task is: `create a file test.sh with one instruction: ls -lah` And the response is: `{ "name": "Write", "arguments": { "file_path": "test.sh", content: "..."}}` And the file wasn't created. My config is this: ``` cat ~/.config/opencode/opencode.json { "$schema": "https://opencode.ai/config.json", "provider": { "ollama": { "npm": "@ai-sdk/openai-compatible", "name": "Ollama (local)", "options": { "baseURL": "http://localhost:11434/v1" }, "models": { "qwen2.5-coder:7b-instruct": { "name": "qwen2.5-coder" } } } } } ```
yindo closed this issue 2026-02-16 17:32:38 -05:00
Author
Owner

@rekram1-node commented on GitHub (Sep 21, 2025):

@leonardorame I think this issue may be relevant for you: https://github.com/sst/opencode/issues/1068

@rekram1-node commented on GitHub (Sep 21, 2025): @leonardorame I think this issue may be relevant for you: https://github.com/sst/opencode/issues/1068
Author
Owner

@rekram1-node commented on GitHub (Sep 21, 2025):

Looks like:

I found out why agentic actions such as using opencode's provided tools didn't work. It's because Ollama has set the context window at 4096 for the models.

In ollama if you set:
Set parameter 'num_ctx' to '16384'

it seems to have fixed it...

I can add this to docs once we resolve your issue

@rekram1-node commented on GitHub (Sep 21, 2025): Looks like: > I found out why agentic actions such as using opencode's provided tools didn't work. It's because Ollama has set the context window at 4096 for the models. In ollama if you set: Set parameter 'num_ctx' to '16384' it seems to have fixed it... I can add this to docs once we resolve your issue
Author
Owner

@leonardorame commented on GitHub (Sep 22, 2025):

Hi @rekram1-node, I don't know where to put that parameter:

I tried in opencode.json, in both ollama -> options, and ollama -> models, with quotes and without it, but it seems to be ignored by ollama:

{
  "$schema": "https://opencode.ai/config.json",
  "provider": {
    "ollama": {
      "npm": "@ai-sdk/openai-compatible",
      "name": "Ollama (local)",
      "options": {
        "baseURL": "http://localhost:11434/v1",
        "num_ctx": 16384
      },
      "models": {
        "qwen2.5-coder:7b-instruct": {
          "name": "qwen2.5-coder",
          "num_ctx": 16384
        }
      }
    }
  }
}

If I run ollama ps I get:

NAME                         ID              SIZE      PROCESSOR          CONTEXT    UNTIL               
qwen2.5-coder:7b-instruct    dae161e27b0e    6.0 GB    10%/90% CPU/GPU    4096       59 minutes from now 
@leonardorame commented on GitHub (Sep 22, 2025): Hi @rekram1-node, I don't know where to put that parameter: I tried in opencode.json, in both ollama -> options, and ollama -> models, with quotes and without it, but it seems to be ignored by ollama: ``` { "$schema": "https://opencode.ai/config.json", "provider": { "ollama": { "npm": "@ai-sdk/openai-compatible", "name": "Ollama (local)", "options": { "baseURL": "http://localhost:11434/v1", "num_ctx": 16384 }, "models": { "qwen2.5-coder:7b-instruct": { "name": "qwen2.5-coder", "num_ctx": 16384 } } } } } ``` If I run `ollama ps` I get: ``` NAME ID SIZE PROCESSOR CONTEXT UNTIL qwen2.5-coder:7b-instruct dae161e27b0e 6.0 GB 10%/90% CPU/GPU 4096 59 minutes from now ```
Author
Owner

@leonardorame commented on GitHub (Sep 22, 2025):

For the record:

Create a file named, for example modelfile (in any directory) with this content:

FROM qwen2.5-coder:7b-instruct
PARAMETER num_ctx   8192
PARAMETER num_batch 384
PARAMETER num_thread 12

Run: ollama create qwen2.5-coder-7b-8k -f modelfile (of course, the modelfile must be reachable by ollama, if not on the same directory use the absolute path i.e. /home/leonardo/modelfiles/modelfile).

gathering model components 
using existing layer sha256:60e05f2100071479f596b964f89f510f057ce397ea22f2833a0cfe029bfc2463 
using existing layer sha256:66b9ea09bd5b7099cbb4fc820f31b575c0366fa439b08245566692c6784e281e 
using existing layer sha256:1e65450c30670713aa47fe23e8b9662bdf4065e81cc8e3cbfaa98924fcc0d320 
using existing layer sha256:832dd9e00a68dd83b3c3fb9f5588dad7dcf337a0db50f7d9483f310cd292e92e 
using existing layer sha256:9b2154434353e33e707107d2c1a7b7c69023aa85d8545ba3e6975a8027e406dc 
writing manifest 
success 

Then, to check, if you run ollama ls you'll get:

NAME                                                  ID              SIZE       MODIFIED      
qwen2.5-coder-7b-8k:latest                            98181fbdef2d    4.7 GB     2 minutes ago 
....

Adapt opencode.json:

{
  "$schema": "https://opencode.ai/config.json",
  "provider": {
    "ollama": {
      "npm": "@ai-sdk/openai-compatible",
      "name": "Ollama (local)",
      "options": {
        "baseURL": "http://localhost:11434/v1"
      },
      "models": {
        "qwen2.5-coder-7b-8k": {
          "name": "qwen2.5-coder"
        }
      }
    }
  }
}

The next time you run opencode, if you execute ollama ps you'll get:

ollama ps
NAME                          ID              SIZE      PROCESSOR          CONTEXT    UNTIL               
qwen2.5-coder-7b-8k:latest    98181fbdef2d    6.2 GB    13%/87% CPU/GPU    8192       59 minutes from now   
@leonardorame commented on GitHub (Sep 22, 2025): For the record: Create a file named, for example modelfile (in any directory) with this content: ``` FROM qwen2.5-coder:7b-instruct PARAMETER num_ctx 8192 PARAMETER num_batch 384 PARAMETER num_thread 12 ``` Run: `ollama create qwen2.5-coder-7b-8k -f modelfile` (of course, the modelfile must be reachable by ollama, if not on the same directory use the absolute path i.e. /home/leonardo/modelfiles/modelfile). ``` gathering model components using existing layer sha256:60e05f2100071479f596b964f89f510f057ce397ea22f2833a0cfe029bfc2463 using existing layer sha256:66b9ea09bd5b7099cbb4fc820f31b575c0366fa439b08245566692c6784e281e using existing layer sha256:1e65450c30670713aa47fe23e8b9662bdf4065e81cc8e3cbfaa98924fcc0d320 using existing layer sha256:832dd9e00a68dd83b3c3fb9f5588dad7dcf337a0db50f7d9483f310cd292e92e using existing layer sha256:9b2154434353e33e707107d2c1a7b7c69023aa85d8545ba3e6975a8027e406dc writing manifest success ``` Then, to check, if you run ollama ls you'll get: ``` NAME ID SIZE MODIFIED qwen2.5-coder-7b-8k:latest 98181fbdef2d 4.7 GB 2 minutes ago .... ``` Adapt opencode.json: ``` { "$schema": "https://opencode.ai/config.json", "provider": { "ollama": { "npm": "@ai-sdk/openai-compatible", "name": "Ollama (local)", "options": { "baseURL": "http://localhost:11434/v1" }, "models": { "qwen2.5-coder-7b-8k": { "name": "qwen2.5-coder" } } } } } ``` The next time you run `opencode`, if you execute `ollama ps` you'll get: ``` ollama ps NAME ID SIZE PROCESSOR CONTEXT UNTIL qwen2.5-coder-7b-8k:latest 98181fbdef2d 6.2 GB 13%/87% CPU/GPU 8192 59 minutes from now ```
Author
Owner

@leonardorame commented on GitHub (Sep 22, 2025):

I tested it with a context of 8k and 16k, but none of these worked. I still get the instructions to create my file, in json format, when I need opencode to create it by itself.

@leonardorame commented on GitHub (Sep 22, 2025): I tested it with a context of 8k and 16k, but none of these worked. I still get the instructions to create my file, in json format, when I need opencode to create it by itself.
Author
Owner

@leonardorame commented on GitHub (Sep 22, 2025):

This worked!!: https://github.com/p-lemonish/ollama-x-opencode

@leonardorame commented on GitHub (Sep 22, 2025): This worked!!: https://github.com/p-lemonish/ollama-x-opencode
Author
Owner

@rekram1-node commented on GitHub (Sep 22, 2025):

sorry I should’ve communicated it better I was trying to relay info from that ^^

We should update our docs to make this easier for others

@rekram1-node commented on GitHub (Sep 22, 2025): sorry I should’ve communicated it better I was trying to relay info from that ^^ We should update our docs to make this easier for others
Author
Owner

@Atomic-Germ commented on GitHub (Sep 22, 2025):

Mine is now so concerned it suggested the crisis line. I'm starting to think the tool using is a gaslight.

@Atomic-Germ commented on GitHub (Sep 22, 2025): Mine is now so concerned it suggested the crisis line. I'm starting to think the tool using is a gaslight.
Author
Owner

@rekram1-node commented on GitHub (Sep 22, 2025):

@Atomic-Germ can you elaborate what you mean?

@rekram1-node commented on GitHub (Sep 22, 2025): @Atomic-Germ can you elaborate what you mean?
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#1792