Field Notes

Put Key Context at the Edges

Context EngineeringProduction AIAI AgentsRetrieval
Trida AI·
Share
Put Key Context at the Edges

Most pipelines never actually decide the order of the context they send a model. The order just happens: system prompt, retrieved chunks in similarity order, history, question. Then the team debugs the model when the answer ignores a passage that was sitting in the prompt the whole time, fourteenth of sixteen, exactly where nobody would look for it either. Where a fact sits inside a long context changes whether the model uses it, and the difference is large enough that placement deserves the same engineering attention as selection.

The evidence for this is not folklore. In Lost in the Middle, Liu and colleagues moved the one passage that answered a question through documents of different lengths and positions. Performance was often highest when the passage sat at the beginning or the end of the context and fell away when it sat in the middle, in some settings below what the model managed with no documents at all. That held even for models explicitly built for long contexts. Length was not the protection people assumed it was.

So our rule for assembling a run is simple to state and easy to skip: decide which pieces of context the answer cannot afford to miss, and put those pieces at the edges. Everything else earns the middle, or doesn't get in.

What counts as an edge piece

Not much. That is the discipline in it.

The task itself belongs at the start, with the hard limits attached to it: the date range that bounds the answer, the customer the run is about, the action the agent is not allowed to take. These are the facts a wrong guess corrupts quietly, because the answer still reads well with the wrong customer name in it.

The decisive evidence belongs at the end, close to the question the model is actually answering. In a retrieval-heavy run that is usually one or two passages, not the full result set: the clause that sets the threshold, the record that carries the current status, the figure the answer will quote. If three passages disagree, the one the answer should follow goes last, with the disagreement named rather than smoothed over.

The middle is for context that helps but cannot hurt much if it is skimmed: background documents, earlier turns summarised down, tool results the agent may consult. Anthropic's guidance on effective context engineering makes the companion point about volume: a model has an attention budget, and every token added spends some of it. Placement and restraint are the same decision seen from two sides. A short context with the decisive passage buried in it can still fail; a long one with background padded around a well-placed answer usually has a different problem, which is cost.

How an assembler places context: decisive pieces go to the start and end slots, background fills the middle, and a position test checks that moving a decisive piece changes the answer in the expected way.
How an assembler places context: decisive pieces go to the start and end slots, background fills the middle, and a position test checks that moving a decisive piece changes the answer in the expected way.

Assembly is a step, not an accident

Most pipelines have no assembly step to speak of. The system prompt goes first because the framework puts it there, retrieved chunks follow in similarity order, the conversation history accumulates behind them, and the user's latest message lands wherever the template leaves it. Nobody chose that order. It is the residue of three components each doing something reasonable on their own.

We would rather see the order chosen in one place, by code that knows the run. An assembler takes the candidate pieces, classifies each as decisive or background, and lays the window out deliberately: task and limits at the start, background compressed in the middle, decisive evidence and a restated question at the end. Classification can start crude. A retrieved passage that the answer will quote is decisive; a passage included because it ranked fourth is background until something promotes it.

That one place is also where the other context decisions become visible. If the decisive set keeps growing past a handful of pieces, the run probably has a selection problem that placement cannot fix. If the background cannot be compressed without losing something the answer needs, that is worth knowing before the run, not after a bad answer.

One run, assembled two ways

Take an example we built for this piece, an order-support agent answering whether a returned item above a value threshold can be refunded without a manager code. Fourteen retrieved passages go in: the returns policy, two warehouse notices, last quarter's policy summary, carrier guidance, and more. One sentence in the current policy sets the threshold. It is the only sentence the answer turns on.

In the first assembly the passages sit in retrieval order and that sentence lands ninth, between a carrier notice and a superseded summary that names a different threshold. In the second, nothing is added or removed. The task and the no-code limit open the window, the background passages sit in the middle with the superseded summary labelled as superseded, and the current policy passage closes the window next to the question.

Example assemblies of one run, same fourteen passages in both. The second changes only the order, and labels the superseded summary instead of leaving two thresholds unmarked.
Example assemblies of one run, same fourteen passages in both. The second changes only the order, and labels the superseded summary instead of leaving two thresholds unmarked.

We are not claiming the second assembly guarantees the right answer. Models vary, and a passage at the end can still be misread. The claim is narrower: the second assembly is testable in a way the first is not. Move the threshold sentence to the middle of your own eval set and watch what happens to the answers. If nothing changes, your context is short enough, or your model robust enough, that placement is not your problem today. If answers degrade, you have found a cheap fix that no model upgrade was going to give you.

Where this stops helping

Placement is a weak tool against bad selection. If the decisive passage was never retrieved, no ordering rescues the run, and edge placement can make a retrieval gap harder to spot because the answers get more confident on the evidence that did arrive.

It also decays inside a long run. An agent that works for forty turns assembles its context again at every step, and tool results pile into the middle whether anyone planned it or not. The edge rule has to be re-applied as the window is rebuilt, which is an argument for the assembler being code that runs each turn, not a template someone arranged once.

And there is a real tension with caching and with honesty about the middle. Compressing background to protect the edges can strip the qualifications attached to a claim, and a team that learns to game position may start demoting inconvenient evidence to the middle rather than answering it. Placement should follow how much the answer depends on a piece of context. The moment it follows how much the team likes the piece, it has become a way to steer the model past its own evidence, and the evals will eventually say so.

Work with us

If your agents read everything you give them and still miss the one clause the answer turned on, the fix may be in how the context is assembled rather than in a larger window. Bring the run to Trida AI's intake and we will look at what your assembler is doing with the pieces that matter most.