AI EngineeringAI AgentsLarge Language ModelsAI AgentsLarge Language ModelsAI Engineering
AI Engineering12 min read

Self-Improving Memory: Meta's Agent Rewrites Its Own Prompts

Meta's Self-Improving Memory, explained: a model rewrites its own memory prompts, then is fine-tuned on its best runs. What you can reuse in your agents.

Original video audio

Listen instead

Source

Can an AI Model Retrain Itself? Meta Just Tried It

Overview of Meta's Self-Improving Memory in two steps. Step 1, harness optimization: a meta agent turns generic LOAD and OFFLOAD prompts into optimized ones for the Database task. Step 2, harness distillation: the agent's runs with optimized prompts are paired with generic prompts and used to fine-tune the model. Bar charts on the right show test scores for each step.
Table of Contents

The short version

Self-Improving Memory is research from Meta's RAM team where one model, Kimi K2.6, improves how it manages its own memory in two steps. First, a meta agent of the same model reads the agent's past runs and rewrites the two prompts that say what to read from memory and what to save (harness optimization). Then the model is fine-tuned with LoRA on its best runs, with the optimized prompts swapped back to the generic ones, so part of the gain moves into its weights (harness distillation). It was tested on three Continual Learning Bench tasks, and it is a blog post with no paper yet as of November 21, 2026.

  • Memory is task-dependent. Across SQL questions, repo fixes and radio scans, no single memory design (summary, retrieval, skills or hypotheses) won on all three tasks.
  • The prompts the model wrote for itself averaged 56 on the three tasks, against about 45 for the best hand-written prompts and the mid-thirties for a generic one. These are best-observed scores on three tasks with one model.
  • Fine-tuned on its own best runs with only the generic prompt, the model scored 43.1 on average, against 37.6 when fine-tuned on its plain runs. Training kept part of the gain.

It’s finally there! Agents are starting to optimize and retrain themselves!

Alright, I know; I even shared my setup recently, 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.

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.

The experiment: an agent, a memory folder and two prompts

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.

Diagram titled Generic Harness. Three sub-tasks run one after the other. The task agent works on sub-task 1, then an OFFLOAD prompt follows. Sub-tasks 2 and 3 each start with a LOAD prompt and end with an OFFLOAD prompt. Arrows lead from each sub-task down to a shared folder named memory that holds a few files.

The generic harness: each sub-task ends with OFFLOAD, the following ones start with LOAD, and only the memory folder carries over. Figure from Meta’s Self-Improving Memory blog post.

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.

Four memory designs, and the best one changes per task

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 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.

On the left, a table of the three tasks with one example each: Database, answer a question with SQL queries; Codebase, fix a repo issue with terminal commands; Spectrum, find occupied channels from radio scans. On the right, a bar chart titled No single memory representation wins, with five bars per task for the Generic, Summary, Retrieval, Skill and Hypothesis designs. A marker sits on a different design for each task.

The three tasks, with one example each, and the score of each memory design per task. The marker shows the best design, and it’s a different one for each task. Figure from Meta’s Self-Improving Memory blog post.

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.

Letting the model learn its own memory design

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.

Diagram of the Discover stage. A stack of LOAD and OFFLOAD prompt pairs, shaded by score, feeds a box named meta agent, which outputs a new LOAD and OFFLOAD pair drawn with a dashed outline. An arrow sends that new pair back into the stack.

The Discover stage: the pool of LOAD and OFFLOAD pairs goes to the meta agent, which proposes a new pair that goes back into the pool to be scored. Figure from Meta’s Self-Improving Memory blog post.

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!

What the loop looks like on the repo-fixing task

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.

Four columns for the Codebase task. Generic, no strategy, scores 33.5. Hand-written Summary scores 34.3, and its report says every run kept a single file that grew linearly. Iteration 1 shows a better revision at 52.2 that reuses the recorded repository path and adds a rule after each failure, and a weaker revision at 36.6. Iteration 2 shows the best revision at 55.7, with a short quickstart, a table that maps each symptom to its fix and one file per fix.

