Repository navigation
Tool use with Ollama models. #1068
Copy link
Copy link
Closed
Description
using latest ollama version and tool capable models, executions of tool calls seems to be aborted.
Models are not keen to use tool calls, but could be encourage to at least attempt for one but result fails.
opencode.json file;
{
"$schema": "https://opencode.ai/config.json",
"provider": {
"ollama": {
"npm": "@ai-sdk/openai-compatible",
"options": {
"baseURL": "http://localhost:11434/v1"
},
"models": {
"qwen3:30b": {
"name": "Qwen3:30b 65k MoE - local",
"tools": true,
"reasoning": true,
"options": { "num_ctx": 65536 }
},
"devstral": {
"name": "Devstral 14b Dense - local",
"tools": true,
"reasoning": false,
"options": { "num_ctx": 131072 }
}
}
},
"moonshot": {
"id": "moonshot",
"npm": "@ai-sdk/openai-compatible",
"options": {
"baseURL": "https://api.moonshot.cn/v1"
},
"models": {
"kimi-k2-0711-preview": {
"name": "kimi-k2-0711-preview",
"cost": {
"input": 0.001953125,
"output": 0.009765625
}
}
}
}
}
}
My hack to have this work on NixOS.
{ pkgs, ... }:
let
opencodeBin = "/home/berkay/.opencode/bin/opencode";
configSource = "/home/berkay/.config/opencode/providers/opencode.json";
authSource = "/home/berkay/.local/share/opencode/auth.json";
wrapper = pkgs.writeShellScriptBin "opencode" ''
#!${pkgs.bash}/bin/bash
CONFIG_SOURCE="${configSource}"
CONFIG_LINK="./opencode.json"
AUTH_SOURCE="${authSource}"
AUTH_LINK="./auth.json"
# Symlink config if not present
CLEANUP_CONFIG_SYMLINK=0
if [ ! -f "$CONFIG_LINK" ]; then
ln -s "$CONFIG_SOURCE" "$CONFIG_LINK"
CLEANUP_CONFIG_SYMLINK=1
fi
# Symlink auth if not present
CLEANUP_AUTH_SYMLINK=0
if [ ! -f "$AUTH_LINK" ]; then
ln -s "$AUTH_SOURCE" "$AUTH_LINK"
CLEANUP_AUTH_SYMLINK=1
fi
# Run opencode
if [ -x "${opencodeBin}" ]; then
${pkgs.steam-run}/bin/steam-run "${opencodeBin}" "$@"
STATUS=$?
else
echo "Error: opencode binary not found at ${opencodeBin}"
exit 1
fi
# Remove symlinks if we created them
if [ "$CLEANUP_CONFIG_SYMLINK" = "1" ]; then
rm -f "$CONFIG_LINK"
fi
if [ "$CLEANUP_AUTH_SYMLINK" = "1" ]; then
rm -f "$AUTH_LINK"
fi
exit $STATUS
'';
in
{
home.packages = [
pkgs.steam-run
wrapper
];
xdg.desktopEntries.opencode = {
name = "OpenCode";
comment = "AI Coding Agent TUI";
exec = "opencode";
icon = "utilities-terminal";
categories = [ "Development" ];
terminal = true;
startupNotify = false;
};
xdg.enable = true;
}
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels
Activity
smoush7 commentedon Jul 17, 2025
#1034 - same issue, frustrating.
DiedeClaessens commentedon Jul 17, 2025
Not a solution, but I have had better success using LMStudio. Important with that one is that you increase context scope of the model
leporel commentedon Jul 17, 2025
"options": { "num_ctx": 131072 }Does this work with ollama ? I think this is not supported with openai-compatible ollama/ollama#8938
nutt-y commentedon Jul 18, 2025
Where exactly does the
num_ctxfield go? I am not really sure where that should go.renich commentedon Jul 18, 2025
OK. ollama user here in Fedora 42.
I was looking for this solution for a while. This is why I'm posting it here (and all issues) for all to know:
@p-lemonish discovered why and the fix is easy: https://github.com/p-lemonish/ollama-x-opencode
In short, download a model that has tool capabilities:
After that, you're good to go. Just try it out:
With a bit of luck, your file will be there.
Credits:
Pre-requisites
My configuration looks like this:
{ "$schema": "https://opencode.ai/config.json", "provider": { "ollama": { "npm": "@ai-sdk/openai-compatible", "options": { "baseURL": "http://localhost:11434/v1" }, "models": { "granite3.3:8b": { "tools": true }, "mistral-small3.2:24b": { "tools": true }, "qwen3:latest": { "tools": true, "reasoning": true } } } } }Notes
azaeldrm commentedon Aug 30, 2025
It seems they added OLLAMA_CONTEXT_LENGTH as an env var for Ollama. I'm testing it as we speak, but it seems like it works!
maxolasersquad commentedon Sep 11, 2025
The
>>> /set parameter num_ctx 16384from @renich was the key for me. Once I set that on qwen3 the tool usage started working.vdmitriyev commentedon Sep 26, 2025
I have a sort of workaround that semi-works for now. The issue is not only the context of
ollama, but also a model template. Here how this could be addressedPull models
View
templateof existing model:Create initial version of
Modelfile-qwen3-coder.datfile (must be manually modified later):Edit file with content of the file
Modelfile-qwen3-coder.datmanually.Modelfile-qwen3-coder.datmust start with:Modelfile-qwen3-coder.datmust end it:Create a new ollama model
Then use
qwen3-coder-32kin opencodeP.S. It is not a final solution. But maybe it will save some people a bit of time in searching and trying out different ways of making
opencodework withollamamodelsBhautikChudasama commentedon Oct 5, 2025
How does websearch tool work in ollama?
rekram1-node commentedon Oct 5, 2025
@BhautikChudasama the tool should just work assuming ollama has enough context set and is presenting it as an option to the llm
maxolasersquad commentedon Oct 5, 2025
Please do not hijack an issue about one subject to ask a question about another subject.
thdxr commentedon Mar 25, 2026
To stay organized issues are automatically closed after 90 days of no activity. If the issue is still relevant please open a new one.
fix(app): restore composer action labels (anomalyco#1068)