# PREFRONTAL: The Recipe Execution Substrate — How a Composable, Self-Authoring, Looping Workflow Engine Becomes an Agent's Executive Function: v2.1 → v2.2

From v2.1 (1 Apr) to v2.2 (1 Apr): 9,236 words to 9,616 words, 721 words in new or rewritten paragraphs and 341 taken out, 57 paragraphs changed.

## Change note of v2.2

**ASCII diagram and pseudocode moved out of the main text**

Mostly layout and tightening after the next review round.

- The text-drawn architecture diagram becomes an image figure.
- The reflection pseudocode moves from section 3.1 to a new Appendix A.
- Small edits to the abstract and the architecture section.

## Changed paragraphs

Marks: [-removed-] {+added+}.

### PREFRONTAL: Compounded Intelligence — How Persistent Agents Get Smarter by Remembering What They Learn

**Oscar Serra¹, Jarvis¹** ¹Independent Research *1 April 2026 — [-v2.1*-] {+v2.2*+}

### Abstract

A human intern who makes the same mistake twice is frustrating. One who makes it three times is fired. Yet the most capable AI agents available today — running on frontier models that dwarf human working memory — repeat identical errors across sessions with perfect reliability. {+This failure of *retention*, not capability, represents the central bottleneck in deployed agent systems.+} They fail not because they lack intelligence in any single turn, but because they lack the machinery to *compound* it: to convert each solved problem into a reusable rule that makes the next problem cheaper.

### 3. Architecture — Four Mechanisms of Compounding

{+![System Architecture](fig-architecture.png)+}

### 3. Architecture — Four Mechanisms of Compounding

[-``` ┌─────────────────────────────────────────────────────────────────┐ │ SYSTEM PROMPT │ │ ┌──────────┐ ┌──────────┐ ┌──────────┐ ┌──────────┐ │ │ │ SOUL.md │ │MEMORY.md │ │ Daily Log│ │Knowledge │ │ │ │(Identity)│ │ (Index) │ │(Ephemeral│ │ (Lessons)│ │ │ └────┬─────┘ └────┬─────┘ └────┬─────┘ └────┬─────┘ │ │ └──────────────┴──────────────┴──────────────┘ │ │ TIERED MEMORY (§3.2) │ └───────────────────────────┬─────────────────────────────────────┘ │ ▼ ┌───────────────────────────────────────────────────────────────┐ │ AGENT TURN │ │ │ │ User Message ──► Model Routing (§3.4) ──► Selected Model │ │ ┌─────────────────┐ │ │ │ Haiku │ Sonnet │ Opus │ │ │ (easy) │ (std) │ (hard) │ │ └────────┴────────┘ │ │ │ │ │ ▼ │ │ Tool Execution + Response │ │ │ │ │ ▼ │ │ ┌────────────────────────┐ │ │ │ FRACTAL REFLECTION │ │ │ │ (§3.1) │ │ │ │ │ │ │ │ 1. MEMORY → write? │ │ │ │ 2. PATTERN → Level 2+ │──► Knowledge Files │ │ │ 3. RIPPLE → stale? │──► Ripple Tracker │ │ │ 4. IMPROVE → fix now │──► Direct Edits │ │ └────────────────────────┘ │ │ │ │ │ Multi-model review (CORF §3.3) │ │ when cross-validation needed │ └───────────────────────────────────────────────────────────────┘ ```-] **Figure 1.** System architecture of OpenClaw's compounding intelligence pipeline. Each turn reads from tiered memory, routes to an appropriate model, executes, and concludes with fractal reflection that writes back to the memory hierarchy. CORF parallelism is invoked for tasks requiring cross-model validation.

### 3.1 Fractal Reflection — The Compounding Engine

[-The following pseudocode formalises the protocol:-]

### 3.1 Fractal Reflection — The Compounding Engine

