Repository navigation
Closed
Labels
Description
Overview
When the local agent routes a turn to skills, each candidate's schema_metadata tells the model which types it may use. After #3418, a skill's applies_to links make that set deterministic: the skill's linked schemas plus their subtypes. But nothing holds the model to the set. This issue makes the offered set binding for the tools that reference an existing type. The set goes into the tool parameter schema as an enum, and dispatch refuses a type that is not on it.
Problem Statement
- The routed prompt renders each eligible candidate's
schema_metadataunder the shared "EXISTING SCHEMAS" heading (packages/agent/src/local_agent/routing.rs).decisions::schema_candidatesrecords that set as what the model was shown. - The code itself documents the gap (
packages/agent/src/local_agent/decisions.rs,DecisionRecord::selected_off_menu): "nothing constrains anode_typeargument to a retrieved candidate, so the model can and does name a type that was never on offer." - The grammar cannot close it on the locked model. ADR-056 records that llama.cpp's
json-schema-to-grammarconstrains only Gemma 4's outer tool-call envelope, not the argument body. Anenumin the tool schema is therefore an instruction, not a hard constraint, on Gemma 4 E4B. - ADR-064 measured the tool-schema channel at 100% compliance for a constraint stated only there, against 87.5% for resident prose. So the tool schema is the right channel for the set, and a dispatch-side check is what makes it binding.
Proposed Solution
- The offered set for a routed turn is the deduplicated union of every eligible tool-bearing candidate's linked schemas (from Seed built-ins from fixed-UUID tables with Markdown bodies, order agent guidance, and link skills to their schemas #3418's
applies_to) and theirextendssubtypes.- The set exists only when every eligible tool-bearing candidate is linked.
- If any candidate uses the unlinked fallback (the type the query names, or the first five), or the turn is unrouted, there is no set and nothing changes from today.
- Put the set in the tool schema. For a turn that has a set, the per-turn
ToolDefinitions of the tools that reference an existing type getenum: [<set>]on their type parameter. Today those tools arecreate_node,update_node,update_schema,search_nodesandresolve_query: theschema_scopedtools indecisions.rs, exceptcreate_schema, whose type is new by definition. Derive the list from theToolenum, likeschema_scoped, so a new tool forces a decision. - Refuse an off-menu type at dispatch. In a turn with a set, a call whose type argument is not in it is not executed. It returns a tool-result error that names the allowed type ids, so the model can retry or call
route_clarify. ADR-064 assigns errors to the tool-results channel. - Record it. The decision record shows whether the set was enforced, so
selected_off_menucan tell an enforced turn from an unconstrained one.
Architecture Impact
- ADR-038 (
decisions/038-skill-mediated-tool-routing.md) defines skill-mediated routing,schema_metadataand the "EXISTING SCHEMAS" injection. Its 2026-09-17 amendment covers schema discovery. This issue extends it: a routed turn's schema set becomes binding. Companion docs change: add an amendment to ADR-038 describing the offered set, when it applies, and the dispatch refusal. - ADR-064 (
decisions/064-instruction-channel-doctrine.md): consistent. Enum membership belongs in tool schemas (§1), and the refusal is a tool result. - ADR-056 (
decisions/056-gemma-4-e4b-locked-native-model.md): the reason dispatch must enforce the set. The engine grammar does not constrain argument bodies on Gemma 4. architecture/prompt-skill-system.md: rewritten by Seed built-ins from fixed-UUID tables with Markdown bodies, order agent guidance, and link skills to their schemas #3418. Add the offered set to that rewrite, or update it here if Seed built-ins from fixed-UUID tables with Markdown bodies, order agent guidance, and link skills to their schemas #3418 has landed.- ADR-038 "Generated schemas are validated": the per-turn enum is bounded by the candidate set, so it adds no unbounded schema.
Acceptance Criteria
- A routed turn whose eligible tool-bearing candidates are all linked computes the offered set: the union of linked schemas plus
extendssubtypes, deduplicated (unit test) — as built: the set is every type the candidate block lists, so it also includes the type of a schema-typed hit - A turn with any unlinked tool-bearing candidate, or no routing, has no offered set, and its tool schemas and dispatch are unchanged from today (test)
- For a turn with a set, the type parameter of
create_node,update_node,update_schema,search_nodesandresolve_querycarriesenum= the set;create_schemanever does; the tool list is derived from theToolenum (tests) — as built:node_typeoncreate_node,search_nodesandresolve_query,schema_idonupdate_schema;update_nodetakes a node id, has no type parameter and is not held - An off-menu type in a turn with a set is not executed, and the tool result names the allowed ids (test per tool)
- The decision record shows whether the set was enforced
-
eval:decisionson the locked model, before and after: off-menu selections for linked turns drop to zero executed, and no regression in operation accuracy; results posted on this issue - Prompt golden regenerated (
UPDATE_GOLDEN=1) and the diff reviewed - The ADR-038 amendment is committed to nodespace-docs
-
bun run test:changedpasses;bun run quality:fixclean
Technical Specifications
Reference Files
- Routing and rendering:
packages/agent/src/local_agent/routing.rs(Stage-2 candidate block,render_schema_metadata,stage2_permitted_names) - Decision record:
packages/agent/src/local_agent/decisions.rs(schema_candidates,selected_schema,schema_scoped,DecisionRecord::selected_off_menu) - Turn loop and dispatch:
packages/agent/src/local_agent/agent_loop.rs(tool surface per turn, decision recording) - Tool definitions:
packages/agent/src/local_agent/tools.rs - Schema metadata source:
packages/core/src/ops/skill_ops.rs(find_skills, as changed by Seed built-ins from fixed-UUID tables with Markdown bodies, order agent guidance, and link skills to their schemas #3418)
Implementation Notes
- Read the set from the same
schema_metadatathe prompt renders, asschema_candidatesdoes, so the enforced set is the set the model was shown. - Tool definitions are built per turn here. Check that per-turn enum changes do not defeat prompt-prefix reuse in the inference engine, and say so on the issue if they do.
- Model-facing changes fail
prompt_assembly_snapshot; regenerate withUPDATE_GOLDEN=1. - Check the eval fixture's age before an eval run.
Dependencies
- Seed built-ins from fixed-UUID tables with Markdown bodies, order agent guidance, and link skills to their schemas #3418 (adds the
applies_tolinks that make the set deterministic)
Non-Goals
- Constraining
create_schema's type, or any turn without a linked set - Changes to Stage-1 routing or skill retrieval scoring
Activity
malibio commentedon Oct 2, 2026
Baseline on d9f8974 — Frontend: 309 test files passed, 5606 tests passed
malibio commentedon Oct 2, 2026
eval:decisionson the locked model, before and after (PR #3497)Setup.
gemma-4-e4b-q4km, 32,768-token window, one rep each, each on a purged database. Both runs use the fixture and scripts at cf28c4e.enforced, and this branch's parser drops a decision record without it.The twelve existing scenarios: no change
Every scenario gave the same verdict and the same first tool call in both runs.
schema-on-menu-company,declarative-fact-report-resolvedBoth failures are unrelated to this change and identical in both runs (a
create_nodesent without its type, and acreate_relationshipon a fact report). None of these twelve turns is held, since they route to built-in skills, which link to no schema.The two linked-skill scenarios
These are new. Their group seeds a
warranty_claimtype and three skills linked to it throughapplies_to. In both runs retrieval returned the three linked skills and thewarranty_claimschema hit, so the "after" turn was held towarranty_claim.held-on-menu-type: "File a warranty claim for the Aurora blender…"create_nodeonwarranty_claimwith three fields. Passed.held-off-menu-type: "…add a task to ring the buyer back on Friday."tasktwice. Bothcreate_nodecalls reached the executor. They failed on an unrelated field-validation error, so nothing was written, but nothing stopped them for their type.warranty_claim, then asked the user what to do. No call named an off-menu type, no record was created. Passed.Off-menu calls that reached the executor on the linked turn: 2 before, 0 after.
What this does and does not show
enumand the held description in place, the model did not nametaskthis time. In an earlier trial of the same scenario on this branch (before the refusal's wording was revised) it did nametask, dispatch refused the call with the allowed ids, and the turn ended without a write. So both paths have been seen on the model, but in different runs.off_menu_ranon theTool executedlog line). It confirms the guard was in force on every call of the run. It would not detect the guard and an executor disagreeing about which argument names the type; they agree today.selected_schemanow readsschema_idforupdate_schema. No scenario in this fixture callsupdate_schema, so no count moved for that reason.Prompt-prefix reuse
Per-turn
enums do not add a new divergence point. Tool definitions were already rebuilt per turn (declare_write_tool_fieldsdeclaresfield_valuesfrom the retrieved schemas), and the Stage-2 prompt already diverges from Stage 1 at the candidate block.One decision left with the issue owner
A held turn refuses a core type the request names (
task,text) unless a skill links to it, because a core type never reaches the candidate block as a schema hit. In the scenario above that is what makes "add a task…" end in a question to the user. It is recorded as a consequence in the ADR-038 amendment. If that is not the behaviour wanted, the options are to offer core types on a held turn, or to leave the turn open when the request names one.Hold a routed turn's type arguments to the schemas its skills link to (…
Hold a routed turn's type arguments to the schemas its skills link to (…