Software Design Specification - Prompt Engineering / Core
Proposed
The Prompt Evolution Engine implements Lamarckian Evolution for prompt files. Traits acquired during execution (lessons learned) are passed down to the next generation (updated prompts).
This creates an Anti-Fragile System that gains intelligence from every error.
| Neural Network Concept | Prompt Training Equivalent |
|---|---|
| Weights (W) | Prompt file text |
| Forward Pass | LLM generating code from prompt |
| Loss Function (L) | Test suite / Linter / Compiler errors |
| Backpropagation (∇L) | Groomer Agent analyzing error |
| Weight Update | Git commit updating prompt text |
| Learning Rate (η) | Magnitude of allowed text change |
sequenceDiagram
participant Dev as Developer
participant Task as Task Prompt
participant LLM as LLM Engine
participant Test as Test Runner
participant Groom as Groomer Agent
participant Git as Version Control
Dev->>Task: Execute task.prompt.md
Task->>LLM: Generate Code
LLM-->>Test: Output: feature.ts
Test->>Test: Run Tests
alt Tests Pass
Test-->>Dev: ✓ Commit
else Tests Fail
Test->>Groom: error.log
Groom->>Groom: Analyze Root Cause
Groom->>Task: Propose Constraint Update
Groom-->>Git: PR: Update task.prompt.md
Git-->>Dev: Review & Merge
end
Each prompt file contains an append-only section for learning:
1
2
3
4
5
6
7
8
... [Standard Instructions] ...
# 🧬 MEMETIC EVOLUTION LOG (Auto-Generated)
<!-- The AI appends specific failure modes here. -->
- [2025-10-12]: Failed to implement error handling for API 429.
FIX: Always wrap fetch calls in the `retryWrapper` utility.
- [2025-10-14]: Hallucinated a 'User' type.
FIX: Import types strictly from `@/types/index.d.ts`.
When the Evolution Log exceeds threshold items (default: 10), trigger consolidation:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
def consolidate_prompt(prompt: PromptFile, threshold: int = 10) -> PromptFile:
"""Rewrite instructions to incorporate lessons, then clear log."""
if len(prompt.evolution_log) < threshold:
return prompt
consolidated = groomer.synthesize(
original_instructions=prompt.instructions,
lessons=prompt.evolution_log
)
return PromptFile(
instructions=consolidated,
evolution_log=[] # Clear after consolidation
)
The Groomer operates on a Cartesian plane of meaning with two orthogonal axes:
| Vector | Trigger | Action | Example |
|---|---|---|---|
| CONCRETIZATION (Resolution++) | Model was too vague / hallucinated | Add specific constraints | “Use a database” → “Use PostgreSQL 14 with TypeORM” |
| ABSTRACTION (Resolution–) | Model got stuck on wrong detail | Remove specific “How,” focus on “What” | “Use a for-loop” → “Iterate efficiently” |
| SPECIALIZATION (Scope–) | False positive (rule applied incorrectly) | Add exception clause | “Always retry” → “Retry ONLY on 5xx” |
| GENERALIZATION (Scope++) | False negative (rule missed case) | Broaden applicability | “Log user logins” → “Log all auth events” |
CRITICAL: You cannot move diagonally (opposites).
To transform from [Abstract/General] to [Concrete/Special]:
This prevents hallucination from large semantic jumps.
Configured in .github/config/agent-defaults.json:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
{
"economy": {
"constraintBudget": 20,
"decayRatePerCycle": 0.1,
"consolidationThreshold": 10
},
"grooming": {
"vectors": ["concretization", "abstraction", "specialization", "generalization"],
"pivotRequired": true,
"maxChangePerCycle": 3
},
"training": {
"patience": 3,
"batchSize": 1,
"earlyStoppingThreshold": 5
}
}
| Parameter | Description |
|---|---|
constraintBudget |
Max constraints in a prompt (Attention Tax) |
decayRatePerCycle |
Strength reduction for unused constraints |
consolidationThreshold |
Evolution log items before rewrite |
patience |
Retries before grooming triggers |
batchSize |
Errors accumulated before batch update |
| Economy | Role | Anti-Overfitting Mechanism |
|---|---|---|
| Attention Economy | Scarcity (Context Window) | Constraint Budget (Cap & Trade) |
| Knowledge Economy | Power Structure (Regime of Truth) | Foucaultian Deregulation (Prune rules) |
| Intention Economy | Current Goal Demand | Arbiter Agent (Compare intention vs. history) |
When adding a new constraint:
1
2
3
4
5
6
7
8
9
10
11
12
def should_add_constraint(new_constraint: Constraint, prompt: PromptFile) -> bool:
if prompt.constraint_count < BUDGET:
return True
# Find lowest value constraint
weakest = min(prompt.constraints, key=lambda c: c.activation_count / c.token_cost)
if new_constraint.expected_value > weakest.value:
prompt.remove_constraint(weakest)
return True
return False
Every constraint has:
timestamp: When addedstrength: Starts at 100%, decays over timeactivation_count: How often triggeredWeekly cycle: Remove constraints with strength < 20%.
Start with maximum abstraction:
1
2
3
You are an expert software engineer.
Write high-quality code for this task.
Follow standard best practices.
Result: Months of “learning from mistakes” compressed into one synthetic run.
1
POST /evolution/trigger
Request:
1
2
3
4
5
6
7
8
{
"prompt_path": ".github/prompts/phase-3/01-test-fabrication.prompt.md",
"error_log": "TypeError: Cannot read property 'id' of undefined...",
"context": {
"test_file": "auth.test.ts",
"commit_sha": "abc123"
}
}
Response:
1
2
3
4
5
6
7
{
"evolution_id": "uuid",
"proposed_vector": "SPECIALIZATION",
"proposed_change": "Add null check requirement for user objects",
"confidence": 0.85,
"requires_approval": true
}
1
POST /evolution/{id}/apply
1
POST /evolution/consolidate
| Component | Relationship |
|---|---|
| CI/CD Pipeline | Triggers evolution on test failure |
| Semantic Groomer | Executes four-vector operations |
| Axiological Nexus | Provides constraint valuation |
| Version Control | Commits prompt updates |