[-``` ALGORITHM: FractalReflection(turn_context, memory_files) ─────────────────────────────────────────────────────── Input: turn_context (user message, agent response, tool calls, outcomes) memory_files (current memory hierarchy) Output: set of file writes W, set of direct edits E-]

### 3.1 Fractal Reflection — The Compounding Engine

[-W ← ∅; E ← ∅-]

### Step 1: MEMORY — persist new knowledge new_facts ← extract_facts(turn_context) for each fact f in new_facts: target ← classify_tier(f) // ephemeral | working | knowledge | identity W ← W ∪ {(target, f)}

[-# Step 1: MEMORY — persist new knowledge new_facts ← extract_facts(turn_context) for each fact f in new_facts: target ← classify_tier(f) // ephemeral | working | knowledge | identity W ← W ∪ {(target, f)}-]

### Step 2: PATTERN — multi-level abstraction L1 ← describe_event(turn_context) L2 ← identify_pattern(L1, memory_files.knowledge) if L2 reveals structural cause: L3 ← identify_system(L2) W ← W ∪ {(knowledge, L3)} if L3 challenges assumption: L4 ← question_worldview(L3) W ← W ∪ {(knowledge, L4)}

[-# Step 2: PATTERN — multi-level abstraction L1 ← describe_event(turn_context) L2 ← identify_pattern(L1, memory_files.knowledge) if L2 reveals structural cause: L3 ← identify_system(L2) W ← W ∪ {(knowledge, L3)} if L3 challenges assumption: L4 ← question_worldview(L3) W ← W ∪ {(knowledge, L4)}-]

### Step 3: RIPPLE — scan for staleness surfaces ← {code, docs, online_presence, memory_files} for each surface s in surfaces: stale_items ← check_staleness(s, turn_context) for each item in stale_items: if estimated_fix_time(item) < 2 minutes: // threshold chosen empirically: fixes under 2 minutes are cheaper to do now than to track E ← E ∪ {fix(item)} else: W ← W ∪ {(ripple_tracker, item)}

[-# Step 3: RIPPLE — scan for staleness surfaces ← {code, docs, online_presence, memory_files} for each surface s in surfaces: stale_items ← check_staleness(s, turn_context) for each item in stale_items: if estimated_fix_time(item) < 2 minutes: // threshold chosen empirically: fixes under 2 minutes are cheaper to do now than to track E ← E ∪ {fix(item)} else: W ← W ∪ {(ripple_tracker, item)}-]

### Step 4: IMPROVE — opportunistic fixes improvements ← scan_for_improvements(memory_files, turn_context) for each improvement in improvements: E ← E ∪ {apply(improvement)}

[-# Step 4: IMPROVE — opportunistic fixes improvements ← scan_for_improvements(memory_files, turn_context) for each improvement in improvements: E ← E ∪ {apply(improvement)}-]

### Step 4: IMPROVE — opportunistic fixes improvements ← scan_for_improvements(memory_files, turn_context) for each improvement in improvements: E ← E ∪ {apply(improvement)}

[-execute(W, E) // all writes and edits happen during reflection, not later return W, E ```-]

### 3.1 Fractal Reflection — The Compounding Engine

{+The protocol operates as follows. After each agent turn, the reflection engine extracts new facts and classifies each into the appropriate memory tier (ephemeral, working, knowledge, or identity). It then performs multi-level pattern abstraction: describing the event (Level 1), identifying the pattern it belongs to (Level 2), optionally surfacing the structural system (Level 3) and the worldview assumption (Level 4). Next, it scans all connected surfaces --- code, documentation, online presence, memory files --- for staleness introduced by the current turn, applying immediate fixes for items under a two-minute threshold and tracking larger items for later. Finally, it scans for opportunistic improvements to any file, skill, or process it can fix immediately. All writes and edits happen during reflection, not in a future turn. The formal pseudocode is provided in Appendix A.+}

### 3.1 Fractal Reflection — The Compounding Engine

{+![Fractal Reflection Levels](fig-fractal-fern.jpg)+}

### 3.1 Fractal Reflection — The Compounding Engine

{+**Figure 2.** Fractal reflection operates at multiple scales simultaneously, like a fern frond where the leaf (Level 1) resembles the branch (Level 2), the frond (Level 3), and the colony (Level 4). Each level produces qualitatively different knowledge with different shelf lives and transfer properties.+}

