Repository navigation
Description
Overview
This is a spike, not an implementation task. The goal is to re-evaluate the agent prompting architecture from first principles and produce a recommendation — not to patch the defects listed below.
An earlier version of this issue prescribed a specific architecture ("safety invariants resident / parameter mechanics in tool schemas / worked examples in skills") before the system had been assessed as a whole. That was premature, and part of it was undercut on review (see Open Questions). The prescription has been removed. What remains is the evidence, which is worth carrying into a fresh evaluation.
The working assumption going in is that this may warrant starting over rather than incrementally repairing the current design. The spike should test that assumption rather than accept it.
Problem Statement
The local agent's guidance is delivered as two Rust string constants concatenated into the system prompt on every turn, with a second, higher-fidelity copy of the same rules reachable only via a retrieval tool. Investigation while fixing the eval assertion (#1799) surfaced defects at four different levels — wire format, duplication, invariant enforcement, and measurement — which together suggest the delivery architecture is the problem rather than any individual rule's wording.
What was verified
Model: gemma-4-e4b-q4km, native llama.cpp, n_ctx 32768, 14 tools, per-turn tool scoping already exists.
1. The resident block does not scale with the registry.
SCHEMA_CREATION_RULES (~602 tokens, packages/agent/src/agent_guidance.rs:20-27) and TOOL_STRATEGY_RULES (~1,692 tokens, agent_guidance.rs:35-58) are concatenated at packages/agent/src/prompt_assembler.rs:290 into one prompt node sent whole every turn — roughly 89% of a ~10,300-char system prompt. Tool definitions scale via the existing scoping step; the prose about them does not. A greeting turn carries the full enum/title-template/field ruleset.
2. Schema mechanics are duplicated across two hand-synced surfaces, and have drifted.
agent_guidance.rs (resident) and packages/agent/src/skill_pipeline.rs:35-113 (retrieved via search_skills, carries two worked JSON examples). The doc comment at agent_guidance.rs:16-19 already flags this and says the skill-path guidance "should be consolidated here when that path is unified."
3. A silent-drop bug where guidance teaches a key serde discards.
agent_guidance.rs:27teaches JSON key"core_values"SchemaField(packages/nodespace-types/src/schema.rs:29-38) is#[serde(rename_all = "camelCase")]— the wire format iscoreValuesCreateSchemaParams(packages/core/src/schema/mod.rs:138) has nodeny_unknown_fields, so the key is silently discarded rather than rejectedvalidate_schema_field(packages/core/src/behaviors/mod.rs:1305-1319) then fails with "Enum field 'status' must have at least one value defined"
A model that follows our guidance exactly produces an error that reads as model incompetence. The skill path (skill_pipeline.rs:70,89) correctly uses coreValues; only the always-resident text carries the bug.
4. Behavioral invariants are enforced by prose, not code.
packages/agent/src/local_agent/agent_loop.rs:597 terminates a turn whenever the model emits zero tool calls. Nothing in code enforces search-then-act; that invariant exists only as resident prose ("READ-THEN-WRITE TURN COMPLETION", agent_guidance.rs:49) written for search_nodes→update_node, not search_skills→create_schema. This may be the most consequential finding: an unknown number of invariants currently depend on asking a small model nicely.
5. Retrieval quality is poor.
Model-formed queries and what came back (default limit=3, threshold 0.0 at packages/core/src/ops/skill_ops.rs:22):
| Query | Matched | Confidence |
|---|---|---|
| "track equipment checkout and return status" | Organization Guidance | 0.74 |
| "track albums I mean to listen to" | Organization Guidance | 0.87 |
| "create schema for venue booking..." | Schema Creation | 1.05 |
6. The eval cannot currently detect a real effect.
Three A/B/C runs (purged DB, rebuilt daemon, skipped=0 verified each time):
| Variant | Score |
|---|---|
A: resident rules only, create_schema called directly |
6/12 |
B: both surfaces + search_skills routing |
3/12 |
| C: resident schema rules removed, routing kept | 5/12 |
In variant B the model called search_skills and stopped, producing permission-seeking prose ("do you want me to create that tracker for us first?") that resident guidance explicitly forbids.
These numbers are suggestive, not conclusive. n=12 scenarios with only 3 exercising schema creation; binomial SD ≈1.5 scenarios (±3 at 95% CI). Three runs of identical code have scored 10/12, 9/12, 8/12. The 6-vs-3 gap is probably real; 6-vs-5 is not.
Open Questions for the Spike
- Layering. Is there a principled rule for what must be resident vs retrieved vs schema-embedded vs code-enforced? The current partition appears accidental.
- Invariants in prose vs code. How many behavioral invariants are enforced only by prose (finding 4)? Which should be structural — loop-enforced, type-enforced, or made unrepresentable? This may matter more than token budgets.
- Duplication. How many surfaces state the same rule (
agent_guidance.rs,skill_pipeline.rs,skill_rules.rs, tool JSON schemas,packages/skill/SKILL.md)? Where does single-source-of-truth break? - Retrieval. Is
search_skillsfit for purpose at current quality? Is ADR-038's retrieval-not-enumeration decision being honored, subverted, or misapplied? - Guards and repair. Is repair-oriented design used where prose prohibition currently is? (
contains_action_claimatagent_loop.rs:165-198intercepts false claims of completed action but not permission-seeking prose.) - Model fit. Is any of this appropriate for an ~8B local model? An earlier review could not verify that a model this size attends to tool-schema
descriptionfields as strongly as system-prompt prose — so "move mechanics into tool schemas" is unproven and must not be assumed. - Stop-after-search cause. Two co-equal unfalsified mechanisms: recency displacement (a multi-KB skill doc becomes the most recent context) vs turn-budget economics (models trained on single-tool-call ReAct traces treat one call as completing the turn). The A/B/C data cannot distinguish them.
- Measurability. Finding 6 suggests instrumentation is a prerequisite for all other work here.
Proposed Approach
Assess before prescribing. Read the prompting subsystem end to end (~9,700 lines: prompt_assembler.rs, agent_guidance.rs, skill_pipeline.rs, skill_rules.rs, agent_loop.rs, tools.rs, prompt_templates.rs, skill_ops.rs, SKILL.md + its generator), plus the ADR chain, then produce a recommendation with the failure modes ranked by impact — explicitly including whether to rebuild rather than repair.
Implementation issues should be filed from the spike's conclusion, not pre-committed here.
Acceptance Criteria
- Written assessment covering each Open Question above, citing
file:line - Failure modes ranked by impact, distinguishing verified findings from hypotheses
- An explicit recommendation on rebuild vs incremental repair, with reasoning
- A measurement design that can detect a 2-scenario effect, given the 10/9/8 noise floor on identical code — including repetitions per variant, the statistic used, and whether the scenario count needs to grow (only 3 of 12 currently exercise schema creation)
- A position on whether prose-enforced invariants (finding 4) should become structural, with the list of invariants currently in that position
- Follow-up implementation issues filed from the conclusion
- Companion
nodespace-docschange identified if the recommendation extends or amends ADR-038
Technical Specifications
Reference Files
- agent_guidance.rs:
packages/agent/src/agent_guidance.rs—SCHEMA_CREATION_RULES(line 20),TOOL_STRATEGY_RULES(line 35), duplication flagged at lines 16-19 - prompt_assembler.rs:
packages/agent/src/prompt_assembler.rs:290— where both constants are concatenated into one seeded prompt node - skill_pipeline.rs:
packages/agent/src/skill_pipeline.rs:35-113— the worked-examples copy - skill_rules.rs:
packages/agent/src/skill_rules.rs— shared rule text interpolated into both surfaces - agent_loop.rs:
packages/agent/src/local_agent/agent_loop.rs:597(turn termination),:165-198(contains_action_claim) - tools.rs:
packages/agent/src/local_agent/tools.rs:630,698—coreValues, the authoritative key - skill_ops.rs:
packages/core/src/ops/skill_ops.rs:22— retrieval threshold and limit - SKILL.md:
packages/skill/SKILL.md+packages/agent/src/bin/gen_skill_md.rs— external-agent surface generated from the same rules - agent-matrix.ts:
scripts/eval/fixtures/agent-matrix.ts— the 12 scenarios - agent-eval.md:
../nodespace-docs/development/agent-eval.md— eval setup
Measurement Note
Guidance lives in compiled-in Rust constants seeded into the DB on first run. Any eval re-run must purge the DB and rebuild the daemon, and verify the log reports skipped=0, or it silently measures the previous text.
Trustworthiness of Existing Results
scripts/results-e4b.json should not be treated as a baseline. Its own caveats document a false pass, a downstream-poisoned scenario, an unexercised code path, and run-to-run variance large enough that the file tells the reader not to trust its headline count. It also predates the assertion fix in #1799, and every run it records was measured through the architecture this spike is questioning.
Architecture Impact
ADR-038 (Accepted) decided "routing must be retrieval, not enumeration," because an enumerated registry "floods the context window, costs tokens on every turn, and degrades small-model selection accuracy as the option count grows."
The resident guidance block is arguably the same anti-pattern one layer up — a fixed-size prose payload about the registry, paid every turn and growing with it. ADR-038 governs which capability to reach, not how to shape arguments once there; argument mechanics are exactly what is duplicated and drifting. Whether the spike's conclusion extends ADR-038, amends it, or requires a new ADR is itself an output of the spike.
ADR-056 (Accepted) locks the native model to Gemma 4 E4B and already records "a truncated turn (search fired, the write did not)" as a known gap — the same failure mode observed in variant B. ADR-056 also notes the measurement caveat that guidance once shared wording with eval prompts.
A companion nodespace-docs change is likely required once the recommendation is settled.
Related Issues
- create_schema succeeds with no fields: agent is routed around the guidance that teaches them, and noExtraTypes cannot see the failure #1799 (fixed the eval assertion that had been hiding these failures; its proposed routing change is variant B above and was not shipped)
- resolve_query must return a resolved node, not query fragments #1637
- Agent re-executes the previous turn's instruction, creating a duplicate node (cross-turn; the per-turn duplicate guard cannot catch it) #1780
Non-Goals
- Changing the locked native model
- Prescribing the target architecture in this issue — that is the spike's output
- Targeting a headline 12/12; the matrix is too noisy run-to-run for that to be meaningful
Activity
malibio commentedon Jul 29, 2026
AI/ML review: the
core_valuesbug is worse than filed, and two of this issue's claims need softeningAn AI/ML review of the findings verified the token figures (~602 / ~1,692, matching the filed numbers) and the delivery mechanism, but corrected the framing in three places.
1. The wire-format bug has a silent-drop root cause
Filed as "teaches a key the API rejects". It is worse — the key is silently discarded, and the resulting error blames the model:
SCHEMA_CREATION_RULES(packages/agent/src/agent_guidance.rs:27) teaches"core_values"SchemaField(packages/nodespace-types/src/schema.rs:29-38) is#[serde(rename_all = "camelCase")]— the wire format is unambiguouslycoreValuesCreateSchemaParams(packages/core/src/schema/mod.rs:138) has nodeny_unknown_fields, socore_valuesis dropped by serde rather than rejectedfield.core_valuesis thenNone, andvalidate_schema_field(packages/core/src/behaviors/mod.rs:1305-1319) fails with "Enum field 'status' must have at least one value defined (in core_values or user_values)"A model that follows our guidance exactly produces an error that reads as model incompetence. The skill path (
skill_pipeline.rs:70,89) correctly usescoreValues, so only the always-resident text carries the bug.This should be fixed and measured on its own, before any architectural work. It is a one-line change, correct regardless of which delivery architecture wins, and it may account for part of the "create_schema succeeded with 0 fields" failure mode attributed here to prompt architecture.
2. "Routing through search_skills is bad" is confounded by retrieval quality
The evidence table shows variant B retrieved Organization Guidance for two of three schema-creation turns. The model may have stopped after
search_skillsnot because of attention/recency effects but because the retrieved document contained nothing actionable.The claim should read: routing is broken given current retrieval quality. Worth testing before concluding otherwise — raise
SKILL_SEARCH_THRESHOLD(packages/core/src/ops/skill_ops.rs:22, currently 0.0) or drop the defaultlimitfrom 3 to 1, which also cuts the size of the tool result suspected of displacing the system prompt.3. Two co-equal mechanisms for stop-after-search, not one
agent_loop.rs:597terminates when the model emits zero tool calls; nothing in code enforces search-then-act (that invariant lives only in resident prose written forsearch_nodes→update_node, notsearch_skills→create_schema).Beyond recency displacement, an equally plausible mechanism is turn-budget economics: models trained largely on single-tool-call ReAct traces treat one call as completing the turn regardless of the result. The A/B/C data cannot distinguish these — both predict the same observable.
4. Caveat on this issue's proposed solution
"Parameter mechanics belong in tool schemas" is not verified for this model class. Whether Gemma 4 E4B attends to
parameters_schema.properties.*.descriptionas strongly as system-prompt prose is unknown without a targeted ablation, and tool schemas sit near the top of context anyway. The defensible framing is "stop contradicting the tool schema" rather than "tool schema descriptions are inherently better attended."5. The measurement design in the acceptance criteria is not sufficient
agent-matrix.tsids) is more honest than comparing raw totals, since scenarios differ in difficulty — theid-based join inscripts/eval/runner.tscompareToBaselineis the natural place to build itUnder this standard the 6/12 vs 3/12 vs 5/12 figures in this issue are suggestive, not conclusive — the 6-vs-3 gap is probably real, 6-vs-5 is not.
Revised order of work
core_values→coreValues; re-measure variant A with repetitions[-]Agent guidance is delivered as one resident prose block that does not scale with the tool registry, contradicts itself, and teaches a key the API rejects[/-][+]Spike: re-evaluate the agent prompting architecture from first principles[/+]malibio commentedon Jul 29, 2026
#1804 filed as input to this spike — with a correction to this issue's earlier framing
A background review filed #1804 while this issue was being converted to a spike. Its Overview says it supersedes this issue's diagnosis; that framing predates the decision to make this a spike. The correct relationship: #1804 is verified evidence feeding this spike, and the strongest candidate for first implementation work once the spike concludes. It does not replace the assessment.
Verified correction to Open Question "Invariants in prose vs code"
This issue's finding 4 implied invariants are prose-enforced generally. That is wrong, and the accurate picture is more useful.
agent_loop.rsalready contains real structural guards:contains_action_claim(agent_loop.rs:165) — converts fabricated success claims into confirmation requestslooks_like_narrated_tool_call(agent_loop.rs:258) — catches tool calls printed as proseTool::write_semanticsA real single-source-of-truth mechanism also already exists between
skill_rules.rsandpackages/skill/SKILL.md, viagen_skill_md.rs:112(--check) enforced by a test at line 154.So the codebase has an established pattern for making invariants structural. Read-then-write turn completion (
agent_guidance.rs:49) is the notable invariant that has not adopted it, and it is the same failure class as fabrication and narration — a plausible-looking turn that didn't do the thing. That reframes the likely fix from "architectural rebuild" toward "reuse an existing guard pattern", which the spike should weigh seriously before concluding a rebuild is warranted.Sharpens an existing caveat
#1804 notes the tool schemas already state
coreValuescorrectly while the resident prose carries the typo. That is evidence the prose string is unreliable — not that tool-schema descriptions are inherently better attended by an ~8B model. This issue already flags that assumption as unproven; this is why it matters.Still open for the spike
#1804 explicitly declines to recommend restructuring resident-vs-retrieved layering, treating registry scaling as a real but separate concern. That remains an open question here, along with retrieval quality, the stop-after-search mechanism, and measurement design.
malibio commentedon Jul 29, 2026
Folded in from #1804 (now closed): verified findings and a better-evidenced fix
#1804 was filed by a background agent after this issue had been converted to a spike. It has been closed and its content folded here, so this spike is the single place this investigation lives. Everything below was independently verified.
The system is more structurally sound than this issue originally implied
Correcting finding 4 ("behavioral invariants are enforced by prose, not code") — that is too broad.
agent_loop.rsalready carries real code-enforced guards:contains_action_claim(agent_loop.rs:165) — converts fabricated success claims into confirmation requestslooks_like_narrated_tool_call(agent_loop.rs:258) — catches tool calls printed as proseTool::write_semanticsA real single-source-of-truth mechanism also exists:
skill_rules.rsrenders bothimperativeandproseforms from one constant, feedingskill_pipeline.rs::schema_creation_guidance()andpackages/skill/SKILL.mdviagen_skill_md.rs:112(--check), enforced by a test at line 154.The accurate statement: this codebase has an established pattern for making invariants structural. Read-then-write turn completion (
agent_guidance.rs:49) is the notable invariant that never adopted it — and it is the same failure class as fabrication and narration (a plausible-looking turn that didn't do the thing). The 6/12 → 3/12 variant-B regression is exactly this: the model treats retrieval as having completed the turn.This meaningfully lowers the odds that a from-scratch rebuild is the right answer, and the spike should weigh it before concluding otherwise.
A better fix for the duplication than this issue proposed
SCHEMA_CREATION_RULESis a third, hand-written copy of rulesskill_rules.rsalready owns (ONE_SCHEMA_PER_REQUESTthroughTITLE_TEMPLATE_PLACEHOLDERS, lines 48-113).ENUM_FORMAT(skill_rules.rs:78) states the enum rule correctly and is already shared with the other two surfaces — verified.So the remedy is not "move parameter mechanics into tool schemas" (this issue's original proposal, now withdrawn). It is: stop hand-writing a second copy of rules
skill_rules.rsalready owns, and renderSCHEMA_CREATION_RULES's field/enum/title-template content from those constants, with a staleness test mirroringgen_skill_md.rs --check. That makes drift impossible by construction rather than a matter of discipline.Resident-only intent-routing rules (
NODE MODEL,"DATABASE" = SCHEMA,INSTANCE vs TYPE) must stay resident — variant C's regression (schema turns calling no tools at all once resident schema rules were removed) is the evidence.Direct evidence against the tool-schema proposal
The tool-schema descriptions for
create_schema/update_schema(tools.rs:597-668,670-748) already carry thetitle_templateplaceholder rule and thecoreValuesenum shape — and they are correct where the resident prose is wrong. That is evidence this one prose string is unreliable, not that schemas are inherently better attended. Relocating a category of rule on an unverified attention-weighting assumption would trade a known-drift-prone location for an unmeasured one.Candidate first implementation work, pending the spike's conclusion
core_values→coreValues(agent_guidance.rs:27) — a plain typo against the wire format, correct independent of everything elseSCHEMA_CREATION_RULESfromskill_rules.rswith a staleness testagent_loop.rsfollowing thecontains_action_claim/looks_like_narrated_tool_callpattern, applied at the zero-tool-calls termination point (agent_loop.rs:597), conservative enough not to false-positive on legitimate read-only turnsNote for implementation:
prompt_assembler.rs:352-383has aseed_prompt_bodies_match_expected_bytestest whose expected-bytes literal will need updating ifSCHEMA_CREATION_RULESchanges shape.Measurement bar
Any PR reporting a matrix score change should use ≥2 runs per variant (purged DB, rebuilt daemon,
skipped=0verified per run) and state explicitly whether the delta clears the documented ~2-scenario noise floor. By that bar the 6-vs-5 comparison in this issue does not clear it; only 6-vs-3 does.malibio commentedon Jul 30, 2026
Spike complete — conclusion and follow-ups
Roughly 600 model generations on the ADR-056 locked model, plus embedding-only retrieval probes. Full assessment and the reference harness are at
~/nodespace/spike-1802-harness/(deliberately not committed).Conclusion: rebuild vs repair
Neither. The right frame turned out not to be "finish ADR-038" either.
Five of the six solid findings are instances of one defect: four channels instruct the model — resident prose, tool schemas, tool results, and the context block — with no doctrine about which owns what. They overlap, contradict, and dilute each other. Two-stage routing does not touch that; building it on top would yield a more expensive version of the same failures.
So: channel doctrine first, ADR-038 completion second. Written up as ADR-064.
The decisive case is in production today: the
create_schematool schema sayscoreValues, the resident prose sayscore_values, both reach the model in the same prompt, the prose wins, and the key is silently discarded. A single-variable natural experiment with a known-correct control.Answers to the open questions
agent_loop.rs. One (READ-THEN-WRITE TURN COMPLETION) is measurably inert: 72/72 continuation with and without it.search_skillsis fit for purpose but starved: descriptions written as keyword lists for a semantic matcher. Rewording took rank-1 from 35% to 75%. Schema retrieval is separately fine (100% recall@5) but ignores conversation history, missing 38% of follow-ups.duplicate_write_resultis the model to follow.Corrections to this issue's premises
0.0retrieval threshold is a reasoned choice under single-gate design, not an oversight. Raising it without Stage-2 would hide the long tail with nothing judging it.Over-claim I want on record
An end-to-end run scored a bundled "proposed stack" at 75% vs 50% for current. One scenario carries the entire gap — schema creation, 0/3 → 3/3 — and that is exactly what the
coreValuesbug breaks. The parsimonious reading is that it measured that one fix. Do not cite the bundled number as justification; each component has independent evidence.Follow-ups filed
coreValues/deny_unknown_fieldsresolve_queryreturns a node (rewritten)Also amended: #1699 absorbs the skill-description rewrite (same function), #1764 rewritten to make the eval diagnostic before recording a baseline.
Highest value-to-effort: #1810 — one call site, recall 77% → 100%. Most under-rated: #1812, because it gates #1699's delivery and removes the purge-before-eval requirement that currently invalidates measurements.
Recommend closing this spike.
malibio commentedon Aug 2, 2026
Closing — the spike concluded 2026-07-30 (see the 'Spike complete — conclusion and follow-ups' comment above) and produced ADR-064, with all ten filed follow-ups (#1809-#1817, #1637, #1699, #1764) closed. This parent issue was never formally closed alongside them. No further action needed here; ADR-064's doctrine and its follow-on work (the ongoing #1917 goal-driven session) supersede this.