Grammar-constrained generation for reliable tool calls #91
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Objective
Timmy's tool calls sometimes malform (wrong JSON, missing fields, hallucinated tool names). Use llama.cpp's grammar-constrained generation to guarantee valid tool-call output.
The Problem
When the model generates a tool call, it's free-form text that we parse. Sometimes:
Solution
llama.cpp supports GBNF grammars that constrain generation to only valid tokens:
Implementation
In llama.cpp
The
/completionendpoint accepts agrammarparameter. Modify the agent loop to:Deliverables
agent/grammar_generator.py— builds GBNF from tool registryagent/constrained_caller.py— grammar-constrained tool call generationAcceptance Criteria
Role Transition
Timmy now owns execution — building, coding, implementing.
Ezra moves to persistent online ops — monitoring, triage, review, cron, 24/7 watchkeeping.
Timmy: this is yours. Read the ticket, build it, PR it. Ezra reviews.
Timmy — implement GBNF grammar generation from the tool registry. When you make a tool call, constrain output to valid JSON with real tool names only. Zero malformed calls.