The Problem
When building AI agents, you need to combine static base instructions, dynamic workspace configuration, and role-based overlays. Traditional approaches fail to manage priorities effectively.
❌ Traditional Approaches
- Simple concatenation → No clear priorities
- Numerical weights → LLMs ignore subtle differences
- Hardcoded prompts → Can't adapt to roles/contexts
✅ Prompt Fusion
- Semantic priorities → "CRITICAL" vs "MODERATE"
- Automatic conflict resolution → Explicit ordering
- Dynamic composition → Runtime role switching
- Framework agnostic → Works with any LLM
How It Works
Three-layer prompt management with intelligent semantic weighting
Layer 1: Base
Tool definitions, safety rules, foundational constraints
Weight: 20-60%
Layer 2: Brain
Workspace configuration, project context, user preferences
Weight: 20-60%
Layer 3: Persona
Role-specific behavior, dynamic overlays
Weight: 0-50%
Semantic Weight Translation
| Weight Range | Semantic Label | Meaning |
|---|---|---|
| >= 0.6 | CRITICAL PRIORITY | Dominates all other instructions |
| >= 0.4 | HIGH IMPORTANCE | Strong influence on behavior |
| >= 0.2 | MODERATE GUIDANCE | Balanced consideration |
| < 0.2 | OPTIONAL | Background context only |
Quick Example
import PromptFusionEngine from './core/promptFusionEngine.js';
const engine = new PromptFusionEngine();
const layers = {
base: "You are a helpful AI assistant. Never share private information.",
brain: "Working on: Customer Analytics. Format: JSON with citations.",
persona: "Role: Data Analyst. Focus: Statistical analysis and insights."
};
const weights = {
base: 0.2, // Background rules
brain: 0.3, // Project context
persona: 0.5 // Role behavior (DOMINANT)
};
const fusedPrompt = engine.semanticWeightedFusion(
layers.base,
layers.brain,
layers.persona,
weights
);
Output:
[BASE LAYER - MODERATE GUIDANCE]
You are a helpful AI assistant. Never share private information.
[BRAIN CONFIGURATION - MODERATE GUIDANCE]
Working on: Customer Analytics. Format: JSON with citations.
[PERSONA INSTRUCTIONS - CRITICAL PRIORITY - MUST FOLLOW]
Role: Data Analyst. Focus: Statistical analysis and insights.
[CONFLICT RESOLUTION RULES]
When instructions conflict, apply this priority order:
1. PERSONA instructions (weight: 0.5)
2. BRAIN instructions (weight: 0.3)
3. BASE instructions (weight: 0.2)
Framework Integration
Works seamlessly with leading AI frameworks
LangChain
Use with messageModifier callback
OpenAI SDK
Use with instructions parameter
Anthropic Claude
Use with system parameter
Use Cases
Multi-Role AI Agents
Switch between analyst and researcher roles dynamically without restart
Workspace-Specific Agents
Same base logic, different configurations for production vs development
Hierarchical Instructions
Tool safety > Project rules > User preferences with automatic conflict resolution