GO TO A SECTION

↑ ↓ to navigate · Enter to openExplore all sections →
FDEInterviews logo
← 🤖 Retrieval & Agents
Foundational

Context Window Management for FDE Agents

Managing the context window is the discipline of deciding what an agent sees on every step, run against a customer's private data and their token bill. Forward Deployed Engineers treat the window as a budget to allocate with four moves, write, select, compress, and isolate, because a deployment that ignores it is either too expensive to run or too unreliable to trust.

WATCH THE EXPLAINER3:54
Transcript

In a lab you tune a prompt once and move on. At a customer, the same agent loops for dozens of turns per task, and every tool call appends its output and every turn appends history. Every one of those tokens lands on an invoice someone in procurement is watching. Left alone, the context just keeps climbing.

Take a hypothetical agent. A 3,000-token system prompt, a 2,500-token tool catalog, and each turn adds about 450 tokens of exchange plus a 2,000-token tool result. At turn one the window holds 7,950 tokens. Turn five, 17,750. Turn ten, 30,000. Turn twenty, 54,500. And the twenty turns bill 624,500 tokens in total, because every turn re-reads everything before it.

Now make two changes. Prune each tool result to the 300 tokens the next step uses, and summarize turns older than five into an 800-token digest. Turn twenty now runs on 10,050 tokens, with the last five turns still verbatim. The run bills 189,500 tokens, about a third of the cost. The customer notices the third. The model notices that its instructions aren't buried under forty thousand tokens of tool output.

Those two changes are instances of four moves, and each one is a lever on what actually lands in the window on a given step. Write. Select. Compress. Isolate.

Write means persisting context outside the window instead of carrying it inline. A scratchpad file, an external memory store, or a structured run log holds the state the agent would otherwise re-paste every turn. At a customer, that log doubles as the audit trail a stakeholder can read afterwards, so it earns its keep twice.

Select means loading only what this step needs: retrieval over the customer corpus, tool schemas pulled on demand, and few-shot examples chosen by similarity to the current input. The failure is dumping the whole knowledge base in to be safe. You pay for thousands of irrelevant tokens and bury the passage that mattered.

Compress means shrinking what you keep. Summarize old turns once they fall out of use. Prune a tool's JSON response to the three fields the next step reads. Collapse a retrieved 6,000-token document to the 400 tokens that answer the question. Uncompressed history is the most common reason a long agent run slows down and starts drifting.

Isolate means splitting work so contexts don't bleed. Scoped sub-agents and a separate session for each tenant keep one customer's data out of another's prompt, and a separate window for a noisy tool stops a chatty API crowding out the instructions. In a multi-tenant deployment, that's a data-governance requirement. You design it in from the first customer.

The follow-up interviewers hold in reserve: by turn twenty your agent is slow and answering from stale history. What do you cut? Answer with a budget. 2,000 tokens for the system prompt, 1,500 for the tools, 4,000 for retrieved context, 3,000 for recent turns verbatim, 1,000 for the running summary, and the rest of a 16,000-token target for the reply. The system prompt and the current task never get trimmed.

A budget with numbers is a design. "We manage context carefully" is a hope. Write, select, compress and isolate. The full explainer is on fdeinterviews.com.

TL;DR: A frontier context window is a fixed budget you spend on the customer's token bill, not free space to fill. The FDE job is four moves: write context out to durable storage, select only what the step needs, compress what you keep, and isolate one tenant or tool from another. Get this wrong and the agent is slow, costly, and confidently wrong by turn twenty.

The FDE version of the problem

The context window concept covers what the window is and why input and output share it. This concept is about the harder job on top of that: running an agent thousands of times a day, at a customer, against their data, on their invoice.

In a lab you tune a prompt once and move on. Embedded with a customer, the same agent loops for dozens of turns per task, reads from a private corpus you do not control, and bills every token to an account someone in procurement is watching. A long-running agent's context grows on every step: each tool call appends output, each turn appends history. Left alone it climbs past the point where the model attends well and past the point where finance stops asking questions. Context management is what keeps the deployment both accurate and affordable, which is why it shows up in staff and principal loops as a systems question, not a prompting tip.

