Skip to content

Enhanced System Prompt Management with User-Defined Components and Priority System #24

@ngduyanhece

Description

@ngduyanhece

Title

Implement Enhanced System Prompt Management with Multi-Component Architecture and
Runtime Customization

Summary

Replace the current monolithic system prompt with a flexible, multi-component
architecture that allows users to define custom prompt components, manage
priorities, and customize system behavior while preserving the existing prompt as
immutable defaults.

Background

Current State

  • Simple Architecture: Single systemPrompt string in cipher.yml (2,608 characters)
  • Limited Customization: No way to modify specific prompt sections without affecting
    entire prompt
  • Static Configuration: Requires restart to change system prompt
  • Monolithic Structure: All prompt logic in one block

Current System Prompt Flow

  1. memAgent/cipher.yml → systemPrompt field
  2. loadAgentConfig() → YAML parsing + environment expansion
  3. AgentConfigSchema → String validation
  4. createAgentServices() → PromptManager.load()
  5. ContextManager.getSystemPrompt() → Single prompt string

Problems with Current Approach

  • Users cannot customize domain-specific instructions without losing core
    functionality
  • No separation of concerns (memory instructions, personality, domain knowledge)
  • Difficult to version and maintain different prompt variations
  • No runtime management capabilities
  • Cannot enable/disable specific prompt features

Proposed Solution

Multi-Component Architecture

Transform the current monolithic prompt into a structured, priority-based component
system:

interface PromptComponent {
name: string; // Unique identifier
priority: number; // 0-1000 (higher = more important)
content: string; // Prompt content
enabled: boolean; // Runtime toggle
metadata?: {
category?: 'system' | 'memory' | 'user' | 'domain';
immutable?: boolean; // Cannot be modified
version?: string;
description?: string;
};
}

Enhanced Configuration Schema

Support both backward-compatible string format and new structured format:

Option 1: Simple string (backward compatibility)

systemPrompt: "You are an AI programming assistant..."

Option 2: Advanced multi-component structure

systemPrompt:
prompts:
- name: "core_system"
priority: 1000
content: |
You are an AI programming assistant with advanced memory capabilities.
enabled: true
metadata:
category: "system"
immutable: true

  - name: "user_personality"
    priority: 500
    content: |
      Be helpful, concise, and focus on practical solutions.
      Always explain your reasoning for complex problems.
    enabled: true
    metadata:
      category: "user"
      customizable: true

  - name: "domain_specific"
    priority: 300
    content: |
      For this TypeScript project, prioritize type safety and performance.
      Suggest efficient implementation patterns.
    enabled: false
    metadata:
      category: "domain"

settings:
  merge_strategy: "priority_order"
  separator: "\n\n"
  max_length: 8000
  truncate_strategy: "lowest_priority"

Key Features

  1. Backward Compatibility
  • Existing cipher.yml configurations work unchanged
  • Automatic migration from string to structured format
  • Graceful degradation when new features fail
  • Zero-downtime deployment
  1. Immutable System Components
  • Core system prompt preserved as default components
  • Components marked as immutable: true cannot be modified
  • Automatic restoration of corrupted immutable components
  • Version tracking for system components
  1. Flexible User Customization
  • Add domain-specific prompt components
  • Enable/disable components based on context
  • Adjust priorities for component ordering
  • Session-specific customization
  1. Runtime Management
  • Modify components without system restart
  • Real-time validation and preview
  • Component library and preset management
  • Import/export configurations
  1. Performance Optimization
  • Intelligent prompt composition caching
  • Lazy evaluation of component changes
  • Memory-efficient component storage
  • Fast validation and error handling
  1. Comprehensive Validation
  • Schema validation for all configurations
  • Runtime validation for component operations
  • Clear error messages and warnings
  • Conflict detection and resolution

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions