PART 5 · Harness & Self-Improvement
Context Engineering: From Handcrafted Prompts to Auto-Evolving Systems
As Agent tasks grow longer, context management is no longer optional. It has become the core battleground of Harness optimization.
Evolution of Optimization Targets
The smarter and more powerful the model, the more complex and general the optimization targets become. This evolution line goes all the way from tweaking prompts to optimizing the code that writes the optimizer.
The Problem: Context Bloat
Naive Append = Loss of Control
Naively appending all tool responses and model outputs to the context leads to rapid loss of control as Agent task duration grows.
Long-context research will continue to advance, but currently long-context intelligence and context engineering are often intertwined: context management is a critical layer for building more structured, concise contexts under the limited attention of LLMs.
Long-context research will continue to advance, but currently long-context intelligence and context engineering are often intertwined: context management is a critical layer for building more structured, concise contexts under the limited attention of LLMs.
ACE: Agentic Context Engineering
Plain English: Context is the AI's working memory — everything it can see in front of it. ACE's idea is: don't let memory turn into a mess; instead, maintain a well-organized working manual. The doer (Generator) follows the manual, the reviewer (Reflector) summarizes lessons learned, and the editor (Curator) organizes those lessons into the manual entry by entry. The manual keeps getting sharper, not thicker.
Context is an ever-evolving script — never let Prompts grow unchecked
ACE (Zhang et al. 2025) maintains a structured bullet-point script, where each entry includes an identifier and description. Three components collaborate to maintain this script:
Component 1
Generator
Executes tasks and generates trajectories, using bullet points from the script as guidance.
Component 2
Reflector
Distills insights from both successful and failed trajectories, extracting lessons learned.
Component 3
Curator
Updates the structured context with incremental, itemized entries, periodically refining and deduplicating.
ACE Framework: Generator produces trajectories → Reflector distills insights → Curator incrementally updates the context script. (Source: Zhang et al. 2025)
Key Design: The Curator outputs structured (identifier, description) entries and merges them into the script using deterministic logic, never rewriting entire prompt blobs. This avoids context collapse and conciseness bias that arise from iterative rewrites.
MCE: Meta Context Engineering
Plain English: ACE is about organizing the manual well. MCE asks a deeper question: can the method of organizing the manual itself be optimized? For example, organize by time or by topic? Record outlines or detailed notes? MCE separates what to record (content) from how to record (method), and evolves both: not only do notes get better, the note-taking method also keeps getting smarter.
Separating Mechanism from Content — Bi-Level Optimization
MCE (Ye et al. 2026) goes further than ACE: it separates how to manage context (mechanism/Skill) from what is in the context (content), optimizing both levels simultaneously.
An MCE Skill defines the context function
• ρ = static components (prompts, knowledge base, codebase)
• F = dynamic operators (search, select, filter, format)
An MCE Skill defines the context function
c = F(x; ρ):• ρ = static components (prompts, knowledge base, codebase)
• F = dynamic operators (search, select, filter, format)
What the formulas mean: Two sentences. Inner loop: given the current note-taking method, optimize the notes as much as possible. Outer loop: compare different note-taking methods and pick the best one. Optimize content first, then optimize the method — alternating rounds.
Bi-level Optimization:
Inner: c* = argmax J_train(c; s) ← given skill s, find optimal context
Outer: s* = argmax J_val(c*) ← find optimal skill (on validation set)
Skill Database: H = {(s_i, c_i, J_train_i, J_val_i)} tracks history
Skill Evolution: s_new = crossover(task, H) ← Meta-agent performs agentic crossover
Context Optimization: c_new = engineer(task, s_new; c_prev, Rollouts)
MCE Framework: meta-level skill evolution searches context management mechanisms; base-level optimizes task context. (Source: Ye et al. 2026)
Implementation: Context Function = Directory in a File System
In MCE, a context function is instantiated as a collection of files in a dedicated directory:
• Static files:
• Dynamic files: context data and rollout records
Both meta-level and base-level optimization run in a standard coding environment using the toolset:
• Static files:
skill.md (stores the most important task knowledge)• Dynamic files: context data and rollout records
Both meta-level and base-level optimization run in a standard coding environment using the toolset:
Read, Write, Edit, Bash, Glob, Grep, TodoWrite
Meta-Harness: The Harness That Optimizes the Harness
Plain English: This is the outermost layer of the nesting. ACE optimizes note content, MCE optimizes the note-taking method, and Meta-Harness directly optimizes the source code of the entire workbench. It's like letting AI redesign the entire workshop — far beyond swapping tools or methods. Most powerful, but also the most compute-intensive (every revision requires a full trial run and scoring).
Optimization Target: The Code That Decides What Gets Stored, Retrieved, and Presented
Meta-Harness (Lee et al. 2026) goes one layer deeper: what is being optimized is no longer the context content. What is being optimized is the code itself that determines what information should be stored, retrieved, and presented to the model. It is the Harness that optimizes the Harness.
• Proposer is itself a coding Agent
• Output is a set of Harness candidates on the Pareto frontier
• Execution history is accessed via the file system: coding agent reads on demand with
• Each proposed harness is a dictionary in the file system: contains source code, scores, trajectories, and state updates
• Proposer is itself a coding Agent
• Output is a set of Harness candidates on the Pareto frontier
• Execution history is accessed via the file system: coding agent reads on demand with
grep/cat, avoiding stuffing everything into the prompt• Each proposed harness is a dictionary in the file system: contains source code, scores, trajectories, and state updates
Meta-Harness outer loop optimization algorithm: iteratively creates new harnesses, keeping only the qualified ones. (Source: Lee et al. 2026)
Meta-Harness performance on text classification and TerminalBench-2. Note: the TerminalBench-2 experiment was initialized from an already-strong harness. (Source: Lee et al. 2026)
Comparison of Three Approaches
ACE
Learn from Trajectories
Maintains structured bullet points via a deterministic Generator→Reflector→Curator pipeline. Update rules are still hand-designed.
MCE
Evolve Management Mechanisms
Doesn't fix context format; uses free-form skills to store knowledge, bi-level iteration evolves both skills and context. Mechanism itself is mutable.
Meta-Harness
Optimize the Entire System Code
Proposer is a coding Agent, optimization target is the harness source code itself, outputs Pareto-frontier candidates. Most general but most compute-intensive.
Live Comparison: See Three Strategies Evolve Round by Round
Ready
Naive Append
Stuffing all history into context every round…
ACE Structured
Curator only incrementally writes structured entries…
MCE Meta-Evolution
Skill and content both evolving simultaneously…
Click Run 10-Round Comparison above to watch how the three strategies change in real time as rounds progress: who is bloating, who stays stable, who keeps improving.
Core Takeaway: Once harness design becomes an executable search space, powerful coding Agents can leverage the same design space that human engineers use. The future of context engineering is letting systems automatically learn what to store when, how to retrieve it, and how to present it — even the cleverest handcrafted prompts are just a transitional phase.