File size: 21,070 Bytes
48f76bc | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 | # Turn decisions: engine, data, and evaluation
The why and the map are in [`docs/decision-engine.md`](../../docs/decision-engine.md); this is the training loop.
At every visible user turn, and at the start of every worker leg, the host
asks a local decision model which units the request needs: which loadable
tool schemas join the call and which instruction units stay out of the prompt.
Skills are ranked when the coordinator requests one through free text. The questions live in
`lycaon/config/packs/painted-wolf/platform/host/decisions.yaml`; the host
side is `lycaon/internal/decide` (engine client), `lycaon/internal/promptunit`
(the unit catalog), and `lycaon/internal/coordinator/turnload` (the decision
and the ledger). This directory holds the engine daemon and the offline
tooling that trains and scores it. Everything here is a bespoke experiment:
it runs outside the verification queue and never during automated tests.
## What is decided, and what happens without an engine
| Unit | Decision | Without an answer |
|---|---|---|
| Loadable tool schema | one logical `multi` question, with each released tool option encoded independently; a tool loads when its P reaches `turn.tools.load_at` | only the floor is offered; `request_tools` loads the rest |
| Instruction unit (`shared/units/*.md`) | one `multi` question per turn, every unit an option; a unit is omitted when its P is below `omit_below` and its certainty reaches `confidence_floor` | every unit renders |
| Turn kind | one `choice` question; a confident `answer_only` vetoes tool loading | no veto |
| `skills_read` text | loaded skills ranked against the text; the best relevant skill is read | word overlap |
| `request_tools` text | loadable schemas ranked against the text | exact names and word overlap |
A joint turn head uses three engine rows: the state is encoded once per row, and
each option is a `[MASK]` marker the head reads on its own. A yes/no
question per option would put the state through the encoder once per option,
about 77 times per turn; the three-row set costs 0.25 s p50 on MLX. Option
texts are the tool name plus `option_words` words of its description,
exported into the corpus so training reads exactly what the host asks. `state.head_tokens` is the
engine's budget for the options; the request text gets what remains.
Each kind defaults to the behaviour the surface has without a model, and the
engine only moves it toward the failure the model can recover from: a
missing tool costs a `request_tools` round trip, an extra instruction costs
bytes. A unit attached to loadable tools follows them and is never scored.
Switched off (`LYCAON_DECIDE_DISABLED=1`), without a binary or checkpoint, or
past its deadline, the engine abstains and every site keeps the surface's own
default: the floor is offered, every loadable tool is listed as requestable
with the same bounded description the engine would have scored, every
instruction unit renders, every skill lists, and nothing is pre-read. That
is the only difference between off and on: on, the head adds likely tools to
the call and omits guides it is confident about; it never removes a tool the
floor offers, and the kind veto ships off (`kind.veto_tools`).
## Engine
The host launches Painted Wolf Decide (`pw-decide`,
`lycaon/internal/decide/native`) as a stdio subprocess speaking line-delimited JSON (`hello`,
`decide`, `rank`). One backbone stays resident and every request names the
head it wants; a head is a small set of weights swapped over the shared
encoder, so turn decisions and ranking share one memory footprint and one
forward path:
| Head | Trained by | Serves |
|---|---|---|
| `turn-load` | `scripts/decide/train.py` | tool and unit decisions, turn kind |
| `unit-rank` | `scripts/decide/train.py --families skills` | skill roster, `skills_read`, and `request_tools` ranking |
| `code-rank` | `scripts/decide/rerank/train_rerank.py` | summarize, repomap, and project-search reranking |
| `web-rank` | web-page pairs | verified web pages and search snippets |
A head is a safetensors file whose header names the backbone it was trained
over (`scripts/decide/headfile.py`); the engine refuses one trained over
another backbone, and a request for a head that did not load answers with the
checkpoint's own. The host resolves `pw-decide` beside its own executable and
the heads staged under `engine-root/decide/heads/<name>.safetensors`;
`LYCAON_DECIDE_HEADS="turn-load=PATH,unit-rank=PATH,code-rank=PATH"` names them outright
and `LYCAON_DECIDE_BINARY` / `LYCAON_DECIDE_MODEL_DIR` point a checkout at a
build and a checkpoint (`./task build:decide`, `pw decide ensure`). A packaged
app resolves the checkpoint `stage-engine.sh` bundles under
`engine-root/decide/models/`.
`LYCAON_DECIDE_DISABLED=1` switches the engine off; every decision then falls
back as the table above says.
On Apple silicon the engine runs the model on Apple's MLX (`--device mlx`,
what `auto` picks there): candle's Metal backend costs about five times more
per row, and the MLX port in `native/src/mlx.rs` mirrors the candle port op
for op, which its parity test checks on a tiny checkpoint. MLX's kernels
ship as `engine-root/decide/mlx.metallib` (about 136 MB, the framework's
whole kernel library); the host passes that path as `--metallib`, and the
engine also finds a copy beside its own executable. Building the engine on a
Mac compiles MLX from source once (CMake, network for the framework
checkout, and Xcode's Metal toolchain: `xcodebuild -downloadComponent
MetalToolchain` when the build says it cannot execute `metal`). The engine
caps MLX's allocator cache at 512 MB when it loads: every request has its own
batch size and sequence length, so an uncapped cache keeps growing toward the
GPU's working set (20 GB was measured on a rerank eval), and a resident
sidecar must not do that to the machine. With the cap the same eval holds
the engine at about 1.5 GB.
Heads are training artifacts. The shared release manifest,
`lycaon/config/packs/painted-wolf/platform/host/decision-release.json`, pins
their hashes, labels, backbone, and initial-preload option vocabulary. A
development checkout installs the matching set under
`<artifact bin>/decide-heads/<name>.safetensors`
(`python3 scripts/artifact_paths.py bin .` prints the directory; names are
`turn-load`, `unit-rank`, `code-rank`, `web-rank`), and every `build:lycaon-dev` stages
them into the engine root that `den:sidecar` and `den:app` run against.
Missing or mismatched required heads fail staging. The host intersects the
release vocabulary with permitted tools; new tools remain requestable without
changing the preloader's encoded options. Refresh the vocabulary and evaluate it
with its head before releasing it. The factory's `release_manifest.py` rebuilds
the manifest from the selected artifacts and their evaluated corpus.
Python is training-side only. `parity_probe.py --model ID --head FILE
--examples FILE --engine <launcher>` scores turns through the trainer's own
forward and through `pw-decide`. Report the actual probability gaps and
threshold crossings for the loaded heads; metadata compatibility alone does
not establish numerical parity, and agreement is not a model-quality test.
The training environment:
```bash
python3 -m venv .venv-decide && .venv-decide/bin/pip install laya
```
## Backbone
Laya ships two backbones with different head shapes, so a head only fits the
backbone it was trained on:
| `LYCAON_DECIDE_MODEL_ID` | Backbone | Hidden | Context |
|---|---|---|---|
| `convaiinnovations/laya` | ModernBERT-large, English vocabulary | 1024 | 512 |
| `convaiinnovations/laya-multilingual` | mmBERT-base, 100+ languages | 768 | 1024 |
The backbone is one choice for every head: the heads share the encoder, so
the replay eval here and the rerank eval must agree on it before either
ships. The shipped backbone is `convaiinnovations/laya-multilingual`: on the
same turn data it scored no worse than the English checkpoint and ran the
turn set in 0.81 s against 1.32 s p50 on candle Metal. Changing it means
training the turn-load head and running the replay eval under each id on the
held-out captures.
## Corpus
The host exports the corpus the decision scores; nothing here parses packs:
Artifacts live in the checkout's resolved build directory, never under the
checkout itself; every command below uses that directory as `$DECIDE`:
```bash
DECIDE="$(python3 scripts/artifact_paths.py build .)/decide"
BUILD_ONLY=true ./task eval:tool-usage # builds lycaon-debug; or LYCAON_DEBUG_BINARY=... pointing at one
scripts/decide/corpus.py --out "$DECIDE/corpus.json"
```
`corpus.json` carries every coordinator surface's floor, loadable tools, and
scored units; every tool's option text and request card; every unit and
skill card; the question templates; and the catalog revision that receipts
record. Third-party packs contribute units through the same catalog, so the
corpus is whatever the effective catalog resolves to.
## Data
Every decided turn leaves a receipt, including a turn whose engine was off or
abstained, and `lycaon-debug decide export` is the one reader that turns
receipts into training rows (`pw-decide-row/1`, described by
[`row.schema.json`](row.schema.json) and loaded through `rows.py`). A row is
the state the engine read, verbatim; the candidates the turn offered
(`offered`); what the engine answered (`engine`); and what the session then
did (`labels`). Coordinator turns and worker legs export alike: a worker
leg's receipt names its tool profile as the surface and its coordinator
session as `root_session`.
```bash
lycaon-debug decide export --db <store.db> --out rows.jsonl [--roots roots.txt]
```
Labels are always the host's own vocabulary and come from what the session
actually did: the offered loadable tools it called, the ones it asked for by
name, each `request_tools` need with the names it spelled out and the tools
it went on to call, the skills it read, and the kind those calls imply
(`turnload.ObservedKind`). A scored instruction unit attached to tools is
needed exactly when one of them was called; an unattached unit has no
behavioural label (`turnload.GuideLabels`). A turn that did not complete
keeps only its needs.
A tool a session called is weak evidence that the request needed it: driving
models call tools out of habit, and a head trained on calls learns which
tools are common rather than which a request needs. When judges have scored
the turn's loadable tools against its request (`labels.tool_scores`, and a
second judge's `labels.second_scores`), a tool is needed when both judges
scored it likely or certain, unneeded when both scored it at most unlikely,
and unlabelled otherwise, so the head never trains on a call two judges
disagree about; a tool the model asked for by name is always needed. A card
only one judge scored is unlabelled. Skill and need levels are the two
judges' mean, except that by default (`--rank-levels blended`) the skill a
turn read first and the tools used after a need train at the top level
whatever the judges scored them; `--rank-levels skills-blended` keeps the
override for skill reads only, and `--rank-levels judged` drops it. `--tool-truth` on the trainer,
calibration, and replay chooses the rule (`rows.TOOL_TRUTH`); rows without
tool scores fall back to the called tools.
A row whose `engine.state` is `answered` carried what the engine chose, so a
tool the engine preloaded and the session then called is not an independent
label: the turn families train on the rows the engine did not answer, and
under a live engine a turn's needs are exactly the tools it missed, which is
what the rank head ranks in production.
Open training data comes from the dataset factory, `paintedwolf-decide`: it
drives sessions with open-weights models in sandboxed runners against pinned
public repositories (through `lycaon-debug decide generate`, which drives a
JSON-lines task file through one sidecar and records a manifest), exports
their receipts, has an open-weights judge of another family score skill and
tool cards 0..4, and splits by repository and prompt group. Rows from your
own stores export the same way and train the same way; they stay on the
machine that exported them.
Generation tasks that select a workflow provide both `workflow` and
`workflow_version`. The runner verifies that exact catalog identity before
creating task sessions and records it in each result manifest; it does not
select a version implicitly. Omit both fields for ordinary chat tasks.
For example, `{"id":"review","prompt":"Review this change","workflow":"implement","workflow_version":"1.0.0"}` pins that definition.
## Train, calibrate, evaluate
Hold out whole packs and whole repositories: units from `--holdout-pack` stay
out of the guide labels so the eval measures generalization to units the
head never saw (what lets extensions ship their own units without
retraining), and the factory holds out every row of its held-out
repositories. The rest splits by prompt group, so the validation set is
prompts the head never trained on.
```bash
# turn-load answers the turn questions; unit-rank ranks skill and tool cards.
# The rank pairs are kept out of turn-load because they outnumber its rows and
# pull the shared weights. On a GPU host, set LYCAON_DECIDE_DEVICE=cuda.
scripts/decide/train.py --corpus corpus.json --train train.jsonl --val val.jsonl --holdout-pack painted-wolf/browser \
--families tools,guides,kind --tool-weight sqrt-inverse --seed 11 --out heads/turn-load.safetensors
scripts/decide/train.py --corpus corpus.json --train train.jsonl --val val.jsonl \
--families skills,requests --skill-scored 4 --skill-zeros 3 --out heads/unit-rank.safetensors
# Replay through the shipped engine, calibrate the thresholds, and time the turn set.
# The launcher execs: pw-decide serve --model <checkpoint dir> --model-id <id> --device mlx
# --head-max-len <state.head_tokens> --head turn-load=<head> --head unit-rank=<head>
export LYCAON_DECIDE_ENGINE=<launcher>
scripts/decide/replay_eval.py --corpus corpus.json --examples holdout.jsonl --holdout-pack painted-wolf/browser --json replay-holdout.json
scripts/decide/calibrate.py --corpus corpus.json --examples val.jsonl
scripts/decide/bench_latency.py --corpus corpus.json
```
The launcher runs the same binary with the same arguments the host uses, so
the replay measures the shipped engine; `parity_probe.py` cross-checks a
head against the trainer's own forward.
`train.py` precomputes the frozen backbone's features once and trains the
head for up to sixty epochs, stopping after twelve without a better
selection loss: the validation loss of tools and guides, the families that
change what a turn carries. Kind is trained and reported but does not pick
the checkpoint; its loss swings enough to stop a run before the tools head
has learned anything. The trainer reports precision and recall per family,
and per host for coordinator turns and worker legs, rather than one pooled
number, because the guide rows carry many always-true units that would hide
an unlearned tools head. Option sets come from each row's `offered`
candidates and option texts from the corpus, choice labels index options in
the engine's order (sorted by name), and skill pairs use the corpus's cards,
so the head sees at training exactly what it answers at the turn.
`--tool-weight sqrt-inverse` weighs each tool's positives by
sqrt(N / (n + 1)), clamped to [1, 20], so a tool few turns use still pulls
the head. Check a new head with the trainer's own forward before blaming the
engine: `pw-decide` matches it to the fourth decimal.
`replay_eval.py` reports tool load precision and recall (micro, and macro
over tools), loads per turn, guide omission precision and recall, kind
accuracy, skill top-1 and the share of turns whose first-read skill the
pruned roster listed, against judged skill scores the preload precision and
the share of turns whose roster lists a relevant skill, need ranking, bytes
saved per turn, the share of requests cut at `user_text_chars`, and engine
latency; overall and by host, surface, language, project, and the model that
drove the session, and for the held-out packs.
`calibrate.py` also reports the tool threshold each host would choose alone.
`bench_latency.py` measures the full turn question set on this machine,
which is the number the `deadline_ms` budget must respect.
A head ships when it beats the engine-off default on the held-out sets and
is at least as good as the shipped head on every set both can be scored on.
Off, no loadable tool is preloaded and every guide renders, so any tool
recall saves round trips, while a wrongly omitted guide costs the turn;
guide omission therefore turns on only when its precision on the held-out
repositories reaches 0.97. The rest are targets the shipped head reports
against: tool recall ≥ 0.9 (a missed tool costs a `request_tools` round
trip, so recall outranks precision), skill top-1 ≥ 0.7, first-read skill
listed ≥ 0.95, bytes saved ≥ 30% on investigate turns. On the generated
sessions a turn averages 11.8 coordinator calls of 7.5 s and 0.46
`request_tools` round trips, so the engine pays for itself once it avoids
about a quarter of them. The latency budget is the catalog's `deadline_ms`,
5 s for turn, request, lookup, and tool-event decisions: the decision runs once before
the turn's first model call, and one avoided round trip pays for many seconds
of it, so accuracy is the binding bar, not the engine's wall time.
## Author probe
`lycaon-debug decide probe --request "..." --surface implement_investigate`
runs the turn decision through the engine resolved from the environment and
prints what it would load and omit, so a pack author can see whether their
unit's description loads for the requests they intend.
## Shipped heads: B5 tools, B7G guides, E4 skills, open1 code
The release manifest pins four heads over the open1 dataset: B5 `turn-load`
for tools, B7G `guide-load` for guides, E4-dense1 `unit-rank` for skills and
needs, and open1 `code-rank`. The host asks the guides question of the guide
head when the release ships one and of `turn-load` otherwise.
B5 encodes each tool independently: consensus labels, 24 inverse-weighted
sampled negatives per turn, no rare-tool weighting or augmentation, learning
rate 5e-4, seed 11, batch 64, a 45-epoch cap. On validation it scores
0.822 precision and 0.291 recall at 0.95 with 0.308 preloads per turn; the
shipped cutoff is 0.85 (`decisions.yaml`), which on recorded sessions loads
five times as often at the same precision. Diagnostic requests outside
training show that initial prediction still misses useful tools; `request_tools`
covers the rest, with coverage 92.4% and top-1 77.7% at 2.59 loads per need
on the recorded validation check.
E4 uses two-judge labels and a seeded half-family augmentation mix. On 789
acceptance requests, 660 with a consensus-relevant skill, a relevant skill
was visible in the first six for 92.1%, and automatic preloads were relevant
in 122 of 123 cases; common-skill visibility is 87.9%, rare-skill 80.4%.
Stage the head set with `PW_DECIDE_HEADS_DIR` when building a checkout; the
build verifies it against the committed release manifest.
The committed release manifest binds its exact weights and option texts.
## Guide omission: B7
B7 trains the B5 recipe with `--families tools,guides`: every tool and every
guide option on its own row. Guide labels are relabelled from tool calls
before training: a unit was needed when its turn called a tool it `attaches`
to or one it is `needed_with`. `claim-evidence` and `survey-first-pass` carry
labels for the first time; earlier releases left them unknown, so no audit
could certify them.
The host only omits ids listed in `turn.guides.omittable`; an empty list
retains every guide. `train-host/guide_audit.py` certifies a unit at 97%
omission precision and 98% needed-guide retention on validation and on the
held-out repositories, and never from an unknown label. Keep that report with
the installed head and thresholds; replays enforce the same list.
Guides-only control (B7G, `--families guides`, 21 epochs, patience stop),
scored with `train-host/turn_probe.py` on the relabelled rows:
| Unit | Holdout omissions | Unneeded | Needed retention |
|---|---|---|---|
| native-summarize-tool | 47 of 674 | 100% | 100% |
| native-find-tool | 6 of 674 | 100% | 100% |
| claim-evidence | 93 of 680 | 97.8% | 97.8% |
| native-recall-tool | 640 of 680 | 98.1% | 25% (16 positives) |
| survey-first-pass | 0 of 680 | | |
Certified at `omit_below` 0.15: `native-summarize-tool`, `native-find-tool`.
`claim-evidence` misses retention by 0.2 points on holdout and precision on
validation (92.8%); `native-recall-tool` omits almost always and misses the
few turns that called it. Labels are observational: a unit whose tool is
rarely called has few positives, so retention swings on a handful of turns.
The shipped list and any decision past the audit are recorded in
`decisions.yaml` beside the numbers.
|