Skip to content

fix(agent): raise per-response token budget so tool calls aren't truncated#138

Merged
bararchy merged 1 commit into
masterfrom
fix/agent-followthrough
Jun 29, 2026
Merged

fix(agent): raise per-response token budget so tool calls aren't truncated#138
bararchy merged 1 commit into
masterfrom
fix/agent-followthrough

Conversation

@bararchy

@bararchy bararchy commented Jun 29, 2026

Copy link
Copy Markdown
Member

Root cause

The agent appeared to 'stall' after announcing intent and never wrote the file. A raw-token dump on a live 30B session showed the model does emit a correct <tool_call><function=write_file>… with the whole file inline — but the 512-token per-response cap truncated it before the closing </tool_call> tag. parse_tool_calls needs that tag, so it matched nothing → the turn silently ended.

Fix

One line: the model already self-terminates on <|im_end|>, so the per-response cap is just a safety bound — raise the default 512 → 4096 (env SHAINET_AGENT_MAX_TOKENS). KV-cache cost grows ~linearly (~0.2-0.4 MB/token on this 30B), so a few-thousand-token ceiling is comfortable on a 16 GB card.

Verified

  • Builds (stub + CUDA no-codegen), crystal tool format clean, ameba 0.
  • 30B (Q4 + MoE offload) end-to-end: ⚒ write_file(path=…, content=<full script>) now generates completely and parses — the call fires.

@bararchy bararchy changed the title fix(agent): follow through when the model only announces intent fix(agent): raise per-response budget so tool calls aren't truncated mid-write Jun 29, 2026
…cated

The model writes whole files inline inside <tool_call>, but the 512-token
per-response cap cut generation off before the closing </tool_call> 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.
@bararchy
bararchy force-pushed the fix/agent-followthrough branch from a722951 to b71a901 Compare June 29, 2026 13:02
@bararchy bararchy changed the title fix(agent): raise per-response budget so tool calls aren't truncated mid-write fix(agent): raise per-response token budget so tool calls aren't truncated Jun 29, 2026
@bararchy
bararchy merged commit e6a4128 into master Jun 29, 2026
5 checks passed
@bararchy
bararchy deleted the fix/agent-followthrough branch June 29, 2026 13:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant