Repository navigation
Tool Calling Issues with Open Source Models in OpenCode #234
Description
Summary
While OpenCode provides excellent support for frontier cloud models, I've encountered some compatibility challenges when using open source models for tool calling functionality. This appears to be related to differences in how various open source models implement tool calling compared to the standardized approaches used by cloud providers.
Environment
- OpenCode Version:
0.1.107 - Provider: Custom OpenAI-compatible endpoint (local models via Ollama)
- Models Tested:
qwen2.5-coder:7b-instructqwen2.5-coder:14b-instructgranite3.3:latest
Issues Encountered
1. Case Sensitivity in Tool Names
Expected: Model calls write tool (lowercase)
Actual: Models (like qwen) generate Write tool calls (capital W)
Error: AI_NoSuchToolError: Model tried to call unavailable tool 'Write'. Available tools: bash, edit, webfetch, glob, grep, list, lsp_diagnostics, lsp_hover, patch, read, write, todowrite, task, todoread.
Affected Models:
- qwen2.5-coder:7b-instruct
- qwen2.5-coder:14b-instruct
2. Complete Tool Calling Failure
Expected: Model generates tool calls when requested to create/edit files
Actual: Models respond with text only, no tool calls generated
Affected Models:
- granite3.3:latest (despite
"tools": trueconfiguration)
Steps to Reproduce
- Configure OpenCode with local open source model:
{
"model": "local/qwen2.5-coder:7b-instruct",
"toolsEnabled": true,
"provider": {
"local": {
"api": "http://localhost:11434/v1",
"models": {
"qwen2.5-coder:7b-instruct": {
"tools": true,
"reasoning": true
}
}
}
}
}- Ask model to create a file:
"Create a test.md file with 'Hello World' content" - Observe tool calling behavior
Expected Behavior
- Models should generate properly formatted lowercase tool calls (
write,edit, etc.) - Tool execution should work consistently across different open source models
- Configuration should clearly indicate which models support tool calling
Actual Behavior
- Inconsistent tool calling across models
- Case sensitivity issues preventing tool execution
- Some models fail to generate tool calls entirely
Additional Context
This appears to be related to the diverse ecosystem of open source models, where different models have varying tool calling implementations and training approaches. OpenCode works excellently with standardized cloud models, and extending this robust functionality to the more varied landscape of open source models presents some interesting technical challenges.
Possible Solutions
- Tool name normalization: Implement automatic case conversion (
Write→write) - Model compatibility matrix: Document which open source models have been tested and verified to work
- Per-model tool configuration: Allow custom tool calling formats per model
Impact
Improving compatibility with open source models would help developers who prefer or require local/private model usage for privacy, security, cost, or infrastructure reasons.
Activity
piotrjaromin commentedon Jun 23, 2025
I have similar problem, ollama models respond with information that they need to use tools and then they are not doing it. But from what I saw it was mostly for "/init" prompt, when I provide simple prompts like "list files in current directory" or "read log.txt file" it seems to work at least with qwen3:30b (did not check smaller models beucase I was too focused on making "/init" work)
p-lemonish commentedon Jul 1, 2025
Hi, in case someone else stumbles upon this. I have documented a solution to this. My issue was related to ollama forcing the context window of the local LLM's to be 4096, which cut off the context given by opencode ~10k tokens. Simply increase the context window of your model.
https://github.com/p-lemonish/ollama-x-opencode
Chleba commentedon Jul 6, 2025
@p-lemonish well this is the first time using "/no_think" prefix that devstral was able to create at least one file.
I did use devstral with bigger context window before with TUI but nothing could be created, written in or anything.
Cyrille37 commentedon Dec 8, 2025
Hi
I don't know if it helps, but I solved some tool errors without forgetting to call
/initat first.fix: resolve issues anomalyco#240, anomalyco#238, and anomalyco#234 (…
fix: improve tool name repair for local/Ollama models
chore: Add supportsStructuredOutputs option to blablador config
Delqhi commentedon Mar 7, 2026
We hit the same class of failures with OpenAI-compatible custom providers. In our case, the provider would often answer once with text or legacy tool payloads and then the OpenCode session stopped instead of continuing into a real tool loop.
We got this working in a fork with an opt-in compatibility layer instead of treating every custom provider like native OpenAI:
message.function_calland streameddelta.function_call<tool_call>payloadsfinish_reason=stopbut no usable tool call was recognizedfunctions/function_callmore reliably thantools/tool_choiceLive result on our side: a previously broken OpenAI-compatible endpoint that answered once and stopped was able to continue multi-turn tool execution in OpenCode.
This likely overlaps with the blank/empty custom-provider reports in #15756, #5210, and #10573.
If useful, I can package this into a PR as an explicit custom-provider compatibility path so the default behavior for native providers stays unchanged.
Delqhi commentedon Mar 7, 2026
Opened a PR for this: #16531
It adds an opt-in compat layer for custom
@ai-sdk/openai-compatibleproviders viaprovider.options.toolParser, including legacyfunction_callrequest/response rewriting and tool recovery from structured JSON or single-tool text replies.eric-isakson commentedon May 5, 2026
EDIT: I spoke to soon, I had brief success with this strategy then went right back to having tool calling failures :(
For folks that land here before any kind of real fix is available, I was able to work around this limitation with some simple prompting in
~/.config/opencode/AGENTS.md, thought it might be helpful for someone since it took me several hours of fiddling to get this working, it is working successfully for me with qwen3 coder models running in ollama:I would imagine similar prompting is a reasonable workaround but might need to be tweaked a little depending on which model you are using.
fix: list skills across skill directories (anomalyco#234)
github-actions commentedon Jul 5, 2026
To stay organized issues are automatically closed after 60 days of no activity. If the issue is still relevant please open a new one.