← Latest papers
🤖 AI

Context as an Environment: Programmatic Context Management for Long-Horizon Agents

The paper introduces Scroll, a programmatic context management system that treats agent sessions as executable environments with an append-only event log and a persistent Python kernel, enabling LLMs to dynamically manage long-horizon state through code while achieving state-of-the-art performance on long-context benchmarks.

Original authors: Yin Lin, Elaine Ang, Erkang Zhu, Bolin Ding, Jingren Zhou

Published 2026-08-25
📖 6 min read🧠 Deep dive

Original authors: Yin Lin, Elaine Ang, Erkang Zhu, Bolin Ding, Jingren Zhou

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

Imagine a conversation that never ends. You are talking to a very smart computer program, one that can help you write code, plan complex trips, or research deep topics. At first, the conversation is easy. The program remembers everything you have said in the last few minutes. But as the conversation stretches over hours or days, the amount of information grows. Eventually, it becomes too much for the program to hold in its immediate memory. In the world of artificial intelligence, this immediate memory is called a context window. It is a fixed size, like a desk that can only hold a certain number of papers. When the pile of papers gets too high, the program must throw some away to make room for new ones.

The problem is that the program does not know which papers are important until it is too late. If you ask a question about something you mentioned three days ago, the program might have already discarded that paper. Traditional solutions try to solve this by summarizing the old papers into a short note or by picking out a few facts to keep in a separate notebook. But these methods are risky. If the program throws away a specific detail, like a date or a number, that detail is gone forever. It cannot be recovered. For tasks that require looking back at a long history to find exact facts or to track how a situation changed over time, losing even a single detail can cause the program to fail.

A team of researchers has proposed a different way to handle this growing conversation. They call their system Scroll. Instead of trying to fit the entire history into the program's immediate memory, they treat the history as a separate, permanent environment that the program can visit whenever it needs to. Think of it as a vast, organized archive that sits just outside the program's desk. The program does not read the whole archive at once. Instead, it writes a small instruction, like a search query or a command, to go into the archive, find the specific page it needs, and bring just that page back to the desk.

The core of this system is a permanent record of every single interaction, called an Event Log. This log is like a tape recorder that never stops, capturing every message, every tool result, and every decision in exact detail. It is stored safely outside the program's immediate memory, so nothing is ever lost. Alongside this log is a persistent workspace, a kind of digital sandbox where the program can keep its current thoughts and calculations. When the program needs to remember something from the past, it does not rely on a summary. It writes a piece of code to search the Event Log, find the exact moment it is looking for, and load that information into its workspace.

This approach changes how the program thinks about its own memory. Instead of guessing what to keep, the program decides what to look up at the moment it is needed. If the program is planning a trip and needs to remember a preference the user mentioned weeks ago, it writes a command to search for that specific preference. It then loads the exact words the user used and uses them to make a decision. The program only brings the necessary information into its immediate view. The rest of the conversation history remains safely stored in the archive, waiting to be retrieved if the program needs it later.

To keep the immediate view from getting too full, the system has a way to clear out old information that is not currently being used. When the workspace gets crowded, the system moves the oldest parts of the conversation back into the archive. However, unlike other systems that might delete or summarize these old parts, Scroll keeps them exactly as they are. It creates a small map, an index, that tells the program exactly where in the archive those old parts are stored. If the program later realizes it needs to check an old conversation, it can use this map to jump directly to the right spot and retrieve the original text. This ensures that the program can always go back to the source, even if the information is no longer in its immediate view.

The researchers tested this system on several difficult challenges designed to see how well an artificial intelligence can handle long conversations. In one test, the system had to answer questions based on a history of over one million words of conversation. In another, it had to act as an agent that makes decisions over a long period, using tools to gather information and solve problems. The results showed that this new method was highly effective. On a test measuring how well the system could remember and reason over long histories, it achieved a score of 94.8 percent. On another test involving ten million words of history, it scored 73.1 percent, which was higher than any other system previously published. In a test where the system had to manage a growing environment while solving complex tasks, it reached 86.7 percent, far surpassing the best previous results.

The success of this system comes from its ability to treat memory as a programming task. By allowing the program to write its own instructions for finding and using information, the system leverages the program's growing ability to write code. It does not force the program to compress its history into a summary that might lose important details. Instead, it gives the program the tools to access the full, unedited history whenever it is needed. The researchers found that this method works well across different types of powerful programs, suggesting that the ability to manage long-term memory through code is a general skill that can be learned by various systems.

This work suggests a shift in how we build intelligent agents. Rather than trying to make the program's immediate memory larger or better at summarizing, we can give it access to a permanent, searchable record of its own life. The program learns to navigate this record, deciding what to bring forward and what to leave behind. This keeps the immediate view clear and focused, while ensuring that the full truth of the past is always available. The researchers believe that this approach could help artificial intelligence handle even longer and more complex tasks in the future, allowing it to learn from a much deeper history without losing the details that matter.

Drowning in papers in your field?

Get daily digests of the most novel papers matching your research keywords — with technical summaries, in your language.

Try Digest →