-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Description
Problem (one or two sentences)
Roo Code cannot handle native tool calling when using Kimi K2 Thinking model. This is important because it works the best with native tool calls, and if I try XML ones, it starts doing them in its think block and Roo Code ignores them. But native calls are outside of the think block, and Roo Code seem to pick up them correctly (for example, native read_file tool call gets formatted in Roo Code UI as "Roo wants to read this file", which means Roo Code understood that the tool call is there and picked it up). But then, it seems to fail to add file content. Other native tool calls are effected as well if they have output.
Context (who is affected and when)
Everyone who is using Kimi K2 Thinking is affected, as far as I can tell. The issue is reproducible with both llama.cpp and ik_llama.cpp.
Reproduction steps
- Use latest ik_llama.cpp or llama.cpp with their provided chat template and enable Jinja:
--jinja --chat-template-file /home/lissanro/pkgs/ik_llama.cpp/models/templates/Kimi-K2-Thinking.jinja --special. My full command (the same command works for mainline llama.cpp, just remove all instances of "ik_"):
~/pkgs/ik_llama.cpp/build/bin/llama-server \
--model /mnt/neuro/models/Kimi-K2-Thinking-Q8_0-Q4_0.gguf \
--ctx-size 262144 --n-gpu-layers 62 --tensor-split 28,22,25,25 -ctk q8_0 -ctv q8_0 -b 4096 -ub 4096 \
-ot exps=CPU \
--threads 64 --host 0.0.0.0 --port 5000 \
--jinja --chat-template-file /home/lissanro/pkgs/ik_llama.cpp/models/templates/Kimi-K2-Thinking.jinja --special \
--slot-save-path /var/cache/ik_llama.cpp/k2-thinking
-
Using latest Roo Code, set in Advanced settings of OpenAI-Compatible endpoint Native tool calling.
-
Try a simple prompt, like "Read a file and summarize it". For example, these are generated tokens I get:
token 9413: 'Let'
token 1019: ' me'
token 1701: ' first'
token 2032: ' read'
token 276: ' the'
token 47572: ' Navigation'
token 42346: 'Icons'
token 126635: '.jsx'
token 1650: ' file'
token 308: ' to'
token 2050: ' see'
token 30245: ' what's'
token 6506: ' currently'
token 1459: ' there'
token 11: ','
token 1780: ' then'
token 2598: ' check'
token 1632: ' how'
token 4643: ' it's'
token 2602: ' being'
token 2040: ' used'
token 306: ' in'
token 276: ' the'
token 29297: ' Header'
token 8183: ' component'
token 13: '.'
token 163607: '</think>'
token 163595: '<|tool_calls_section_begin|>'
token 163597: '<|tool_call_begin|>'
token 41937: 'functions'
token 8827: '.read'
token 6101: '_file'
token 25: ':'
token 15: '0'
token 163598: '<|tool_call_argument_begin|>'
token 8264: '{"'
token 12481: 'files'
token 1289: '":'
token 81103: '[{"'
token 4953: 'path'
token 7471: '":"'
token 6435: 'src'
token 23991: '/components'
token 45841: '/icons'
token 14: '/'
token 28433: 'Navigation'
token 42346: 'Icons'
token 126635: '.jsx'
token 16934: '"}'
token 24216: ']}'
token 163599: '<|tool_call_end|>'
token 163596: '<|tool_calls_section_end|>'
token 163586: '<|im_end|>'
Quote from ikawrakow/ik_llama.cpp#955 (comment):
Written by magikRUKKOLA:
Roo Code sent the description of the native tools to the LLM ( https://github.com/RooCodeInc/Roo-Code/blob/main/src/core/prompts/tools/native-tools/read_file.ts ). And by the response of the LLM you're seeing that it picked up the tool for an execution (see tool_calls_section_begin token). So the stage 1 and 2 are completed. Quote:
[x] Passing function descriptions to Kimi-K2
[x] Kimi-K2 decides to make a function call and returns the necessary information for the function call to the userNow its stage 3. Quote:
[ ] The user performs the function call, collects the call results, and passes the function call results to Kimi-K2
So now the RooCode supposed to do that. Why it doesn't do so? Well, I have no idea. Just check the logs of the RooCode somehow.
I wonder, does Roo Code follow the official documentation for native tool calls: https://huggingface.co/moonshotai/Kimi-K2-Thinking/blob/main/docs/tool_call_guidance.md ?
I am attaching one of the screenshots how the issue looks in Roo Code:
Expected result
Roo Code executes the native tool call, and for example for native read_file tool call returns file's content
Actual result
The model does not get any output, sees empty result, and tries again, after few tries Roo Code usually stops it due to looping
Variations tried (optional)
Another way to reproduce, that demonstrated that Roo Code seems to execute tool calls but fails to add their output:
Prompt: Write "Test" to Test.md
Then the model has some thinking, at the end deciding "Let me proceed with the write_to_file tool." and it does:
token 9413: 'Let'
token 1019: ' me'
token 1328: ' use'
token 276: ' the'
token 4846: ' write'
token 4585: '_to'
token 6101: '_file'
token 4453: ' tool'
token 308: ' to'
token 2819: ' create'
token 77832: '/write'
token 5294: ' Test'
token 6847: '.md'
token 472: ' with'
token 276: ' the'
token 3646: ' content'
token 414: ' "'
token 2719: 'Test'
token 6082: '".'
token 163607: '</think>'
token 163595: '<|tool_calls_section_begin|>'
token 163597: '<|tool_call_begin|>'
token 41937: 'functions'
token 9189: '.write'
token 4585: '_to'
token 6101: '_file'
token 25: ':'
token 15: '0'
token 163598: '<|tool_call_argument_begin|>'
token 8264: '{"'
token 4953: 'path'
token 1289: '":'
token 1: '"'
token 2719: 'Test'
token 6847: '.md'
token 3923: '","'
token 4204: 'content'
token 7471: '":"'
token 2719: 'Test'
token 3923: '","'
token 1611: 'line'
token 5736: '_count'
token 1289: '":'
token 16: '1'
token 92: '}'
token 163599: '<|tool_call_end|>'
token 163596: '<|tool_calls_section_end|>'
token 163586: '<|im_end|>'
The result is that I see Test.md opened and "Test" added to it.
Next expected result would be the model calling task completion, but instead, it does not see the result of its tool call, and starts looping, thinking again that needs to write it, like previous attempt is not even there. Either Roo Code does not append the output of the tool call or even drops whole messages with native tool calls, otherwise it is strange that the model loops like that without even acknowledging the previous attempt (especially when it was successful).
App Version
3.34.2
API Provider (optional)
OpenAI Compatible
Model Used (optional)
Kimi K2 Thinking
Roo Code Task Links (optional)
No response
Relevant logs or errors (optional)
Metadata
Metadata
Assignees
Labels
Type
Projects
Status