From b71a901da98d91d68d0e1d0f78e14f3c282fe8ed Mon Sep 17 00:00:00 2001 From: Bar Hofesh Date: Mon, 29 Jun 2026 16:02:30 +0300 Subject: [PATCH] fix(agent): raise per-response token budget so tool calls aren't truncated The model writes whole files inline inside , but the 512-token per-response cap cut generation off before the closing tag, so parse_tool_calls found no call and the turn silently ended. The model already stops itself on <|im_end|>, so the cap is just a safety bound: raise the default 512 -> 4096 (env SHAINET_AGENT_MAX_TOKENS). KV cache grows ~linearly with it. --- examples/agent.cr | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/examples/agent.cr b/examples/agent.cr index 669a5e6..ef30674 100644 --- a/examples/agent.cr +++ b/examples/agent.cr @@ -536,7 +536,11 @@ end # Entry point # ---------------------------------------------------------------------------- model_dir = ARGV[0]? -max_tokens = (ARGV[1]? || "512").to_i +# Per-response generation ceiling. This is a safety bound, not a target — the +# model stops itself on <|im_end|>. It must be large enough that a tool call +# writing a whole file isn't truncated before its closing tag +# (which would make the call unparseable). KV cache grows ~linearly with it. +max_tokens = (ARGV[1]? || ENV["SHAINET_AGENT_MAX_TOKENS"]? || "4096").to_i unless model_dir && Dir.exists?(model_dir) STDERR.puts "Usage: agent [max_tokens]" STDERR.puts " (point at an already-downloaded model, e.g. ~/models/Qwen3-Coder-30B-A3B-Instruct)"