z.ai provider consistently fails to use kilocode tools
Description
The z.ai LLM consistently fails to use kilocode's tools when used through the Z AI API Provider. Basically, everything other than reading files fails with errors such as:
- Kilo Code tried to use edit_file without value for required parameter 'target_file'. Retrying...
- Kilo Code tried to use edit_file without value for required parameter 'instructions'. Retrying...
- Kilo Code tried to use apply_diff without value for required parameter 'path'. Retrying...
I played around with the custom temperature but to no avail.
In this state, the combination of kilocode and z.ai is not usable.
Kilo Code tried to use edit_file without value for required parameter
This error is from the Morph fast apply experimental feature, please try disabling that first.
Kilo Code tried to use apply_diff without value for required parameter
If this error persists you can try disabling "Editing through diffs" (it's in the provider settings under Advanced)
This error is from the Morph fast apply experimental feature, please try disabling that first.
I never had and still don't have this feature enabled.
If this error persists you can try disabling "Editing through diffs" (it's in the provider settings under Advanced)
This seems to resolve it, thx. Still a bummer, this is not working with diffs.
TL;DR (The "TL" is at the end after the screenshot)
Summary of Issues: "Apply_Diff Fails" due tool use failure; "The model's response ended unexpectedly..."; and "Kilo Code is having trouble..." (which I am guessing occurs after a certain number of failures)
Models used when errors occured: openrouter/sonoma-sky-alpha & x-ai/grok-code-fast-1
OS, VSCode, Kilo Details: OS Specs: Edition Windows 11 Pro Version 24H2 Installed on 6/15/2025 OS build 26100.4770 Experience Windows Feature Experience Pack 1000.26100.197.0 Kilo: Version: 4.96.0 (0a8566d7) VS Code: Version: 1.104.1 (user setup) Commit: 0f0d87fa9e96c856c5212fc86db137ac0d783365 Date: 2025-09-17T23:36:24.973Z Electron: 37.3.1 ElectronBuildId: 12404162 Chromium: 138.0.7204.235 Node.js: 22.18.0 V8: 13.8.258.31-electron.0
I am posting this here because it appears to be an issue with tool use, despite not being about Z.Ai directly. If I am in error, let me know and I will jump to whatever thread is most appropriate.
I signed up for Kilo's API routing due to the extremely high number of call failures, amongst other issues, using OpenRouter. Unfortunately, it appears that I am having issues with Kilo as well. The failures are not exactly the same, but similar enough to think that the issue is now my set up or usage of the models. I have included the series of errors that are currently on my screen. I could provide historical sessions where there are more red blocks than any other color in the task box at the top of the extension tab. However, those were with OpenRouter.
That said, the problem has been getting worse (failures have been getting more frequent) day by day. Like I said I have been using Kilo for 3 days as an API router. The first day was gold. The second day saw some failures. Today.... Yeah... Today has been bad and is getting worse.
Even after turning off the diff editing, the tool runs into issues such as:
Kilo Code tried to use write_to_file without value for required parameter 'path'. Retrying...
What also happens again and again, is that, using z.ai, kilocode stops writing into files but adds this to the chat window instead:
<write_file>
<path>path/to/file.ts</path>
<content>
...
</...
Afterwards one of two things happen. Either it endlessly starts writing the same <write_file>... stuff until I cancel the execution, or it ends in this error at some point:
Kilo Code is having trouble...
This may indicate a failure in the model's thought process or inability to use a tool properly, which can be mitigated with some user guidance (e.g. "Try breaking down the task into smaller steps").
The error that I see has more to do with the apply_diff tool more than anything, but I suspect that there is probably a common cause for the errors, but kick out different messages based on minor nuace rather than massive differences in the error... That's just my initial reaction.
I am also experiencing this with z.ai provider and subscription, but using z.ai through Kilo or OpenRouter, the tools work fine. Anything that needs a tool just shows xml-like tags and do not get parse by Kilo.
I'm able to use Z.ai's OpenAI compatible endpoint with a token limit of 64k and it works. > 64k and tools start failing even though it has 2x the context supported.
i have same issue also the very same problem is in these #2513 #2550 #1818 https://github.com/Kilo-Org/kilocode/issues/2369#issuecomment-3290334035 https://github.com/Kilo-Org/kilocode/issues/2369#issuecomment-3290622905
i guess the main culprit is the z.ai itself cuz teh bug doesnt really depend on the IDE like Kilocode or Rucode or whatever its always fails at the same circumstances
I now employ a workaround that for now fixes the tooling issues for me. Instead of using the z.ai provider, I installed claude code router and - via the ccr ui - configured z.ai as the model for all types of calls:
"Providers": [
{
"name": "z.ai",
"api_base_url": "https://api.z.ai/api/anthropic/v1/messages",
"api_key": "YOUR_KEY",
"models": [
"glm-4.5"
],
"transformer": {
"use": [
"Anthropic"
]
}
}
],
"StatusLine": {
"enabled": false,
"currentStyle": "default",
"default": {
"modules": []
},
"powerline": {
"modules": []
}
},
"Router": {
"default": "z.ai,glm-4.5",
"background": "z.ai,glm-4.5",
"think": "z.ai,glm-4.5",
"longContext": "z.ai,glm-4.5",
"longContextThreshold": 60000,
"webSearch": "z.ai,glm-4.5",
"image": ""
},
Then, in kilocode, I switched to the "Anthropic" provider and set http://127.0.0.1:3456/ as the custom URL.
kilocode now thinks, I'm using sonnet but the ccr logs reveal that actually, glm-4.5 is used.
Edit: you have to start ccr in terminal (ccr start), so that the local server runs.
so it uses tools with no problems now ?
I customized the modes, created several new modes entirely, and updated the orchestrator. In the context settings, I enabled "Automatically run intelligent context compression" and set the "compression threshold" to 49%. The agent has been running for several hours now and there are no issues so far. The tools are not throwing any errors.
This isn't a solution, just a workaround. I noticed that constantly using context compression significantly degrades the model's performance. Overall, the problem remains unresolved.
My colleagues and I are running into the same issue: we can’t get GLM 4.5 to work, even though it should be a fully capable model. What’s odd is that I see other users on these forums using the model without problems, which makes me wonder.
I haven’t changed any settings in the Kilo Code extension, so in my case this fails consistently by default.
I’ve also come across several other issues that point to similar problems:
- #2658 user might be using GLM 4.5.
- #2560
- #2550
- #2369 contributors are reporting problems with GLM 4.5 even though OP mentions Qwen Code.
- #1818
- #1132
Did you install the model locally?
There may be some specifics that are exclusive to GLM 4.5, but there seems to be a broader issue with tool usage in general right now. If you look at other issues that people are bringing up with various models and different scaffolds there seems to be a pattern emerging that points to tool use in general. I am still looking into it personally at the moment, but that is the trend I am starting to see emerge.
Personally I have been using Grok Code Fast 1, Grok 4 Fast, Code SuperNova, Qwen3 Coder 450B, Google 2.5 Flash & Pro, GPT-OSS-120B, Claude 4 Sonnet, and GLM 4.5 & 4.5 Air. Every model that I have used through Kilo or Roo has had tool issues. Using Google CLI (Gemini models only) and Kiro (Claude 3.7 & 4 only) I had no issues at all. The fact that Claude and Gemini have issues in Kilo with tool use, but not in other IDE/scaffolds is very interesting. I realize that it is not entirely apples to apples, but its not apples to oranges....more like Fiji to Granny Smith.
Another thing on tool use with Kilo that I have noticed is that models seem to nearly refuse to use MCP servers. This is a recent phenomenon for me. I had almost started to take for granted that they would use MCP servers without any fuss. However, recently (last couple of days) various models almost flat out ignore my instructions to use MCP server(s).
All of that said, the thing that I am looking into right now is that in Grok's "thoughts" it mentioned that it was having difficulty with the edit_diff XML, which is the first time I have seen that. Additionally, models are getting stuck in loops attempting to search_and_edit or even simply trying to read a file. I asked Grok why this was and it merely said that the tool was only adding to the end of files what it was attempting to inject into a specific place somewhere else in the file.
I'll add my observations.
I use qwen-coder, and I use Filesystem MCP to work around tool issues.
After installing Filesystem MCP, Kilocode barely used it, without explicit instructions.
I created a rule prohibiting the use of standard tools and instructing it to use only Filesystem MCP. This didn't produce much of a result; without an explicit instruction, Kilocode continued to use its standard tools.
Even with an explicit instruction to use Filesystem MCP, errors occasionally occurred, indicating that Kilocode was accessing Filesystem MCP without specifying a specific tool or command.
I added a note to the task explaining the rules for accessing Filesystem MCP in your instructions. It helped, and the errors became fewer.
However, I'll note the progress over the last two weeks: Kilocode has started using Filesystem MCP for file management in half of the cases.
I can't determine the cause; I haven't changed any more rules or system prompts. I suspect that perhaps the model itself has been trained on my tasks or something.
Currently, I use both standard file editing tools and Filesystem MCP. Honestly, I've seen fewer errors. Switching between these tools helps when problems arise. As a last resort, I try creating a new task.
I've seen several users report that adjusting the temperature to 0.6 seems to work around this issue. I would advise anyone to test the model for effectiveness after the change though.
I'll report back with my testing when I get some time.
I can confirm that manually setting the temperature to 0.6 consistently fixed the described issue. My testing shows full performance with GLM 4.5 and 4.6.
That 100% did it for me. Set the temp to 0.6 and flawless victory.
I upgraded to z.ai Pro, and this feature really helped to increase the limit after the system started to fail over and over. Now, the reliable limit is exactly 50% of the announced 200k capacity. Specifically, right after the 100k context limit is filled, the 'tool use' functionality starts to fail repeatedly. The only viable solutions are to either manually condense the context or to set the auto-condensation feature at 50%. Overall, it is significantly better than it was with the 30k limit, but it is still misleading when they advertise a 200k capacity. The reality is that the functional limit is just 100k.