Skip to content

Remove entity type injection from system prompt in favor of on-demand schema discovery #1283

Closed

Description

@malibio

Overview

The system prompt currently injects the full list of entity types (all user-defined schemas, their fields, enum values, etc.) into every agent turn via dynamic_context. At small scale this works, but at scale — 100 custom schemas — this could be 5–10k tokens injected every turn, bloating the context window and consuming the token budget reserved for conversation history.

Problem Statement

  1. Context window bloat at scale — every turn pays the full schema list cost regardless of whether types are relevant to the current message
  2. Architectural incoherence — injecting all types upfront makes search_skills optional when it should be load-bearing. The model can resolve node_type values and field names from the system prompt without ever calling search_skills, making the skill routing layer redundant
  3. search_skills is designed to be the on-demand discovery mechanism for workspace-specific knowledge. With eager injection, that role is already filled before inference begins.

Proposed Solution

Remove entity type injection from the system prompt. Instead, search_skills returns the matched skill plus the relevant type metadata for the current intent — field names, valid enum values, the correct node_type ID. The model gets exactly the schema context it needs, scoped to the current intent, rather than the entire schema dictionary on every turn.

Acceptance Criteria

  • build_workspace_context / format_for_prompt no longer injects entity type list into the system prompt
  • search_skills response includes the matched skill's associated schema metadata (type ID, fields, enum values) sufficient for the model to construct correct create_node / search_nodes / update_node calls
  • Agent produces correct node_type values on create/update calls by reading from search_skills response rather than system prompt
  • Context window usage per turn decreases proportionally to the number of registered schemas
  • Existing agent behavior is preserved for conversational turns (no regression on turns that don't need schema context)
  • PromptAssembler updated to omit entity type block
  • Benchmark harness (packages/agent/tests/search_skills_latency.rs) updated: scenarios use user-defined type prompts (e.g. "show me overdue invoices"), assert search_skills was called (hard failure, not WARN), and BenchToolExecutor returns realistic type metadata in skill match responses
  • Benchmark rerun on the updated architecture and results committed to nodespace-docs/development/benchmarks/
  • Code passes bun run quality:fix
  • Tests pass (bun run test:all)

Technical Specifications

Reference Files

  • packages/agent/src/acp/context_assembly.rs — builds dynamic_context string injected into session
  • packages/agent/src/prompt_assembler.rs — PromptAssembler assembles system prompt including workspace context
  • packages/agent/src/local_agent/prompt_templates.rs — fallback_system_prompt takes dynamic_context param
  • packages/agent/src/local_agent/agent_loop.rs — passes session.dynamic_context into prompt assembly each turn
  • packages/agent/src/local_agent/tools.rs — exec_search_skills — needs to return type metadata alongside skill match
  • packages/core/src/ops/skill_ops.rs — find_skills / FindSkillsOutput — return shape needs schema metadata
  • packages/agent/tests/search_skills_latency.rs — benchmark harness to update

Implementation Details

The search_skills response shape needs to be extended. Currently returns { query, matches: [{ name, confidence, description, tools }] }. Needs to include per-match schema metadata: the type IDs and field definitions associated with each skill's tool_whitelist scope.

Benchmark scenario prompts should reference user-defined types the model cannot resolve without search_skills — e.g. "show me overdue invoices", "find campaigns in draft status", "create a new sprint for Q3". The BenchToolExecutor should return a search_skills response that includes type metadata (field names, enum values, correct node_type ID), and each scenario should assert search_skills_calls > 0 as a hard failure rather than a warning.

Non-Goals

  • Changing skill definitions or the skill pipeline's semantic search implementation
  • Removing workspace context entirely — collections, playbooks, and other non-schema context may still be injected
  • Optimizing inference engine internals

Related Issues

Activity

  1. malibio commented on May 31, 2026

    @malibio
    CollaboratorAuthor

    Frontend baseline: 132 files, 3836 tests passed

  2. self-assigned this
    on May 31, 2026
  3. added 2 commits that reference this issue on Jun 22, 2026
    24b34bb
    6c532ee
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions