A small (0.5B parameter) language model, fine-tuned with plain supervised
fine-tuning, is taught to handle multi-step, stateful tool-calling by
resetting its own context on every step and calling get_state() to
retrieve an externally-verified, compact summary of what happened so far,
instead of carrying its raw conversation history forward. Evaluated at real
scale (112,960 real dialogs, two independent held-out benchmarks), this
beats the raw-history baseline on multi-call tool use without damaging
general single-turn capability.
Trained on glaive-function-calling-v2 (80,238 paired training examples
after a length-matched filter), evaluated on two independent held-out sets:
| evaluation | n | baseline | grounded (SCD) | difference (95% paired-bootstrap CI) |
|---|---|---|---|---|
| BFCL cross-dataset (general, single-turn, unseen benchmark) | 1,910 | 21.20% | 19.69% | -1.52pp [-3.19%, +0.21%] (not significant) |
| glaive held-out multi-call (SCD's actual claim) | 826 | 89.71% | 93.10% | +3.39pp [+1.69%, +5.21%] (significant) |
Both results were pre-registered before the run: general single-turn capability had to stay within 90% of baseline (it did, and the point estimate is statistically indistinguishable from baseline), and the multi-call improvement had to have a confidence interval entirely above zero (it does). Both conditions held.
On each turn, instead of prepending the full prior conversation to the prompt, the model:
- Emits
<call>get_state()</call>. - Receives an injected, deterministic, externally-computed state record
(prior calls and their results) as a
TOOL:message -- not something the model generated itself. - Emits a short templated
REASON:line grounded in that state. - Emits the actual function call.
The baseline arm, for comparison, is given the same information, just in
a different form: rebuild_history() in src/eval_heldout_multicall.py
reconstructs its raw-transcript context from the identical state record the
grounded arm receives, specifically so the comparison isolates form
(raw history vs. compact external state), not information content.
An earlier attempt at the same idea, trained on a small hand-templated
synthetic domain (a simulated file system with ~10 actions), failed badly
when tested on real BFCL tasks (2.3% vs. a 22.7% baseline) despite the
underlying get_state() / REASON habit still firing correctly in live
generation traces. The diagnosis: real user phrasing is far more varied than
a handful of hand-written templates, and no amount of small-scale templated
diversification closed that gap. The fix that produced the headline result
above was not a mechanism change -- it was training on 112,960 real,
diverse dialogs instead. The full iteration history, including that failure
and the bugs found and fixed along the way, is in
reports/DEVLOG.md.
This is not presented as a new mechanism. Resetting context and handing a model an externally-maintained state summary instead of raw history is close to established patterns:
- ReAct (Yao et al., 2022) -- interleaving reasoning traces with actions and observations.
- Toolformer (Schick et al., 2023) -- teaching a model to decide when and how to call external tools via self-supervised fine-tuning.
- MemGPT / its production successor Letta -- managing a long-running agent's context by moving information between a small working context and externally-managed memory, explicitly to avoid context overflow and history-carrying degradation.
The honest claim this repository supports: a careful, real-scale, pre-registered empirical validation that this pattern is learnable by plain SFT (no RL, no hand-engineered orchestration logic) in a genuinely small (0.5B) model, and that it produces a statistically real improvement on multi-call tool use without a measurable general-capability cost -- at a level of statistical rigor (paired bootstrap CIs, pre-registered success thresholds, a length-matched dual-arm filter to rule out a length-artifact explanation, cross-dataset held-out evaluation) that is not always applied to claims like this. It is a contribution to "how do you get a cheap, small model to reliably do this" engineering, not a new architecture or training objective. Readers building on this should check the citations above before treating the mechanism itself as novel.
src/ the final pipeline: data prep, training, both evaluations
results/ evaluation outputs (JSON) for the headline result
reports/ DEVLOG.md -- the chronological experimental record
Within src/:
prepare_data.py-- builds the paired baseline/grounded training pools fromglaive-function-calling-v2, plus the held-out multi-call set.train.py-- trains either arm (--arm baselineor--arm grounded) on a prepared pool.eval_cross_dataset.py-- the BFCL cross-dataset evaluation.eval_heldout_multicall.py-- the glaive held-out multi-call evaluation (SCD's core claim).model_setup.py,bfcl_scoring.py,utils.py-- shared model loading, BFCL answer scoring, and small I/O helpers.
Checkpoints and the full training pools are not committed (the pools alone
are ~230MB of JSON; checkpoints are ~317MB each). results/ keeps the small
evaluation outputs and the held-out multi-call set so the eval scripts can
be re-run against a checkpoint you train yourself.
cd src
python3 prepare_data.py --out-dir ../data --model-name Qwen/Qwen2.5-0.5B
python3 train.py --arm baseline --pool ../data/pool_baseline.json \
--model-name Qwen/Qwen2.5-0.5B --out-weights ../data/baseline.pt \
--out-json ../data/baseline_train.json --steps 6000
python3 train.py --arm grounded --pool ../data/pool_grounded.json \
--model-name Qwen/Qwen2.5-0.5B --out-weights ../data/grounded.pt \
--out-json ../data/grounded_train.json --steps 6000
python3 eval_cross_dataset.py --arm grounded --weights ../data/grounded.pt \
--expected-sha256 <sha256 printed by train.py> \
--model-name Qwen/Qwen2.5-0.5B --out ../data/grounded_bfcl.json
python3 eval_heldout_multicall.py --arm grounded --weights ../data/grounded.pt \
--expected-sha256 <sha256 printed by train.py> \
--model-name Qwen/Qwen2.5-0.5B --heldout ../data/heldout_multicall.json \
--out ../data/grounded_multicall.json
Repeat the last two commands with --arm baseline against the baseline
checkpoint for the comparison numbers in the table above.
MIT — see LICENSE. No code inherited from any external project.