The LOAD and OFFLOAD prompts on the Codebase task, from the generic version to the best revision, with their scores and the meta agent’s report between each rewrite. Figure from Meta’s Self-Improving Memory blog post.

What the model’s own prompts get you

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!

Grouped bar chart of test scores for Database, Codebase, Spectrum and their average, with five bars each: No memory, Compaction, Generic, Best human-written and Optimized. On average, No memory scores 20.4, Compaction 37.1, Generic 36.1, Best human-written 44.6 and Optimized 56.0.

Test scores per task and on average for no memory, compaction, the generic prompt, the best human-written prompts and the prompts the model optimized itself. Figure from Meta’s Self-Improving Memory blog post.

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.

Training the model on its own best runs

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!

Diagram of the Demonstrate and Distill stages. In Demonstrate, a run made with optimized LOAD and OFFLOAD prompts sits above the same run where the two prompts are replaced by generic ones. In Distill, the run with generic prompts is used to train the model, with the loss marked under the agent's own responses.

Demonstrate and Distill: the optimized LOAD and OFFLOAD prompts are replaced by the generic ones, the responses stay the same, and the model is trained on its own responses. Figure from Meta’s Self-Improving Memory blog post.

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.

Grouped bar chart of test scores for Database, Codebase, Spectrum and their average, with three bars each: No SFT, SFT on generic trajectories and SFT on optimized trajectories. On average, No SFT scores 36.1, SFT on generic trajectories 37.6 and SFT on optimized trajectories 43.1.

Test scores with the generic prompt only: the base model, the model fine-tuned on its generic runs, and the model fine-tuned on its runs with optimized prompts. Figure from Meta’s Self-Improving Memory blog post.

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!

What’s new here, and what isn’t

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, Co-Harness and Harness-Zero, 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.

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.

What to take from this

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 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!

Discussion

Comments

Loading

No account needed. Your name and comment will be public, so do not include private information. See the privacy page for details.

Keep learning

Want the practical side of AI, without the hype fog?

I share the useful parts on YouTube, Substack, and the AI engineering guides.

FAQ

What is Self-Improving Memory?

It's research from Meta's RAM team, published as a blog post in November 2026. A model first rewrites the prompts that manage its own memory and keeps the versions that score best, then it is fine-tuned on the runs it produced with those prompts. The same model, Kimi K2.6, plays both the agent and the meta agent that rewrites the prompts.

What is harness optimization?

It's the first step. The agent's harness has two memory prompts: LOAD, sent before each sub-task, says what to read, and OFFLOAD, sent after it, says what to save. A meta agent reads the message histories, the scores and the memory folder from past runs, finds the recurring failures and rewrites both prompts. Every rewrite is scored, and the four best become the parents of the next round.

What is harness distillation?

It's the second step. The model runs the tasks once with its best prompts and every call is logged. The optimized prompts are then swapped back to the generic ones while the responses stay exactly as they were, and a LoRA fine-tune teaches the model to act as if it had the good prompt while only seeing the short one.

Which memory design works best for AI agents?

It depends on the task. Meta compared a running summary, retrieval (RAG), a skill library and hypothesis tracking on three tasks, and no single design won on all three. Test them on your own task instead of picking one by default.

Did the model's own prompts beat hand-written ones?

On these three tasks, yes. Averaged over the tasks, no memory scored around 20, a generic prompt 36.1, the best hand-written prompts 44.6 and the model's own prompts 56.0. These are best-observed scores, on three tasks, with one model.

Does this mean AI is now improving itself on its own?

No. It's a blog post with no paper linked yet, on three tasks and one model, and the fine-tuned model keeps only part of the gain. It also needs an evaluation you trust to score every rewrite. So it isn't proof that models are now self-evolving, but it's a very interesting signal for memory management.

What can I reuse from this in my own agents?

Log your agent's full runs and its memory folder after each task. Turn failures into rules, written as if-then statements. And only with an eval you trust, let a model propose rewrites of its instructions, score them on tasks it hasn't seen and keep only the winners.