v18 broken tool calling

#21
by slepkaviba - opened

v18 cannot call any tools in opencode:
I see similar up to v18, including tool not calling or bleeding (in opencode):

Let me use the systematic debugging skill for this bug investigation.

<parameter=name>
skill
<parameter=parameters>
{"name": "systematic-debugging"}

v16 runs perfectly fine...

Ok, it is caused by https://github.com/Opencode-DCP/opencode-dynamic-context-pruning plugin...

I guess it is something with the way it manipulates the context... As without it, it works fine.

Also OWUI has no issue with tool calls...

Gosh. Those ecosystems are pure chaos...

Ok, it happens for anything playing with messages...

I'm the architect agent — no personal name. I plan and design only.
What needs planning?

<instruction name="context_far">
CONTEXT REMINDER — ~11%
You should use `ctx_reduce` to drop old tool outputs before continuing.
Largest: §1§, §3§, §4§. Tags §4§ and above are protected (last 20) — You MUST NOT try to reduce those.
Tags are marked with §N§ identifiers (e.g., §1§, §42§).
Actions:
- 
drop: Remove content entirely. Best for old tool outputs you already acted on.
- 
Syntax: "3-5", "1,2,9", or "1-5,8,12-15" (bare integers).
- 
Only drop what you have already processed. NEVER drop large ranges blindly.
</instruction>

I guess I will report on opencode side...

Ps. Amazing work man! <3

Or might be this is some way that nested tags bleed? As seems like it bleeds out now the tags, if they are somewhere in the message.

I think I have finally solved it in v19. So far it has been flawless in 3 long agentic tests in a row. Previously, I had it happen in around 80% of my sessions.

This has been a tough one to crack. To fix it I had to resort to better prompt engineering:

<IMPORTANT>
Reminder:
- You can use the <think></think> block to plan your next tool call OR to synthesize data and formulate your final response to the user.
- ALL explanation and reasoning MUST be placed strictly inside the <think></think> block.
- Function calls MUST follow the specified format: an inner <function=...></function> block must be nested within <tool_call></tool_call> XML tags.
- If you choose to call a tool, you MUST output the <tool_call> block IMMEDIATELY after closing </think>. Do NOT output any conversational text before the tool call.
- The <tool_call> and <function> tags MUST be at the very beginning of a new line, with NO spaces or indentation before them.
- To call multiple functions, output a separate, completely closed <tool_call></tool_call> block for EACH function. Do NOT nest <tool_call> blocks.
- If you have gathered all necessary data and do not need to call a tool, answer the question like normal and provide your final response to the user IMMEDIATELY after closing </think>.
</IMPORTANT>

It helped a bit, but did not solve it. What I think finally did it, was a complete rewrite of the KV cache handling, by setting preserve_thinking to true as default, and abolishing the empty think injection, which was poisoning the model's in-context learning.

froggeric changed discussion status to closed

That's interesting. I have preserve thinking always on, but with thinking on and off it was strange...

Man, this is amazing job you do here.

Sign up or log in to comment