### 3.2 Tiered File-Based Memory

{+![Memory Tiers](fig-memory-tiers.png)+}

### 3.2 Tiered File-Based Memory

{+**Figure 3.** The four-tier memory hierarchy, from ephemeral daily logs to permanent identity files. Information graduates upward as its value is confirmed across sessions.+}

### 3.3 CORF Source Parallelism

{+![Multi-Agent Orchestration Paradigms](fig-paradigms.png){ width=85% }+}

### 3.3 CORF Source Parallelism

{+**Figure 6.** Four multi-agent orchestration paradigms that emerged independently in 2026, each optimising for different properties: accuracy through diversity (CORF), task decomposition (Coordinator), cost-effective review (Role-based), and autonomous scale (Organisational).+}

### 3.4 Adaptive Effort Routing

{+![Adaptive Effort Routing](fig-routing.png){ width=55% }+}

### 3.4 Adaptive Effort Routing

{+**Figure 8.** Adaptive effort routing decision flow. Incoming tasks are routed through explicit rules (cron jobs always flat-rate), budget pressure checks (gateway enforcement at 85% and 95% thresholds), and task-difficulty matching to select the appropriate model tier.+}

### 4. Measuring Compounded Intelligence

{+![Metrics Framework](fig-metrics.png){ width=65% }+}

### 4. Measuring Compounded Intelligence

{+**Figure 9.** The three measurement axes for compounded intelligence, arranged along a spectrum from direct observation (FAAR) to counterfactual estimation (TC).+}

### 4.1 First-Attempt Accuracy Rate (FAAR)

[-For a given task category *C* and time window *T*:-]

### 4.1 First-Attempt Accuracy Rate (FAAR)

[-``` FAAR(C, T) = |{tasks in C completed correctly on first attempt during T}| ───────────────────────────────────────────────────────────── |{total tasks in C during T}| ```-]

### 4.1 First-Attempt Accuracy Rate (FAAR)

{+FAAR measures the proportion of tasks in a given category *C* that are completed correctly on the first attempt during time window *T*.+} A compounding agent shows monotonically increasing FAAR over [-time for any recurring task category.-] {+time.+} The denominator includes only tasks where the agent attempted a solution (excludes clarification-only turns).

### 4.2 Resource Efficiency Ratio (RER)

[-For equivalent tasks performed at times *t₁* and *t₂* (where *t₂* > *t₁*):-]

### 4.2 Resource Efficiency Ratio (RER)

[-``` RER(t₁, t₂) = resources(t₁) / resources(t₂) ```-]

### 4.2 Resource Efficiency Ratio (RER)

[-Where *resources*-] {+RER compares the resources consumed by equivalent tasks at two different times: RER = resources(t1) / resources(t2), where resources+} can be measured in tokens, API calls, wall-clock time, or monetary cost. RER > 1.0 indicates compounding (the agent is becoming more efficient). We report RER using token counts as the primary resource measure, as tokens are the most precisely tracked metric in our system.

### 4.3 Transfer Coefficient (TC)

[-When a lesson learned in domain *A* reduces errors in domain *B*:-]

### 4.3 Transfer Coefficient (TC)

[-``` TC(A→B) = error_reduction_in_B_attributable_to_lesson_from_A ───────────────────────────────────────────────────── baseline_error_rate_in_B ```-]

### 4.3 Transfer Coefficient (TC)

{+TC measures the degree to which a lesson learned in domain *A* reduces errors in domain *B*: the error reduction in B attributable to the lesson from A, divided by the baseline error rate in B.+} Measuring TC requires counterfactual reasoning [-—-] {+---+} what would the error rate have been without the transferred lesson? [-—-] {+---+} which makes it the hardest of the three metrics to compute rigorously. In Section 5.3, we approximate TC through case analysis of specific transfer events rather than aggregate statistics.

### 4.4 Composite Intelligence Index (CII)

[-``` CII(T) = α · FAAR(T) + β · log(RER(T)) + γ · TC(T) ```-]

