maximus-slm-tool-calling
Skill1 starsChanged 4 months agoMITView on GitHub
Make small local models (roughly 3B-32B) call tools and emit JSON reliably. Covers native chat-template tool calling vs prompted JSON, grammar-constrained decoding (llama.cpp GBNF / JSON schema, Ollama format), shrinking the tool surface, one-tool-per-step decomposition, tool-result truncation, and a malformed-call regression test. Use for 'local model won't call tools', 'agent writes the tool call as text', 'invalid JSON from Ollama', 'GBNF', 'constrained decoding', 'function calling with a small model'.
In this repository49 other files it gives its agents.
- core/AGENTS.mdAGENTS.md
- CLAUDE.mdCLAUDE.md
- file-opsSkill
- maximus-agent-designSkill
- maximus-ai-cost-controlSkill
- maximus-ai-data-pipelineSkill
- maximus-ai-fluency-for-buildersSkill
- maximus-ai-product-specSkill
- maximus-ai-safety-governanceSkill
- maximus-ai-ux-patternsSkill
- maximus-brainSkill
- maximus-build-featureSkill
- maximus-chain-of-verificationSkill
- maximus-code-reviewSkill
- maximus-contact-intelligenceSkill
- maximus-counterparty-discoverySkill
- maximus-debug-incidentSkill
- maximus-deep-research-proSkill
- maximus-deep-researchSkill
- maximus-design-specSkill
- maximus-devops-shipSkill
- maximus-eval-and-testSkill
- maximus-fine-tuningSkill
- maximus-fintech-paymentsSkill
- maximus-investigative-researchSkill
- maximus-k3-model-selectionSkill
- maximus-k3-self-hostingSkill
- maximus-literature-reviewSkill
- maximus-llm-model-selectionSkill
- maximus-local-research-assistantSkill
- maximus-local-research-assistantSkill
- maximus-mlops-deploySkill
- maximus-ollama-opsSkill
- maximus-openclaw-localSkill
- maximus-people-finder-recruiterSkill
- maximus-people-finderSkill
- maximus-plan-implementationSkill
- maximus-prompt-engineeringSkill
- maximus-python-scientificSkill
- maximus-rag-pipelineSkill
- maximus-replit-handoff-proSkill
- maximus-slm-evalSkill
- maximus-slm-local-finetuneSkill
- maximus-slm-local-stackSkill
- maximus-transaction-analystSkill
- maximus-write-articleSkill
- memory-keeperSkill
- skill-templateSkill
- web-researchSkill
The file
Files
Maximus — SLM Tool Calling
Frontier models make tool calling look like a solved problem. Small models
expose how narrow the channel really is: the call wrapped in an apology, file
where the schema said path, or a perfectly worded description of the call
instead of the call itself. None of that is fixed by writing "please" in
capitals.
Purpose
Take a local agent that fails at tool calls and make its failure rate measurable, then low. Work through the fixes in order of impact, and prove each one with a regression set rather than a single lucky run.
Scope boundary
| Need | Skill |
| Reliable tool calls / JSON from a small model | this skill |
| Agent loop design, memory, recovery (any model) | maximus-agent-design |
| Prompt and schema wording | maximus-prompt-engineering |
Runtime config (format, templates, context) | maximus-ollama-ops |
| Measuring pass rate across models | maximus-slm-eval |
The three ways a model calls a tool
- Native, via the chat template. The model was trained to emit calls in
a format its template encodes, and the server returns a structured
tool_callsfield. The most reliable path, when it exists. - Prompted JSON. Tools are described in the prompt and the harness parses the reply. Works with any model and fails far more often, because nothing enforces the shape.
- Edit formats. Diffs or search/replace blocks instead of a schema. Weaker models handle text formats better, and the failures are visible.
Core workflow — fixes in order of impact
- Build the regression set first. Collect 20-50 real prompts with their expected tool and arguments, including multi-step chains and a few where no tool is the right answer. Score: parses, right tool, right arguments, chain completes. Without this, every "fix" is anecdote.
- Use a model trained for tool use. Reliability is a training property:
two models of the same size can differ enormously. Prefer agentic or coder
tunes, and confirm
ollama showlists thetoolscapability. - Confirm the template. A GGUF imported without its tool-call template
silently degrades to prompted JSON. Check
ollama show --template. - Constrain the decode. Grammar-constrained decoding masks every token
that would break the schema, so invalid JSON is never produced. llama.cpp
converts JSON Schema to GBNF (
json_schemaon completions,response_formaton/chat/completions,--grammar-fileon the CLI). Ollama takes a schema informat. Constrain the action block, not the whole reply: forcing structure at every token can suppress the reasoning the model would otherwise do first. - Shrink the tool surface. Fewer tools, shorter descriptions, enum-typed arguments. Each tool definition is also context the model must hold.
- Decompose chains. Small models commonly lose the tool-call pattern after the first tool result. Give each step one tool, with the orchestration in code rather than in the model.
- Truncate tool results. Large outputs push the model past its effective working memory. Summarize or slice before feeding them back.
- Validate and retry once. Parse against the schema. On failure, send the exact validation error back once, then fail loudly. Never loop.
Grammar gotchas
- llama.cpp supports a subset of JSON Schema. Unsupported features are
skipped silently, so test the converted grammar with the Python converter
or
llama-gbnf-validator. - Objects default to no additional properties in the converter.
- Patterns like
x? x? x? ...can make sampling very slow; usex{0,N}. - Constrained shape is not correctness. A schema-valid call to the wrong tool with the wrong ID still needs checking.
Anti-patterns
- "You MUST call the tool" as the whole fix. It helps a little, and it does not replace a template or a grammar.
- Twelve tools on a 7B model. Split the agent.
- Grammar over the whole reply on a reasoning task. Let it think, then constrain.
- Judging from one run. Tool-call failure is a rate; measure it.
- Retrying until it parses. That hides a broken setup and burns latency.
Output
The regression set, a before/after pass-rate table per fix applied, the final schema or grammar, and a one-line statement of the residual failure rate the user is accepting.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

