The Research Report
The Prompt That Rewrites Itself: Inside SePO's Self-Evolving Optimization Loop
How a team from NUS and CityU HK turned the optimizer into the optimized — and beat hand-crafted chain-of-thought by nearly 5 points across five benchmarks.
There's a paradox hiding in plain sight inside every prompt optimization pipeline. You build a "prompt agent" — an LLM-powered optimizer that iteratively refines the system prompts of task agents. The prompt agent reads evaluation scores, diagnoses failure modes, and proposes improved prompts. It's clever. It works. But the prompt agent itself? Its system prompt is written by hand, tuned by intuition, and frozen in place for the entire run. The optimizer is never optimized.
SePO (Self-Evolving Prompt Optimization), introduced by Wangcheng Tao, Han Wu, and Weng-Fai Wong in arXiv:2606.04465, closes that loop. The same evolutionary search that refines task agents' prompts also refines the prompt agent's own system prompt. The optimizer optimizes itself. And across AIME'25, ARC-AGI-1, GPQA, MBPP, and Sudoku, this self-referential design beats Manual Chain-of-Thought prompting by +4.49 average accuracy points — while remaining fully model-agnostic and human-readable.
Let's dig into why this works, how the evolutionary loop is structured, and what it means for the future of agentic systems.
The Asymmetry Problem
Most prompt optimization methods share a common architecture. A task agent (the system you're trying to make better) has a system prompt p that governs its behavior. A prompt agent (the optimizer) reads evaluation feedback — scores, error patterns, failure cases — and proposes a revised prompt p'. You iterate. The best prompt wins.
The problem: the prompt agent has its own system prompt, p̃, that tells it how to optimize. That p̃ is written by a human. It never improves. It's a fixed metalayer sitting atop an otherwise dynamic system.
This creates what the SePO authors call an asymmetric optimization. Only the task agent's prompt is learnable. The prompt agent's prompt is handcoded. The entire optimization surface is tilted — you can improve the worker but not the manager.
Prior work nibbled at this. PromptBreeder co-evolved task prompts alongside mutation prompts, but its meta-stack had a fixed top layer — a hand-written "hyper-mutation prompt" that was never itself evolved. The loop was bounded but never closed. MetaSPO treated prompt optimization as cross-task meta-learning, but the meta-optimizer itself stayed hand-written.
SePO's move is deceptively simple: treat the prompt agent as just another task agent. Its task happens to be "improve prompts." Apply the same optimization procedure to it. Close the loop.
Self-Referential Closure: The Key Insight
Formally, SePO defines a prompt task T̃ = (D̃, S̃). The dataset D̃ collects inputs of the form (T, A, E) — a pool of tasks, the task agent being optimized, and evaluation results. The scoring function S̃ measures whether the refined prompt p' improves task agent accuracy over p on task T.
Now the optimization of the prompt agent's system prompt becomes:
p̃\ = argmax{p̃} E\{(T,A,E) ~ D̃} [S̃(T, A, E, Ã_{(p̃, M̃, W̃)}(T, A, E))]*
This is the same mathematical form as optimizing a task agent's prompt — just with different parameters. The procedure is identical. The prompt agent treats itself as a "special task agent whose task is to improve task agent prompts." The authors call this self-referential closure.
At each evolutionary step during pre-training, the parent prompt p̃ fed into the prompt agent is the prompt agent's current system prompt. The agent is literally improving a copy of itself. It's not metaphorical self-improvement — it's a concrete feedback loop where the optimizer's instructions are themselves the optimization target.
The Evolutionary Loop in Code
SePO runs open-ended evolutionary search over an archive of candidate prompts. Here's a pseudo-code reconstruction of the core loop (Algorithm 1 from the paper), showing both stages:
def sepo(stage, seed_prompt, generations, children_per_gen,
prompt_agent_model, task_agent_model, task_pool,
pre_trained_prompt_agent_prompt=None):
"""
SePO: Self-Evolving Prompt Optimization
stage: "pre-training" or "fine-tuning"
- Pre-training: optimizes the prompt agent's OWN system prompt
- Fine-tuning: optimizes a task agent's system prompt (prompt agent is fixed)
"""
archive = [seed_prompt] # 𝒜 ← {p^(0)}
for t in range(1, generations + 1):
children = []
for k in range(children_per_gen): # parallelizable
# Sample a parent from the archive
parent = sample_from(archive)
# Build evaluation: run task agent with parent prompt on task(s)
eval_results = evaluate(parent, task_pool, task_agent_model)
# The prompt agent generates a child prompt
# KEY DIFFERENCE between stages:
if stage == "pre-training":
# Self-referential: the prompt agent uses its OWN current
# system prompt (which is the parent!) to generate an
# improved version of itself
child = prompt_agent_generate(
system_prompt=parent, # ← THIS is the self-reference
model=prompt_agent_model,
task_context=task_pool,
eval_feedback=eval_results,
parent_prompt=parent
)
elif stage == "fine-tuning":
# Prompt agent is frozen; uses pre-trained p̃*
child = prompt_agent_generate(
system_prompt=pre_trained_prompt_agent_prompt,
model=prompt_agent_model,
task_context=task_pool,
eval_feedback=eval_results,
parent_prompt=parent
)
# Score the child prompt on the task(s)
child_score = evaluate(child, task_pool, task_agent_model)
# Admission criterion: only keep improvements
if passes_admission(child_score, parent_score, archive):
archive.append(child)
children.append((child, child_score))
# Archive grows organically — earlier prompts become stepping stones
# for later generations, preserving diversity
# Return the best prompt found across all generations
return best_prompt(archive)
The critical line is the system_prompt=parent assignment during pre-training. The prompt agent is asked to generate an improved version of itself — it reads its own current instructions, sees the evaluation feedback, and produces a rewritten version. That rewritten version becomes both the next candidate in the archive and the system prompt for the next generation's prompt agent. The snake eats its tail.
The admission criterion is what makes this open-ended rather than greedy. Children only enter the archive if they improve on their parent. But the archive never shrinks — earlier prompts persist as stepping stones. This is inspired by QD (Quality-Diversity) principles from evolutionary computation: maintaining diverse high-performing solutions, not just the single best.
Two Stages: Pre-Training and Fine-Tuning
SePO mirrors the familiar pre-training → fine-tuning paradigm from deep learning, but applied to prompts rather than weights.
Stage 1: Pre-Training (Evolving the Prompt Agent Itself)
During pre-training, SePO-Generalist runs the self-referential loop over a multi-task pool — drawing tasks from different domains (math, reasoning, coding, science). The prompt agent's system prompt evolves from a seed p̃⁽⁰⁾ to an optimized p̃\*, learning general prompt optimization skills across diverse problem types.
This is where the magic accumulates. Each generation, the prompt agent reads its own current instructions, sees how well those instructions guided it to improve task agent prompts across multiple domains, and rewrites itself. Over many generations, the prompt agent learns not just domain-specific tricks but meta-strategies for prompt improvement: how to diagnose failure patterns, how to balance specificity versus generality, how to preserve working elements while refining weak ones.
SePO-Specialist is the single-task variant — pre-training on the same task that fine-tuning will target. It's less efficient (you must re-run pre-training for each new task) but serves as a useful ablation.
Stage 2: Fine-Tuning (Optimizing Task Agent Prompts)
During fine-tuning, the prompt agent is frozen — it uses the pre-trained p̃\ throughout. The optimization target shifts to the task agent's system prompt p*. The same Algorithm 1 runs, but now the evolutionary search is optimizing task-specific behavior rather than the optimizer itself.
A single pre-training run can be reused across many fine-tuning tasks. This amortizes the cost and, crucially, allows the prompt optimization skill to generalize to tasks the prompt agent has never seen during pre-training.
Results: +4.49 Points Over Manual CoT
The evaluation suite is intentionally diverse — five benchmarks spanning very different cognitive demands:
| Benchmark | Domain | What It Tests |
|---|---|---|
| AIME'25 | Mathematics | Multi-step algebraic and geometric reasoning |
| ARC-AGI-1 | Abstract reasoning | Novel visual pattern completion |
| GPQA | Graduate-level science | Expert-level physics/chemistry/biology |
| MBPP | Code generation | Python programming from natural language specs |
| Sudoku | Logic puzzles | Constrained constraint satisfaction |
Across all five, SePO-Generalist achieves the best accuracy against three baselines: Manual Chain-of-Thought (the strongest hand-crafted prompt strategy), TextGrad (textual-gradient optimization), and MetaSPO (cross-task meta-learning). The average improvement over Manual-CoT is +4.49 accuracy points.
The consistency matters more than the average. SePO doesn't just win on one domain and lose on others — it wins on every single task. That's the signature of a genuinely general prompt optimization skill, not domain-specific overfitting.
Cross-Task Generalization
Perhaps the most striking finding: the prompt optimization skill learned during pre-training on one set of tasks generalizes to tasks the prompt agent has never seen. The pre-trained prompt agent, when fine-tuned on a held-out task, still outperforms baselines. This suggests that SePO isn't memorizing task-specific prompt tricks but learning how to optimize prompts as a transferable meta-skill.
This has practical implications. Pre-train once, deploy many times. Each new task only requires the (much cheaper) fine-tuning stage, reusing the same evolved prompt agent.
Why This Beats the Alternatives
Versus Manual CoT: Hand-crafted chain-of-thought prompts are impressive but limited by human intuition. You can only think of so many prompt strategies. SePO's evolutionary archive can explore combinatorial spaces that no human would navigate manually.
Versus TextGrad: TextGrad treats prompt optimization as gradient descent in natural language — identifying "textual gradients" (critiques) and propagating them through the computation graph. But it requires a fixed optimizer (the critique generator) whose own prompt is hand-written. SePO closes the loop: the optimizer evolves itself.
Versus PromptBreeder: PromptBreeder's meta-stack is the closest predecessor. It co-evolves task prompts and mutation prompts. But the top of the meta-stack — the hyper-mutation prompt — stays hand-written. SePO's self-referential closure means there is no fixed top. The optimizer is inside the population it searches over.
Versus MetaSPO: MetaSPO meta-learns a shared cross-task prompt, but the meta-optimizer itself is hand-engineered. SePO applies the same optimization to the meta-optimizer, removing the need for manual meta-design.
What the Evolved Prompts Look Like
One of the underappreciated advantages of prompt-level optimization (versus weight-level or architecture-level) is interpretability. You can read the evolved prompts. The authors analyze them qualitatively and find that the pre-trained prompt agent develops sophisticated meta-strategies: decomposing problems into sub-steps, validating intermediate results, and adapting its approach based on the type of evaluation feedback it receives.
These aren't tricks that would be obvious to write by hand. They emerge from the evolutionary pressure of hundreds of generations of prompt refinement across diverse tasks. The archive mechanism preserves intermediate stepping stones, allowing the search to rediscover and recombine effective sub-strategies in ways that greedy optimization would miss.
The Broader Implication: Self-Referential Agent Design
SePO sits at an interesting intersection of two trends in AI agent research.
The first is the shift from modifying outputs (Self-Refine, Reflexion) to modifying agent code (ADAS, OpenEvol). SePO operates on system prompts — a middle ground that's more structured than output revision but more interpretable and model-agnostic than code generation. You don't need to trust generated code; you can read the prompt.
The second is the shift from fixed agents to self-evolving agents. The Gödel Machine vision — an agent that proves theorems about its own improvement and rewrites itself — has been an aspirational North Star. SePO is a concrete, practical instantiation: the agent proves nothing formally, but it demonstrates improvement empirically, and it does so by rewriting the very instructions that govern its improvement process.
The self-referential closure is the key design choice. It's what distinguishes SePO from "just another prompt optimizer." By placing the prompt agent inside the population it searches over, the optimizer becomes the optimized. The loop is closed. And as the results show, closing that loop yields consistent, measurable gains.
Practical Takeaways
For practitioners building LLM-based agents:
- Don't just optimize task prompts — optimize the optimizer's prompt too. The asymmetry in existing pipelines is a real bottleneck. Whatever gains your prompt optimizer produces, they're bounded by the quality of the optimizer's own instructions.
- Pre-train once, fine-tune many times. SePO-Generalist amortizes the cost of evolving the prompt agent across all downstream tasks. The fine-tuning stage is much cheaper than re-evolving the optimizer from scratch.
- Archives, not greedy search. The open-ended evolutionary approach with archive admission preserves diversity. Earlier (potentially mediocre) prompts serve as stepping stones for later breakthroughs. Don't just keep the best — keep what's interesting.
- Model-agnostic and human-readable. Unlike weight-level or architecture-level optimization, SePO's output is a natural language prompt. You can inspect it, understand it, and port it across models.
The code is available at github.com/taowangcheng/SePO (preparation in progress at time of writing).
Looking Ahead
SePO opens several natural extensions:
- What if the archive mechanism itself evolves? Currently, the admission criterion is fixed. A meta-evolutionary layer could optimize which candidates survive and how they're sampled.
- What about multi-modal prompts? The current framework operates purely in text. Extending to multi-modal system prompts (with images, structured data, or tool definitions) would widen applicability.
- Can the two-stage pipeline be unified? Pre-training and fine-tuning use the same algorithm but different targets. An online variant that continuously evolves both could adapt to distributional shift.
The deeper question is about the nature of self-improvement in AI systems. SePO demonstrates that a self-referential loop — where the improver improves itself — yields measurable, consistent gains without sacrificing interpretability or model-agnosticity. It's not full Gödel Machine recursion, but it's a concrete step in that direction. And it's a step you can read.
SePO: Self-Evolving Prompt Agent for System Prompt Optimization — Wangcheng Tao, Han Wu, Weng-Fai Wong. arXiv:2606.04465, June 2026. Paper · Code