{"id":"2079876456637768187","url":"https://x.com/vorty279/status/2079876456637768187","text":"","author":{"name":"vorty","username":"vorty279","avatarUrl":"https://pbs.twimg.com/profile_images/2024590606253584384/kfM1SV5o_200x200.jpg"},"createdAt":"Wed Jul 22 10:29:24 +0000 2026","engagement":{"replies":4,"retweets":3,"likes":40,"views":60164},"article":{"title":"Loop Engineering: how a system improves itself","previewText":"They sell you a prompt. One perfect prompt for money. The secret is that the perfect prompt does not exist. What exists is a loop that finds a good prompt on its own while you sleep.\nLoop engineering","coverImageUrl":"https://pbs.twimg.com/media/HNXS39RXsAAgN5d.jpg","content":"They sell you a prompt. One perfect prompt for money. The secret is that the perfect prompt does not exist. What exists is a loop that finds a good prompt on its own while you sleep.\n\nLoop engineering is not about writing the right instruction on the first try. It is about building a loop that makes an attempt, looks at the result, understands what went wrong, and rewrites itself. Round and round until the metric stops climbing.\n\nThe whole idea in one sentence: you do not engineer the answer, you engineer the loop that arrives at the answer.\n\n## The core of every loop: four steps\n\nThe loop is always the same under any sauce. Four steps that repeat until the result is good enough.\n\nGenerate: the system makes an attempt. Writes a prompt, code, an answer, a strategy.\n\nEvaluate: the result runs through a metric. A test, a score, a compiler, a judge. The point is the evaluation is automatic and numeric.\n\nReflect: the model looks at the failures and states in words why it failed. Not just \"score 0.4\", but text like \"it missed the empty-input check here\".\n\nMutate: based on the reflection the system rewrites its attempt, and the loop starts again.\n\n![the four steps that repeat until the metric stops climbing](https://pbs.twimg.com/media/HNXawrFX0AAXJBb.jpg)\n\n## Why this works and prompt engineering does not\n\nManual prompting is you guessing. You try a phrasing, look with your eyes, change a word, look again. You are a slow evaluator, and you get tired.\n\nThe loop does the same thing a thousand times a night and never tires. And the key difference is that it has memory. Every attempt is saved to an archive with its score, and the next mutation starts not from scratch but from the best so far.\n\nThis is the part people skip. Without the archive it is not a self-improving loop, it is just a retry. The archive of past attempts and their results is what turns random search into directed evolution.\n\n![without the archive it is a retry; with it, the next mutation starts from the best result, not from zero](https://pbs.twimg.com/media/HNXbKxLW4AEUtwQ.jpg)\n\n## How the metric climbs in practice\n\nLook at a real run and the individual attempts jump up and down, that is noise. But the \"best in archive\" line climbs monotonically, because the archive remembers the good finds and does not let them slip back. The loop stops when the target is reached or the iteration budget runs out.\n\n![individual attempts are noisy, but the best-so-far from the archive pulls quality up to the target threshold](https://pbs.twimg.com/media/HNXb3BKWMAA2R3j.png)\n\nThis mechanism is what modern systems run on. ShinkaEvolve from Sakana AI reaches a new state-of-the-art on the circle-packing task in roughly 150 evaluations where prior systems burned thousands, thanks to the archive and smart parent sampling. GEPA lifts accuracy on math benchmarks just by reflecting on failures, and on some tasks turns out several times more sample-efficient than reinforcement learning.\n\n## The Thinker · Worker · Verifier pattern\n\nWhen one model in a loop hits a wall, the roles get split across three agents.\n\nThinker breaks the task into steps and plans. Worker executes a concrete step, generates output. Verifier checks quality and decides: accept or send back for a redo.\n\nIt is the same generate → evaluate → reflect, but the roles are explicit, and the verifier is a separate agent rather than just a test. Useful where evaluation itself needs reasoning. The downside is three agents cost three times more, so the verifier usually runs on a cheap model and the thinker on an expensive one.\n\n![thinker plans, worker executes, verifier accepts or sends back for a redo](https://pbs.twimg.com/media/HNXcoBwWYAAMmkB.jpg)\n\n## The main trap: verifiable outcome\n\nThe loop improves exactly what you measure. If the metric is off, the system gets better at the off metric and worse in reality. This is called goodharting: the proxy metric climbs while the product degrades.\n\n![after the divergence point the proxy metric keeps climbing while real quality falls](https://pbs.twimg.com/media/HNXc4cPXUAApwXk.jpg)\n\nHence the iron rule: loop engineering only works where the outcome is verifiable automatically and honestly. Code passes tests, yes or no. A math problem has a right answer, yes or no. A SQL query ran in so many milliseconds. Those are good loops.\n\nWhere there is no honest automatic evaluation (like \"do people enjoy the text\"), the loop will optimize the judge and not reality. So either build an honest evaluator, or keep a human in the loop on the final step. Recent work handles this by anchoring the loop to a specification and a regression oracle rather than a scalar metric, then the loop converges toward the spec instead of over-optimizing a proxy.\n\n## A minimal loop in Python\n\nNo framework, pure idea. Claude generates, the test evaluates, Claude reflects, repeat.\n\nThree things turn a retry into a real loop: memory is fed back into generation, the best is stored separately, and there is a stop condition on both target and iteration count. Without the last one the loop spins forever and burns money.\n\n## Where this actually gets used\n\nCode. An agent writes a function, runs tests, reads the traceback, fixes it. SICA (Self-Improving Coding Agent) edits its own codebase and lifts its own SWE-bench score.\n\nPrompts. Instead of hand-tuning you run prompt evolution against a dataset. GEPA reflects on failures and improves the prompt iteratively.\n\nAlgorithms. AlphaEvolve from DeepMind and its open counterparts evolve source code using execution as the fitness function, and find solutions better than human ones.\n\nData engineering. The loop optimizes SQL and pipelines using the query plan and runtime as the metric.\n\n## Repositories (all open)\n\nTake it and run it, there is no one to pay. Links verified at time of writing, still check the stars, license, and last-commit date before you depend on anything.\n\nSakanaAI/ShinkaEvolve: program evolution with an archive, parallel evaluation, and smart parent sampling; sample-efficient, Apache-2.0. Has skills to run inside Claude Code and Codex. https://github.com/SakanaAI/ShinkaEvolve\n\ngepa-ai/gepa: reflective evolution of prompts and code: optimizes any textual parameter against any metric via natural-language feedback. Adapters for DSPy, RAG, MCP. https://github.com/gepa-ai/gepa\n\nMaximeRobeyns/self_improving_coding_agent: SICA, an agent that edits its own codebase. A genre classic. https://github.com/MaximeRobeyns/self_improving_coding_agent\n\nalgorithmicsuperintelligence/openevolve: an open implementation of AlphaEvolve: code evolution through a MAP-Elites archive and a cascade evaluator. https://github.com/algorithmicsuperintelligence/openevolve\n\nShengranHu/ADAS: automated design of agentic systems: a meta-agent that invents agent architectures by programming them in code. https://github.com/ShengranHu/ADAS\n\nXMUDeepLIT/Awesome-Self-Evolving-Agents: a large curated survey with papers, benchmarks, and code on the topic. A good place to dig further. https://github.com/XMUDeepLIT/Awesome-Self-Evolving-Agents\n\nFor the basics, read Reflexion (language agents with verbal reinforcement learning) and DSPy as a framework where loop optimization is built in (the GEPA optimizer ships as a teleprompter).\n\n## The main idea\n\nLoop engineering is a shift from \"you write the answer\" to \"you build the machine that finds the answer\". Four steps, generate, evaluate, reflect, mutate, plus an archive and an honest metric.\n\nAll the difficulty is not magic but two things nobody sells in a course: build an honest evaluator, and do not let the loop optimize the proxy instead of reality.\n\nThe prompt is sold for money. The loop that finds the best prompt on its own sits on GitHub for free.\n\nArticle by @vorty279, content maker in the AI space. Verify figures and model versions against primary sources before publishing, this field moves fast."}}