Skip to content

feat(decide): typed decisions — the LLM node's decide interface, Laya-ready (schema v30) - #18

Merged
luiscota99 merged 2 commits into
mainfrom
feat/decide-laya
Oct 15, 2026
Merged

luiscota99 merged 2 commits into
mainfrom
feat/decide-laya

Conversation

@luiscota99

Copy link
Copy Markdown
Owner

Summary

The hub spec's LLM node has two interfaces: generate (prose; shipped in #16 on Anthropic) and decide (judgements: choice, score, yes/no). This is the decide half, built so the decision model (Laya) can take over per question without touching callers. Follow-ups are tracked in #17.

What the spec asked for, and where it is

Spec Implementation
Questions are versioned; the interface never changes src/decide.py registry: worth_remembering@v1, test_passes@v1, is_duplicate@v1, route_rung@v1
The audit log is the dataset: input, answer taken, outcome later decisions table (schema v30) + record_outcome(); one decision ledger row per call
Bootstrap on Haiku haiku backend through the shared LLM layer; task=decide resolves to claude-haiku-5-5 under the Anthropic provider
Laya as the decide backend laya backend: Router(default="multilingual", …).predict(state, {name: noul|choice|score spec}, model=…); reads noul / choice / score / probabilities / answer_confidence / low_confidence; any failure falls back to haiku
Policy flips one question at a time, measured, reversible ~/.engram/policy.json pins backend + threshold per question@vN; engram decide policy --set worth_remembering@v1=laya
Joins the request path only under a measured CPU latency engram decide bench reports both backends' p50/p95 and agreement; policy max_latency_ms (300) is the gate
Haiku's answers become the first labels engram decide export writes the JSONL set labelled by outcome when present, else by the answer taken

Consumers wired now: memory_auto_extract screens each candidate with worth_remembering (fail open: no backend, no drops; kept candidates carry decision_id), and the llm_judge grader in skill validation is test_passes.

Verification

  • tests/test_decide.py (19): registry and policy; haiku JSON, bare yes/no and choice parsing; logging and ledger; laya pinned, threshold, choice shape, failure fallback, missing package; outcomes, stats, export; bench; both consumers
  • v30 migration test
  • Full suite 1520 passed in 129 s with zero real LLM calls (the first draft reached the local Ollama through the new path; screening is now opt-in for callers and gated on the availability check tests already patch)
  • ruff clean, pyright 0 errors, Cloak 0 errors, docs/COMMANDS.md regenerated
  • Laya on the VM: install the extra, run bench, confirm the answer-dict keys against the installed version (Decision model (Laya): retraining loop, outcome signals, and the request-path gate #17)

🤖 Generated with Claude Code

luiscota99 and others added 2 commits October 15, 2026 03:12
…-ready (schema v30)

The hub spec splits the LLM node into generate (prose) and decide
(judgements: choice, score, yes/no). This is the decide half, built so
the decision model can be swapped in per question without touching
callers.

- src/decide.py: versioned question registry (worth_remembering@v1,
  test_passes@v1, is_duplicate@v1, route_rung@v1); decide() returns a
  Decision or None (fail open); every call logged to the new `decisions`
  table (input, answer, backend, confidence, latency, later outcome via
  record_outcome) and as a `decision` ledger row; policy file
  (~/.engram/policy.json, ENGRAM_POLICY_PATH) pins backend + threshold
  per question@vN — a pointer change, reversible
- backends: haiku (bootstrap; task=decide → claude-haiku-5-5 under the
  Anthropic provider, ENGRAM_LLM_DECIDE_MODEL overrides; strict-JSON
  prompt, tolerant parse) and laya (Convai Innovations' local decision
  model, optional extra [laya]; Router(default=…, device, models),
  predict(state, {name: noul|choice|score spec}, model=…); reads
  noul/choice/score/probabilities/answer_confidence/low_confidence
  defensively; failure or missing package falls back to haiku)
- consumers: memory_auto_extract screens candidates with
  worth_remembering (screen=True on the MCP/digest path; no backend →
  nothing dropped; kept candidates carry decision_id); skill-validation
  llm_judge grading is test_passes
- CLI: engram decide ask | stats | bench | export | policy | outcome.
  bench re-runs recent inputs on both backends → latency p50/p95 +
  agreement, the measured gate (policy max_latency_ms=300) for promotion
  and for the request path; export writes the JSONL fine-tuning set
  labelled by outcome when present, else by the answer taken
- schema v30 migration + fresh DDL (decisions + 2 indexes)

Tests: tests/test_decide.py (registry/policy, haiku JSON + bare yes/no +
choice parsing, logging + ledger, laya pinned/threshold/choice/failure/
missing, outcomes/stats/export, bench, both consumers), v30 migration.
Existing extraction and validation tests pass unchanged; the full suite
(1520) makes zero real LLM calls (timed, log grepped). ruff clean,
pyright 0 errors, Cloak 0 errors. docs/COMMANDS.md regenerated.

Retraining loop + outcome signals + the VM latency gate: #17.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
`engram decide <id>` already exists — the inbox approval command, the single
proposal→execution path (ADR-0007). Python 3.12's argparse rejects the
duplicate subparser (3.9 silently allowed it, which is why it passed
locally); CI caught it through the docs/COMMANDS.md freshness check.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@luiscota99
luiscota99 merged commit 305ae1c into main Oct 15, 2026
5 checks passed
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