Concepts/Concept

The Memory Envelope: The Context Package Injected to the Model at Each Step

From the Dongfang Yiteng execution agent (case by Bo Liang)

The Memory Envelope: The Context Package Injected to the Model at Each Step

Definition

Every reasoning step of an execution-type agent first assembles an input struct before handing it to the model. In Dongfang Yiteng's code this struct is called ReasonContext; the name ADPS gives it is the memory envelope — at every step you seal an envelope and hand it to the model, and it holds only what this step needs to see.

An envelope usually holds four things: the anchor, the original goal of the user session; the current progress (collection) projected and trimmed out of the ledger; the conclusion drawn by upstream intent recognition; and the relevant lessons recalled from the experience store. When needed, it also attaches the necessary mechanical state. Once this package is assembled, the model at this step knows where it is going, how far it has come, and what mistakes others made in similar spots. What goes into the envelope is narrative content, the semantics the model is to understand; the control signals the program branches on travel through a separate channel and do not enter the envelope.

How it works

What the memory envelope guards against is two kinds of distortion in a long chain. The first is goal drift: the execution chain receives the original request at the entry point and runs it through reasoning, action, and task planning, with the information reworked, expanded, or compressed as it is passed down. If the context simply takes the previous step's output as the next step's input, fed straight down a single-pass chain, then over a long enough path the original goal's share is diluted. By the task-planning stage, what is fed to the model to generate a plan may consist mostly of the trains of thought from the reasoning process, with what the user actually wants reduced to a fraction. The most typical case is when the user replies with nothing but "continue" in a new turn: without the anchor, the model either cannot understand what "continue" means or acts wildly on its own interpretation. Fix the anchor into every envelope, and this kind of distortion is blocked.

The second is context overflow. Even as a distilled progress summary, the ledger still piles up a great deal of content over a long chain, and the full record cannot be stuffed into the prompt. The memory envelope's approach is to project just once, at the key reasoning entry points: based on the scenario being handled at that moment, it trims a temporary working set out of the ledger and puts it into the envelope, rather than dumping all of history on the model at once.

The payroll-setup scenario at Dongfang Yiteng shows clearly how this envelope is used. The task is broken into several steps, completed in relay by different reasoning and action stages. When a given reasoning step's turn comes, what is assembled into ReasonContext is not every detail of all preceding steps, but the trimmed key milestones plus the ever-present original goal. Most of the details produced by earlier steps are irrelevant to the current one; the envelope keeps only the key results relevant to the task at hand, picking out and sealing in what this step needs to see before handing it to the model.

When you need it

When your agent has a long execution chain, and each reasoning step has to choose what to feed the model from among the original goal, the current progress, and past experience, rather than mindlessly concatenating the entire history into the prompt. What it holds comes from anchor, ledger, collection, the sources it draws on span layered memory L1/L2/L3, and the act of sealing the envelope itself can be understood as a downstream link of intent as compilation.


This is an ADPS blue-book concept. Back to Concepts or the pattern matrix.