Skip to content

Unify agent guidance rules into a single source for local agent and gRPC tool layer #1089

Closed

Description

@malibio

Overview

The local agent's prompt assembler owns agent guidance rules (search-first, schema creation, node reference format) as DB-seeded prompt nodes. Under ADR-032, the @nodespace/agent-tools TypeScript package will also need consistent guidance injected into per-agent context files (CLAUDE.md / AGENTS.md). Both paths must derive from a single authoritative source to prevent drift.

The MCP initialize handler (packages/core/src/mcp/handlers/initialize.rs) that previously held a parallel copy of these rules is being deleted as part of ADR-031.

Problem Statement

Two locations own overlapping guidance content today:

  1. packages/agent/src/prompt_assembler.rs — seed_prompt_nodes() returns built-in prompt sections seeded to the DB on startup, used by the local Ollama agent
  2. packages/agent/src/acp/context_assembly.rs — assembles context for agent sessions; after ADR-032 this writes CLAUDE.md / AGENTS.md files and must embed the same rules

Rules that exist in both and can drift:

  • Schema creation rules: title_template tokens must match fields array; do not add name/title fields unless used in template
  • Search first guidance: always search before updating or fetching by ID; never use placeholder IDs
  • Node reference format: bare nodespace:// URIs (no markdown links, no backticks)

Any change to these rules must currently be made in multiple places with no test ensuring they stay in sync.

Proposed Solution

Extract shared rules into a single authoritative source in packages/agent/src/agent_guidance.rs exporting const rule strings. Both prompt_assembler.rs and context_assembly.rs import from it.

// packages/agent/src/agent_guidance.rs
pub const SEARCH_FIRST_RULES: &str = "TOOL STRATEGY:\n- ALWAYS search first...";
pub const SCHEMA_CREATION_RULES: &str = "SCHEMA CREATION RULES:\n...";
pub const NODE_REFERENCE_FORMAT: &str = "NODE REFERENCES: ...";

Acceptance Criteria

  • Shared guidance rules (search-first, schema creation, node references) exist in exactly one place in the codebase
  • Local agent (PromptAssembler) derives guidance from that single source
  • Context file assembler (context_assembly.rs) derives guidance from that single source
  • Changing a rule in one place automatically updates behavior for both the local agent and all PTY agent sessions
  • All existing tests pass (bun run test:all)
  • Code passes bun run quality:fix

Technical Specifications

Files to Modify

  • packages/agent/src/agent_guidance.rs (NEW) — single source of truth for guidance constants
  • packages/agent/src/prompt_assembler.rs — replace inline rule strings with imports
  • packages/agent/src/acp/context_assembly.rs — import shared rules when assembling context files
  • packages/agent/src/lib.rs — expose agent_guidance module

Current overlapping content locations

Rule Prompt assembler location Context assembly location
Schema creation prompt_assembler.rs Tool Strategy Guide seed (priority 50) context_assembly.rs (to be added under ADR-032)
Search first prompt_assembler.rs Tool Strategy Guide seed Same
Node references prompt_assembler.rs Response Formatting Rules seed (priority 60) Same

Dependencies

Related Issues

Activity

  1. changed the title [-]Unify agent guidance rules into a single source for MCP and local agent[/-] [+]Unify agent guidance rules into a single source for local agent and gRPC tool layer[/+] on May 17, 2026
  2. malibio commented on May 17, 2026

    @malibio
    CollaboratorAuthor

    Architecture update: MCP references removed

    Updated to reflect ADR-031 and ADR-032:

    • The MCP initialize handler (packages/core/src/mcp/handlers/initialize.rs) is being deleted — its parallel copy of guidance rules disappears with it
    • The new second path is context_assembly.rs, which under ADR-032 writes CLAUDE.md / AGENTS.md context files for PTY agent sessions
    • Scope is now: local agent PromptAssembler + PTY context file assembler, both sourcing from agent_guidance.rs
  3. self-assigned this
    on May 17, 2026
  4. malibio commented on May 17, 2026

    @malibio
    CollaboratorAuthor

    Starting work on this issue in worktree-issue-1089-unify-agent-guidance.

    Baseline test status (from worktree, before any changes):

    • Frontend: 3917 passed, 1 failed, 128 test files
    • Pre-existing failure: src/tests/utils/marked-config.test.ts > Performance and reliability > should handle large text efficiently — performance threshold flake (661ms vs 500ms limit), unrelated to this issue.
  5. added a commit that references this issue on May 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions