SWE-MeM: Learning Adaptive Memory Management for Long-Horizon Coding Agents
SWE-MeM is a training framework that equips software engineering agents with adaptive, on-demand memory management capabilities through a flexible tool and Memory-aware GRPO, enabling them to dynamically optimize context usage and achieve superior performance on long-horizon coding tasks compared to existing static methods.
Original paper licensed under CC BY 4.0 (http://creativecommons.org/licenses/by/4.0/). This is an AI-generated explanation of the paper below. It is not written or endorsed by the authors. For technical accuracy, refer to the original paper. Read full disclaimer
The Problem: The "Too-Much-Info" Traffic Jam
Imagine you are a brilliant software detective (an AI agent) hired to fix a bug in a massive, complex building (a code repository). You start your investigation, but as you work, you leave a trail of notes, photos, and recordings of every single step you take.
- The Issue: In the real world, these "notes" (the conversation history) keep piling up. Eventually, the pile becomes so huge that it blocks the door. Your detective brain (the AI model) has a limited amount of space to look at things at once (the "context window"). If the pile gets too big, you either can't see the new clues, or you get so overwhelmed by old, irrelevant details that you forget what you were actually trying to solve.
- The Old Way: Previous methods tried to solve this by being rigid. They were like a strict librarian who says, "Every time you write 100 pages, I will automatically throw away the first 50 pages and replace them with a generic summary." This is bad because sometimes the first 50 pages contain the only clue you need, and sometimes the last 50 pages are just you complaining about the weather (which you can safely throw away).
The Solution: SWE-MeM (The Smart Personal Assistant)
The authors created SWE-MeM, a new training framework that teaches the AI agent to be its own smart personal assistant. Instead of a rigid librarian, the agent learns to manage its own memory proactively.
Here is how it works, broken down into three simple parts:
1. The Flexible Tool (Deciding When and What)
SWE-MeM gives the agent a special tool called compress. The agent learns to ask itself three questions before using it:
- When? Do I need to clean up now? (Is my desk getting too messy?)
- What? Which parts of my notes are junk? (Is this a long list of failed test attempts, or is it a critical code snippet?)
- How? How do I summarize this? (Do I just keep the conclusion, or do I keep the specific error message?)
Analogy: Imagine you are writing a diary. A rigid system deletes the first page every time you write a new one. SWE-MeM is like a smart editor who looks at your diary and says, "Hey, you spent three days just staring at a blank wall (low value). Let's summarize that as 'Day 3: Stuck.' But you found the broken pipe on Day 5 (high value). Let's keep that detail exactly as is."
2. The Training Method (Learning by Doing)
How do you teach an AI to be this smart? You can't just tell it; it has to practice. The authors used a three-step training process:
- Synthesizing Trajectories (The Simulation): They created thousands of fake "detective cases." They used a super-smart AI to act as a judge, deciding when the detective should have cleaned up its notes. They built a dataset where the agent practices compressing the right things at the right times.
- Curriculum Learning (Schooling): They taught the agent in stages. First, they taught it the basics: "Here is how you write a summary." Once it got that, they moved to the advanced class: "Now, learn to summarize before you run out of space, not just when you are forced to." This is like teaching a student to pack a suitcase before the trip, rather than waiting until the bag is bursting.
- Memory-Aware GRPO (The Reward System): This is the most technical part, but think of it as a video game scoring system.
- In normal training, the AI only gets a "Win" point if it fixes the bug at the very end.
- In SWE-MeM, the system looks at the whole journey. If the AI made a great compression decision in the middle that helped it solve the problem later, it gets a bonus point. If it compressed something important and got stuck, it gets a penalty. This teaches the AI that good memory management is part of winning the game.
3. The Results (Winning the Game)
The authors tested SWE-MeM on SWE-Bench Verified, a tough benchmark where AI agents have to fix real-world software bugs.
- The Score: With a small model (4 billion parameters), SWE-MeM solved 43.4% of the problems. With a larger model (30 billion), it solved 60.2%.
- The Efficiency: Not only did it solve more problems, but it also used fewer tokens (words/characters) and took fewer steps than other methods.
- The Comparison: It beat all the previous "rigid librarian" methods. It proved that letting the agent decide when to clean up its memory is much better than forcing it to clean up on a schedule.
Summary
SWE-MeM is like upgrading a detective from someone who frantically shreds papers when the desk gets full, to a detective who knows exactly which clues to keep, which to summarize, and when to tidy up the desk so they can keep solving cases efficiently without running out of space. It teaches the AI to be proactive, flexible, and efficient, resulting in better code fixes with less wasted effort.
Drowning in papers in your field?
Get daily digests of the most novel papers matching your research keywords — with technical summaries, in your language.