Self-Improving Memory: Meta’s Agent Rewrites Its Own Prompts Meta researchers built a self-improving agent, based on the Kimi K2.6 model, that runs a stream of related tasks with only a file folder carrying over between them, then digests its own trials to select the best-performing prompts and retrain the same model on that dataset. The agent's harness starts with two prompts, LOAD before each sub-task and OFFLOAD after it, and the researchers compared four memory designs — running summary, retrieval (RAG), a skill library and hypothesis tracking — across three Continual Learning Bench tasks: SQL questions, fixing repo issues and finding occupied channels in radio scans, running each memory and prompt combination five times. The best memory design changed per task, indicating memory choice is task-dependent. It’s finally there Agents are starting to optimize and retrain themselves Alright, I know; I even shared my setup recently https://www.louisbouchard.ai/my-ai-setup/ , where we could already have the agents optimize themselves over time. This is really easy to do with a prompt that tells it to review your interaction and improve the skill you are using, and you do that every time it runs. You can take that to the next level with analytics, identify features to A/B test, and run this automatically every day, so you improve the SEO of your website or app. But I have something new today where language models are literally retraining themselves. It’s from some very cool new research I stumbled upon on Meta’s blog https://facebookresearch.github.io/RAM/blogs/self improving memory/ . The very simple TL;DR is that they asked a model to solve a multi-step task, something that requires multiple back-and-forth, and do that while leveraging different types of memory, like solving it while keeping everything in the prompt, or maintaining a summary of the past prompts and outputs, or using skills or even our old-school RAG. But then they asked the same model to digest all these trials on the task, pick the prompts that led to the best results, and ultimately make a dataset from that and retrain the same model. If that was too fast, don’t worry, let’s go over everything they did and why it’s so cool, because there’s even more to it If you don’t know me yet, I’m Louis-François, CTO and co-founder at Towards AI, where we turn engineers into AI engineers who build and ship AI products. Alright, so let’s detail the actual experiment a bit more. Meta’s agent, based on the Kimi K2.6 model, works through a stream of related tasks. So not just one, but multiple tasks. Each one starts with an empty context, and the only thing that carries over is a folder of files the agent reads and writes into. At this initial point, there are only two prompts in the agent’s harness. We have a prompt called LOAD before each sub-task that says what to read. The second prompt, OFFLOAD, is sent only after the sub-task is completed and says what to save. In their generic version they’re super simple prompts, like: read your memory, update it, what to keep is your decision. So, the main goal is to have the model decide what to save when it finishes a task so it can do the next one better. But it’s not only saving the prompts and results processed in the current task. The researchers actually gave four ways to save data into the harness’ memory, which are all classic memory designs: a running summary, retrieval RAG , a skill library and hypothesis tracking, where the model just saves extra guesses to confirm them in the future. They tested them on three Continual Learning Bench https://arxiv.org/abs/2606.05661 tasks: SQL questions, fixing repo issues, and finding occupied channels in radio scans. So one first goal of the experiment here was to compare these four ways to update a harness’ memory. And, as expected, the best design changed per task. And this is one thing we can already take away from this research, even if we are not retraining models ourselves. Memory is task-dependent. Sometimes RAG is ideal, other times you just need to shove it all in the prompt, and in situations where you can test and compare, like in code, simply keeping guesses and actually running them whenever possible beats the rest. And if you want to build a file-based memory like this one for your own agents, I wrote about a memory your AI agents can reuse https://www.louisbouchard.ai/memory-for-ai-agents/ . Alright, so they let the model learn its own memory design from the four options: Summary, Retrieval, Skill, and Hypothesis. Which means they start not with one but four short, handwritten LOAD and OFFLOAD pairs. They then run the agent through the whole task stream with each memory system and prompt combination, and do that five times. That’s a lot of runs. We have 3 tasks, 4 memory systems to compare, so that’s 60 runs in this first round. Each round, the four best become “parents”. Similar to an evolutionary algorithm. Well, exactly an evolutionary algorithm. After this first round, a meta agent of the same model, Kimi again, reads what happened: the message histories, the scores, and the memory folder it made. It summarizes each subtask, analyzes each run, finds the recurring failures, and rewrites the LOAD and OFFLOAD prompts. Every rewrite goes back in the pool to be scored, and the cycle repeats. This means Kimi rewrites its own instructions after reading its own mistakes. Just like each of my skills ends with a prompt to digest the current interaction and improve it, I’d highly recommend implementing this feedback loop in all your skills if you don’t have it already Let me show you what that loop looks like here with Kimi on the repo-fixing task. The running summary design barely beat the generic prompt. The meta agent noticed its memory was one file that kept growing, so the agent kept re-discovering the repository, and it rewrote the prompts to reuse the recorded repo path and write a rule after every failure. The score went from the mid-thirties to the low fifties. Then we’re back at four candidates, now the four best so far, the new parents. Their next report found one append-only file with no index from symptoms to fixes, so the next rewrite added a quickstart, a symptom-to-fix table and one file per fix, and the score went higher again. So here’s what the model’s own prompts get you, averaged over the three tasks. The no-memory option scores around 20, a generic prompt in the mid-thirties, the best handwritten prompt they came up with scored around 45, and the prompts the model wrote itself reached 56 And that’s also why I don’t really hand-tune skills anymore. Models are pretty good at managing them themselves. Here, it actually beats a carefully optimized handwritten prompt just with sheer volume and automated iterations. Just note that this doesn’t happen every time, of course. Sometimes the model loops into sloppiness and the results only worsen. This happens a lot when writing with LLMs, for instance. That’s why I always tell it to only do one round of feedback review. But for other tasks, like coding here, it’s super helpful. And they don’t stop there. We haven’t talked about any retraining of a model yet. This was just prompt and instruction optimization with tons of iterations and tweaking. Once they have the results after these multiple rounds, they run the model with its best prompts one full time on the same tasks and log every call: responses, reasoning, tool calls. That becomes a brand new dataset. The only change they have to make to have the model self-improve from this data is to swap the optimized prompts back to the generic ones and keep the responses exactly as they were. Then a LoRA fine-tune, a small add-on set of weights, teaches the model to act as if it had the good prompt while only seeing the short one. This way, it learns to behave better even from short, unclear directions. That’d make models quite a bit better to most people, I think And the coolest bit is that with only the generic prompt, the retrained model is now clearly better than the base one and better than the model fine-tuned on its own plain runs without the optimization. This means the model can optimize its own harness and then train itself on it to retain some of that optimization. Now, you can keep on repeating this process and see where it leads They haven’t tested that in the research, but that’d be pretty cool to see in future iterations And, by the way, none of this is new on its own: prompt optimization, context distillation, and tying harness tuning to fine-tuning, like WHALE https://arxiv.org/abs/2609.00196 , Co-Harness https://arxiv.org/abs/2607.22688 and Harness-Zero https://arxiv.org/abs/2609.24974 , all exist. What’s new here is doing it on memory instructions only, with one model in both roles and a plain prompt swap. Memory optimization and putting it into the model’s actual weights by retraining it. If the word harness is new to you, I explained it in my harness engineering article https://www.louisbouchard.ai/harness-engineering/ . It’s still a blog post, with no paper linked yet as I write this, on three tasks, one model, and best-observed scores. So it isn’t ground truth that models are now self-evolving and will dominate the world tomorrow. But it’s a very interesting signal towards memory management. So what do you take from this? First, log your agent’s full runs and its memory folder after each task, since that’s what the meta agent reads. Second, turn failures into rules: the winning database prompt said to log every failure as an if-then rule, and the repo prompts did the same. Third, only with an eval you trust, let a model propose rewrites, score them on tasks it hasn’t seen, and keep only the winners. And that’s what I find so cool: we went from a prompt at the end of a skill that improves it, to a meta agent rewriting the instructions, to a model training on its own best runs. By the way, if that was interesting, I discuss memory management and much more in my upcoming AI Engineering for Production book. It’s our second book after Building LLMs for Production. It will be an incredible 600-page-or-so bible on AI engineering, and if this article was interesting, it’s the perfect book for you You can sign up to the waitlist https://www.louisbouchard.ai/book/ to know when it’s out. It’s the first research breakdown like this I’ve done in a long time. Please let me know if you liked it and would like to see more I hope you enjoyed it as much as I did making it Self-Improving Memory: Meta’s Agent Rewrites Its Own Prompts https://pub.towardsai.net/self-improving-memory-metas-agent-rewrites-its-own-prompts-1c734367be21 was originally published in Towards AI https://pub.towardsai.net on Medium, where people are continuing the conversation by highlighting and responding to this story.