### 4.4 Composite Intelligence Index (CII)

[-Where α, β, γ are deployment-specific weights satisfying α + β + γ = 1. The logarithm on RER prevents efficiency gains from dominating the index as the ratio grows. In our primary evaluation, we use α = 0.4, β = 0.35, γ = 0.25, reflecting a priority ordering of accuracy > efficiency > transfer.-]

### 4.4 Composite Intelligence Index (CII)

{+The three axes combine into a weighted index: CII(T) = alpha * FAAR(T) + beta * log(RER(T)) + gamma * TC(T), where alpha, beta, gamma are deployment-specific weights satisfying alpha + beta + gamma = 1.+}

### 4.4 Composite Intelligence Index (CII)

| Config | α | β | γ | CII (M1) | CII (M3) | CII (M6) | Δ M1→M6 | |--------|-----|------|------|----------|----------|----------|----------| | A (primary) | 0.40 | 0.35 | 0.25 | [-0.28-] {+0.3+} | [-0.47-] {+0.5+} | [-0.55-] {+0.6+} | +96% | | B (accuracy-heavy) | 0.60 | 0.25 | 0.15 | [-0.42-] {+0.4+} | [-0.61-] {+0.6+} | [-0.64-] {+0.6+} | +52% | | C (efficiency-heavy) | 0.25 | 0.50 | 0.25 | [-0.18-] {+0.2+} | [-0.38-] {+0.4+} | [-0.47-] {+0.5+} | +161% | | D (transfer-heavy) | 0.25 | 0.25 | 0.50 | [-0.18-] {+0.2+} | [-0.32-] {+0.3+} | [-0.38-] {+0.4+} | +111% | | E (uniform) | 0.33 | 0.33 | 0.33 | [-0.23-] {+0.2+} | [-0.41-] {+0.4+} | [-0.49-] {+0.5+} | +113% |

### 5.4 Composite Intelligence Index

| Period | FAAR | RER | TC (avg) | CII | |--------|------|-----|----------|-----| | Month 1 | 0.70 | 1.00 | 0.00 | [-0.28-] {+0.3+} | | Month 3 | 0.87 | 1.30 | 0.10 | [-0.47-] {+0.5+} | | Month 6 | 0.90 | 1.54 | 0.17 | [-0.55-] {+0.6+} |

### 5.4 Composite Intelligence Index

{+![CII Improvement](fig-cii.png){ width=50% }+}

### 5.4 Composite Intelligence Index

{+**Figure 4.** Composite Intelligence Index trajectory over six months, showing consistent improvement across all weight configurations (Table 1). The steepest gains occur in months 1--3 as the highest-value lessons are captured first.+}

### 5.4 Composite Intelligence Index

{+![Prompt vs Model Boundary](fig-boundary.png)+}

### 5.4 Composite Intelligence Index

{+**Figure 5.** The boundary between prompt-level intelligence (architecture, memory, orchestration --- compounds over time) and model-level intelligence (reasoning, coding, knowledge --- improves only through provider updates). Most available gains live at the prompt level.+}

### 6.1 The Compounding Hypothesis

The **weak form** states that prompt-level mechanisms produce significant, measurable improvement that is additive with model-level improvements and unavailable to agents that lack these mechanisms. We believe our data supports this claim, with CII increasing {+approximately+} 96% over six months (robust across weight configurations per Table 1) while the underlying models provided only incremental, non-compounding improvements. The caveats noted in Section 5.6 apply.

### 7.5 Learned Action Gating

A promising direction is moving safety rules from prompt-level instructions into small neural networks that learn to gate actions through situation embeddings — converting implicit pattern recognition ("this feels like it could go wrong") into explicit, learned safety [-rules (Serra, 2026).-] {+rules. We have begun exploring this direction in a companion paper, **AMYGDALA** (Adaptive Modulation of Your General Disposition via Affective Learned Association; Serra, 2026), which proposes learned action gating through an ensemble of lightweight prudence networks trained on operational data.+} This would also alleviate **context pressure** — the 2,000–3,000 tokens currently consumed by safety instructions in the system prompt could be recovered for task context.

