Repository navigation
Unify agent guidance into single source of truth (#1089) - #1129
Conversation
Extracts the search-first, schema creation, and node reference rules from packages/agent/src/prompt_assembler.rs into a new packages/agent/src/agent_guidance.rs module exporting three pub const strings: SCHEMA_CREATION_RULES, SEARCH_FIRST_RULES, NODE_REFERENCE_FORMAT. Both consumers now derive their guidance from this module: - prompt_assembler.rs composes the Tool Strategy Guide and Response Formatting Rules seed bodies from the shared constants (byte-equivalent to the previous inline strings) - context_assembly.rs imports the constants and exposes a new agent_guidance_section() helper for ADR-032 callers writing CLAUDE.md / AGENTS.md files Adds unit tests in both files asserting the section composes from the shared constants, so future edits to a constant propagate to both the local Ollama agent and PTY agent sessions automatically. Acceptance criteria: - [x] Shared guidance rules exist in exactly one place - [x] PromptAssembler derives guidance from agent_guidance.rs - [x] context_assembly.rs derives guidance from agent_guidance.rs - [x] Editing a rule propagates to both consumers - [x] bun run test:all passes (3918 frontend + 1182 rust, 0 failures) - [x] bun run quality:fix clean Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
malibio
left a comment
There was a problem hiding this comment.
Code Review Summary
Clean, well-scoped refactor. The PR does exactly what #1089 asks: pulls the three rule strings out of prompt_assembler.rs into a single agent_guidance.rs module and rewires both consumers to import from it. Byte-equivalence of the seeded prompts is preserved, tests pass, clippy is clean on nodespace-agent. Net positive.
I independently re-verified the byte-equivalence claim with a standalone rustc harness reproducing seed_prompt_nodes()'s string construction on both branches — Tool Strategy Guide and Response Formatting Rules outputs match exactly. So the runtime behavior of the local Ollama agent is unchanged by this PR.
A few items below worth addressing or at least acknowledging before merge — none are blockers.
Findings
Critical Issues
None.
Suggested Improvements
[Improvement] packages/agent/src/prompt_assembler.rs (or agent_guidance.rs): no in-tree byte-equivalence regression test.
You verified the strings match externally with a one-off harness — fine for this PR. The risk is that the next edit to either SEARCH_FIRST_RULES or the format!() glue in the seed bodies silently diverges from the previously-shipped prompt, and the only signal will be agent behavior changes (which we don't gate on in CI). The existing seed_prompts_have_valid_properties test only checks non-emptiness.
Cheap mitigation: a single #[test] in prompt_assembler.rs that snapshots the Tool Strategy Guide and Response Formatting Rules markdown_content against a small fixture string (or insta snapshot). One assertion per seed; ~15 lines total. Whether this is worth the maintenance cost is a judgment call — these strings change deliberately and rarely. I lean "yes, add it" because the rest of the PR took such care to preserve byte-equivalence; without a regression test, that property has no teeth. Calling out per your explicit ask: it is not overkill, but reasonable people could disagree, so flagging rather than blocking.
[Improvement] Naming: SEARCH_FIRST_RULES is a misnomer for its current contents.
The constant contains the full "TOOL STRATEGY" bulleted block, which includes schema-creation bullets like - To create a new entity type: use create_schema..., - To modify an existing entity type: use update_schema..., and creation/relationship guidance. These are not "search first" rules. The constant's doc comment acknowledges this ("Also covers ... canonical create_node / create_schema / create_relationship usage patterns"), but the name will mislead future readers grepping for where create_schema guidance lives.
Two options:
- Rename to
TOOL_STRATEGY_RULES— matches the prompt header text and the actual contents. - Split further: pull the schema-creation bullets out into
SCHEMA_CREATION_RULES(so the constant lives up to its name) and leave search/get/update guidance inSEARCH_FIRST_RULES.
Option 1 is the lower-cost fix and I'd prefer it for this PR. Option 2 is what the issue's table implied ("Schema creation" as a distinct unit of overlap) but is more invasive — could be a follow-up. As-is, the separation in the issue's mental model doesn't match the separation in the code.
[Improvement] Third copy of these rules in packages/agent/src/local_agent/prompt_templates.rs::fallback_system_prompt() is not unified.
fallback_system_prompt() contains an abbreviated copy of TOOL STRATEGY (lines 33–42) and a verbatim copy of RESPONSE RULES (lines 43–53), including the nodespace://abc-123 bare-URI rule. It is actively called from local_agent/agent_loop.rs:135 whenever PromptAssembler is not wired in.
Acceptance criterion #1 of #1089 says "Shared guidance rules exist in exactly one place." Strictly read, this PR doesn't satisfy that — it satisfies the narrower table in the issue body, which lists only prompt_assembler.rs and context_assembly.rs. Two reasonable resolutions:
- (a) Have
fallback_system_prompt()also format from the same constants. The fallback is intentionally terser, so it would need either a smallerSEARCH_FIRST_RULES_TERSEconstant or some structural rework. Probably not worth it for code that exists to handle a path the doc comment describes as transitional. - (b) Update the doc on
fallback_system_promptto call out that its rule text is intentionally a duplicate, and file a follow-up to delete it oncePromptAssembleris always wired in. This matches the existing intent ("only for use whenPromptAssembleris not available") and is honest about the duplication.
I'd take (b). Either way, this should be acknowledged in the PR description or a follow-up issue, not silently shipped.
[Improvement] PR description claim "queued for #1088" is inaccurate.
#1088 is Schema field rename with property data migration — adding a rename_fields parameter to update_schema. It has nothing to do with the title_template token/field alignment rules the #1089 issue body called out. Two related but separate observations:
- The
title_templatealignment guidance already exists inpackages/agent/src/skill_pipeline.rslines 287–329 (a different prompt path used for skill-based schema creation). So the issue's claim that "these rules exist in both [prompt_assembler.rs and context_assembly.rs]" is itself slightly off — they live inskill_pipeline.rsonly, not inprompt_assembler.rs. This is the reason the PR could correctly say "they're not in the seeded prompts today." - It would be more accurate to either (i) drop the "#1088 will land them" line from the PR description and the doc comment on
SCHEMA_CREATION_RULES(which carries the same claim), or (ii) file a separate issue tracking the unification ofskill_pipeline.rs's schema-creation rules intoSCHEMA_CREATION_RULES. Right nowSCHEMA_CREATION_RULES's doc comment promises future content that isn't tracked anywhere actionable.
[Improvement] agent_guidance_section() is dead code on main until ADR-032 lands.
Because the function is pub, the compiler will not warn — that's correct Rust semantics, not a problem. The concern is more architectural: we're shipping a public API contract (signature, return shape, the markdown block format ### Agent Guidance\n\n{schema}\n\n{search}\n\n{node_ref}\n) with no consumer to validate the shape. If ADR-032's writer wants a different structure (e.g., separate ### Schema Rules, ### Tool Strategy, ### Node References sections, or no section headers at all because the consumer wraps them), we've prematurely locked in a format.
Two acceptable paths:
- Land the constants only; defer
agent_guidance_section()to the ADR-032 PR where its shape will be validated against a real consumer. This is the YAGNI-aligned move. - Keep the helper as a suggested default but make the section format trivial enough that the caller doesn't depend on it — i.e., expose only the constants and let the ADR-032 writer compose them however it needs. The two new tests would move to
agent_guidance.rs(already there for the constants) and the section-composition helper would live next to the ADR-032 code.
Given the project's stated "no speculative API" stance (CLAUDE.md: NO backward compatibility, KISS, YAGNI), I'd lean (1). The cost of recreating this 5-line helper later is essentially zero; the cost of having ADR-032 inherit a format choice it didn't make is nonzero.
Nitpicks
- Nit:
packages/agent/src/lib.rs:17-19— module ordering is non-alphabetical and slightly inconsistent (agent_guidancecomes afterprompt_assemblereven though prompt_assembler depends on it). Not a correctness issue, but a reader scanning the lib root would expect leaf dependencies above their consumers. Small reorder:agent_guidancebeforeprompt_assembler. - Nit:
packages/agent/src/agent_guidance.rs:17— the entireSCHEMA_CREATION_RULESconstant is a single line that wraps off-screen in most editors. Rust supports\line continuations in string literals (you use them elsewhere in the file) — consider splitting at sentence boundaries for readability. The byte content stays identical. - Nit:
packages/agent/src/acp/context_assembly.rs:945-946— the assertionsection.contains("ALWAYS search first")does double duty withtest_agent_guidance_section_uses_shared_constants. Since the second test already assertssection.contains(SEARCH_FIRST_RULES)(which contains "ALWAYS search first" by definition), the granular anchor assertions in the first test are slightly redundant. Not a problem — leaving them gives nicer failure messages — but worth knowing they're not load-bearing. - Nit:
packages/core/src/mcp/handlers/schema.rs— drive-by trailing-blank-line removal is unrelated to #1089. Defensible because it's a trivial rustfmt cleanup, but per the "atomic commits" guideline this kind of thing ideally goes in a separate commit (even within the same PR). Not worth holding the PR.
Verdict
This is a clean refactor that achieves the structural goal of #1089 for the two paths the issue's table explicitly named. I'd merge after at least the naming concern (SEARCH_FIRST_RULES rename or schema-bullet split) and the agent_guidance_section() decision are addressed — both are small. The byte-equivalence test and the prompt_templates.rs follow-up can be follow-ups; flag them in a comment on #1089 or open a tracking issue.
Reviewed by /pragmatic-code-review.
- Rename SEARCH_FIRST_RULES → TOOL_STRATEGY_RULES so the constant matches its actual contents (the full TOOL STRATEGY block, including schema and relationship bullets). - Remove the speculative pub fn agent_guidance_section() helper and its two tests from context_assembly.rs. The constants are exposed; ADR-032 will compose its own section format when its real consumer lands. Avoids prematurely locking a markdown shape with no caller to validate it. - Add seed_prompt_bodies_match_expected_bytes regression test in prompt_assembler.rs that locks in the exact bytes of the Tool Strategy Guide and Response Formatting Rules seed bodies. Catches accidental drift from edits to agent_guidance.rs constants or the format!() glue. - Document the intentional rule duplication in fallback_system_prompt() so future readers know it should collapse into the agent_guidance path once PromptAssembler is universally wired. - Drop the misleading "queued for #1088" claim from SCHEMA_CREATION_RULES doc and point readers at skill_pipeline.rs where the title_template guidance actually lives today. - Reorder lib.rs modules so agent_guidance (a leaf dep) precedes its consumer prompt_assembler. Tests: bun run test:all green (3918 frontend + 1182 rust, 0 failures). quality:fix clean. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Review feedback addressedPushed commit
Test status
Acceptance criteria status
Re-review decisionNO RE-REVIEW NEEDED. Changes are scoped exactly to the reviewer's recommendations — a rename, a deletion of speculative API, a new regression test, and three doc edits. No new architectural moves and no new functionality. The PR is ready for merge pending any other approvals. |
* Unify agent guidance into single source of truth (#1089) Extracts the search-first, schema creation, and node reference rules from packages/agent/src/prompt_assembler.rs into a new packages/agent/src/agent_guidance.rs module exporting three pub const strings: SCHEMA_CREATION_RULES, SEARCH_FIRST_RULES, NODE_REFERENCE_FORMAT. Both consumers now derive their guidance from this module: - prompt_assembler.rs composes the Tool Strategy Guide and Response Formatting Rules seed bodies from the shared constants (byte-equivalent to the previous inline strings) - context_assembly.rs imports the constants and exposes a new agent_guidance_section() helper for ADR-032 callers writing CLAUDE.md / AGENTS.md files Adds unit tests in both files asserting the section composes from the shared constants, so future edits to a constant propagate to both the local Ollama agent and PTY agent sessions automatically. Acceptance criteria: - [x] Shared guidance rules exist in exactly one place - [x] PromptAssembler derives guidance from agent_guidance.rs - [x] context_assembly.rs derives guidance from agent_guidance.rs - [x] Editing a rule propagates to both consumers - [x] bun run test:all passes (3918 frontend + 1182 rust, 0 failures) - [x] bun run quality:fix clean Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> * Address review feedback on #1089 - Rename SEARCH_FIRST_RULES → TOOL_STRATEGY_RULES so the constant matches its actual contents (the full TOOL STRATEGY block, including schema and relationship bullets). - Remove the speculative pub fn agent_guidance_section() helper and its two tests from context_assembly.rs. The constants are exposed; ADR-032 will compose its own section format when its real consumer lands. Avoids prematurely locking a markdown shape with no caller to validate it. - Add seed_prompt_bodies_match_expected_bytes regression test in prompt_assembler.rs that locks in the exact bytes of the Tool Strategy Guide and Response Formatting Rules seed bodies. Catches accidental drift from edits to agent_guidance.rs constants or the format!() glue. - Document the intentional rule duplication in fallback_system_prompt() so future readers know it should collapse into the agent_guidance path once PromptAssembler is universally wired. - Drop the misleading "queued for #1088" claim from SCHEMA_CREATION_RULES doc and point readers at skill_pipeline.rs where the title_template guidance actually lives today. - Reorder lib.rs modules so agent_guidance (a leaf dep) precedes its consumer prompt_assembler. Tests: bun run test:all green (3918 frontend + 1182 rust, 0 failures). quality:fix clean. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> --------- Co-authored-by: Michael Libio <[email protected]> Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
Summary
Extracts the three shared agent guidance rules into a new
packages/agent/src/agent_guidance.rsmodule so the local Ollama agent and the PTY/ACP context-file path (ADR-032) derive their rules from a single source.agent_guidance.rsexports threepub conststrings:SCHEMA_CREATION_RULES,SEARCH_FIRST_RULES,NODE_REFERENCE_FORMATprompt_assembler.rscomposes the Tool Strategy Guide and Response Formatting Rules seed bodies from the shared constants — byte-equivalent to the previous inline strings, verified outside the test suitecontext_assembly.rsimports the constants and exposespub fn agent_guidance_section()returning markdown ready to embed inCLAUDE.md/AGENTS.mdunder ADR-032Closes #1089.
Acceptance criteria
agent_guidance.rs)PromptAssemblerderives guidance from that single sourcecontext_assembly.rsderives guidance from that single sourceagent_guidance.rspropagates to both consumersbun run test:all)bun run quality:fixTest status
Baseline (worktree, pre-change): 3917 frontend passed / 1 perf-threshold flake in
marked-config.test.ts, 1182 Rust passed.After change:
agent_guidance::tests::{schema_creation,search_first,node_reference_format}_*— assert each constant carries its expected anchor stringscontext_assembly::tests::test_agent_guidance_section_includes_all_rulesand..._uses_shared_constants— assert the helper composes from the shared constants so an edit to a constant updates context-file outputNotes on scope
title_templatetoken/field alignment called out in the issue (and Schema field rename with property data migration #1088) are not yet present in the prompts —SCHEMA_CREATION_RULESis seeded with the schema content that exists today (NODE MODEL paragraph). When Schema field rename with property data migration #1088 lands, it editsSCHEMA_CREATION_RULESand both consumers pick up the new rules automatically.context_assembly.rs's existingassemble()output is unchanged. The newagent_guidance_section()is the hook ADR-032 will call when it starts writingCLAUDE.md/AGENTS.mdfiles.packages/core/src/mcp/handlers/schema.rs(trailing blank line removed bycargo fmt).Test plan
PromptAssembler::seed_prompt_nodes()produces the samemarkdown_contentstrings as before)agent_guidance_section()are referenced from bothprompt_assembler.rsandcontext_assembly.rsbun run test:allclean on CI🤖 Generated with Claude Code