The growth is arithmetic before it is a feeling. Take a hypothetical agent with a 3,000-token system prompt and a 2,500-token tool catalog, where each turn adds about 450 tokens of exchange and a 2,000-token tool result. Left alone, the window holds 7,950 tokens at turn 1, 17,750 at turn 5, 30,000 at turn 10 and 54,500 at turn 20; the tokens billed across those twenty turns total 624,500, because every turn re-reads everything before it. Prune each tool result to the 300 tokens the next step uses and summarize turns older than five into an 800-token digest, and turn 20 runs on 10,050 tokens with 189,500 billed across the run, about a third of the cost, with the last five turns still verbatim (all computed). The customer notices the third; the model notices that the instruction it needs is no longer buried under forty thousand tokens of tool output.

The four moves

The working taxonomy is write, select, compress, isolate. Each is a lever on what actually lands in the window on a given step.

Four moves that keep an agent affordable every step 1 A step begins the window is an empty budget 2 Write persist outside the window 3 Select only what this step needs 4 Compress history and tool output 5 Isolate per tenant, per task 6 The model runs on what survived 7 Append the result back to durable storage A scratchpad, a memory store, a run log. Anything the agent may need later belongs outside the window rather than being carried inside it. Top-k from the corpus, plus only the tool schemas this step can actually call. Selection is the difference between a window holding context and one holding history. Left alone, context grows every step: each tool call appends output, each turn appends history. It climbs past where the model attends well and past where finance stops asking questions. One tenant's data must never reach another's window. Scoped sub-agents are that boundary, and it is a security property rather than a tidiness one.

The spine above is the same four moves in the order a single step runs them, with the reason each one earns its place.

rendering diagram…

Write means persisting context outside the window instead of carrying it inline. A scratchpad file, an external memory store, or a structured run log holds the state the agent would otherwise re-paste every turn. At a customer this doubles as the audit trail a stakeholder can read after the fact, so it earns its keep twice.

Select means loading only what this step needs. That is RAG over the customer corpus, tool schemas pulled on demand rather than all at once, and few-shot examples chosen by similarity to the current input. The failure mode is dumping the whole knowledge base into the prompt to be safe: you pay to process thousands of irrelevant tokens and bury the passage that mattered.

Compress means shrinking what you do keep. Summarize old turns once they fall out of active use, prune a tool's JSON response to the three fields the next step reads, and collapse a retrieved 6,000-token document to the 400 tokens that answer the question. Uncompressed history is the single most common reason a long agent run gets slow and starts drifting.

Isolate means splitting work so contexts do not bleed. Scoped sub-agents, per-tenant sessions, and separate windows for a noisy tool keep one customer's data out of another's prompt and stop a chatty API from crowding out the instructions. In a multi-tenant deployment isolation is a data-governance requirement that guardrails enforce, not a performance nicety you add later.

Why interviewers probe this

It is a fast proxy for whether you have run an agent on someone else's bill. A candidate who reaches for a million-token model and stops there has read the spec sheet but never watched a per-turn cost curve. The follow-up interviewers hold in reserve: "your agent's context grows every turn, and by turn twenty it is slow and answering from stale history, what do you cut and in what order?" The strong answer names a per-step budget, compresses history first, selects over the corpus instead of dumping it, and pins the system prompt and the current task so they never get trimmed. Said as a budget: 2,000 tokens for the system prompt, 1,500 for the tools this step can call, 4,000 for retrieved context, 3,000 for the last few turns verbatim, 1,000 for the running summary, and the rest of a 16,000-token target reserved for the reply. Each line has an owner and a trimming rule, and the two that never get trimmed are the first and the current task. A budget with numbers is a design; "we manage context carefully" is a hope.

Common misconceptions

  • "A huge context window means I can stop managing context." Cost and latency scale with tokens processed, so a bigger window is a bigger invoice, not a free pass. You still choose what goes in.
  • "Selection is just RAG." Retrieval over documents is one case. Selection also decides which tools, which memories, and which examples load this step, each of which spends budget.
  • "Isolation is premature optimization." In a multi-tenant customer deployment, keeping one tenant's data out of another's window is a compliance line, not an optimization you defer.
  • "Compression loses information, so avoid it." Carrying every raw turn and full tool dump is what makes long agents slow and unfocused. Summarize deliberately and keep the source in the durable store if you need to reread it.

Key takeaways

  • Treat the window as a per-step budget you allocate, measured against the customer's real token cost, not space to fill because the model allows it.
  • Write state to durable storage, select only what the step needs, compress what you keep, and isolate tenants and noisy tools from each other.
  • The reserve interview follow-up is a long-running agent whose context has bloated; answer with an explicit budget and a compress-then-select order.
  • Isolation in a multi-tenant deployment is a data-governance requirement, so design it in from the first customer, not after the second.

Related concepts

Practise this in questions