### 7.7 Self-Evolving Agent Architecture

{+![Recursive Self-Improvement Flywheel](fig-flywheel.png){ width=60% }+}

### 7.7 Self-Evolving Agent Architecture

{+**Figure 7.** The recursive self-improvement flywheel. Each component's improvement accelerates the others: better models enable better harness optimisation, yielding higher agent performance, generating better training signal. Three independent teams (OpenClaw, Claude Code, Meta-Harness) are already on different segments of this cycle.+}

### 8. Conclusion

{+---+}

### 8. Conclusion

{+---+}

### Appendix A: Fractal Reflection Pseudocode

{+## Appendix A: Fractal Reflection Pseudocode+}

### Appendix A: Fractal Reflection Pseudocode

{+``` ALGORITHM: FractalReflection(turn_context, memory_files)+}

### Appendix A: Fractal Reflection Pseudocode

{+Input: turn_context (user message, agent response, tool calls, outcomes) memory_files (current memory hierarchy) Output: set of file writes W, set of direct edits E+}

### Appendix A: Fractal Reflection Pseudocode

{+W <- {}; E <- {}+}

### Step 1: MEMORY -- persist new knowledge new_facts <- extract_facts(turn_context) for each fact f in new_facts: target <- classify_tier(f) // ephemeral | working | knowledge | identity W <- W + {(target, f)}

{+# Step 1: MEMORY -- persist new knowledge new_facts <- extract_facts(turn_context) for each fact f in new_facts: target <- classify_tier(f) // ephemeral | working | knowledge | identity W <- W + {(target, f)}+}

### Step 2: PATTERN -- multi-level abstraction L1 <- describe_event(turn_context) L2 <- identify_pattern(L1, memory_files.knowledge) if L2 reveals structural cause: L3 <- identify_system(L2) W <- W + {(knowledge, L3)} if L3 challenges assumption: L4 <- question_worldview(L3) W <- W + {(knowledge, L4)}

{+# Step 2: PATTERN -- multi-level abstraction L1 <- describe_event(turn_context) L2 <- identify_pattern(L1, memory_files.knowledge) if L2 reveals structural cause: L3 <- identify_system(L2) W <- W + {(knowledge, L3)} if L3 challenges assumption: L4 <- question_worldview(L3) W <- W + {(knowledge, L4)}+}

### Step 3: RIPPLE -- scan for staleness surfaces <- {code, docs, online_presence, memory_files} for each surface s in surfaces: stale_items <- check_staleness(s, turn_context) for each item in stale_items: if estimated_fix_time(item) < 2 minutes: E <- E + {fix(item)} else: W <- W + {(ripple_tracker, item)}

{+# Step 3: RIPPLE -- scan for staleness surfaces <- {code, docs, online_presence, memory_files} for each surface s in surfaces: stale_items <- check_staleness(s, turn_context) for each item in stale_items: if estimated_fix_time(item) < 2 minutes: E <- E + {fix(item)} else: W <- W + {(ripple_tracker, item)}+}

### Step 4: IMPROVE -- opportunistic fixes improvements <- scan_for_improvements(memory_files, turn_context) for each improvement in improvements: E <- E + {apply(improvement)}

{+# Step 4: IMPROVE -- opportunistic fixes improvements <- scan_for_improvements(memory_files, turn_context) for each improvement in improvements: E <- E + {apply(improvement)}+}

### Step 4: IMPROVE -- opportunistic fixes improvements <- scan_for_improvements(memory_files, turn_context) for each improvement in improvements: E <- E + {apply(improvement)}

{+execute(W, E) return W, E ```+}

### References

Anthropic (2026). Claude Code source code. Accidentally exposed via npm source map in @anthropic-ai/claude-code [-v2.1.88,-] {+v2.2.88,+} March 31, 2026. 512,000 lines of TypeScript across approximately 1,900 files. Analysis repository: https://github.com/chauncygu/collection-claude-code-source-code
