Your agent's prompt is fine. What it reads is the problem
The returns policy was in the context all along, buried under chat history, order tables and FAQs, so choosing what the model sees is the skill to learn.
In brief
- Stuffing more data into the context does not make a model smarter: the longer the context, the worse the model recalls what is in it.
- The prompt decides what the model does, the context decides what it knows while doing it, and with client data the context is the main lever.
- Keep lightweight references, load data only when needed, put data in a clear structure and summarize history before you hit the window limit.
In your second week at a client site, the order-support agent that ran smoothly in the demo starts getting the returns policy wrong on real data. The odd part is that the policy file is right there in the context, alongside the chat history, three tables of order data and the full FAQ.
Many engineers reach first for the prompt: more capital letters, an extra “read the policy carefully”. It rarely helps. How you talk to the model was never the issue; what the model has to read is.
The skill that fixes the right thing is called context engineering, and every FDE who works with client data needs it.
The prompt says “what to do”; the context decides “what it knows”
“Read the policy carefully” changes only how you speak to the model. It does nothing about the fact that the model is reading a policy file mixed in with chat history, order tables and FAQs. Elastic draws the line here: prompt engineering handles the communication, while context engineering handles what information the model can reach when it generates an answer.
Prompt engineering takes the context window as given; context engineering actively curates it. For the returns agent, curation means deciding whether the three order tables go in at all, and whether to include the whole FAQ or just a few passages.
Anthropic describes this as curating and maintaining the optimal set of tokens during model inference, while the Prompting Guide stresses designing both the instructions and the context that accompanies them.
That is why DataHub treats prompt engineering as one component of context engineering: the prompt tells the model what to do, and the context decides what it knows while doing it. When an agent goes wrong at a client, the first question should be “what did the model see at this step?” Rewriting the prompt can wait.
Why does adding more data make the agent worse?
Intuition says that the more client data you give a model, the better it understands the situation. Anthropic points to the opposite: as context grows longer, the model’s ability to accurately recall information within it declines, a phenomenon it calls context rot. In its account, an LLM has an “attention budget” that gets used up as it reads large amounts of context.
Go back to the returns agent. The policy file is in the context, but it has to compete for attention with dozens of old chat turns and thousands of order rows that have nothing to do with the question. The model is not broken. It is diluted.
LangChain, citing Andrej Karpathy, describes context engineering as the art and science of filling the context window with just the right information for the next step. The key words are “next step”. Context is reassembled for every step; it is never a fixed store loaded once at startup.
Four questions before every model call
LangChain groups context engineering strategies into four buckets: write, select, compress and isolate. They work well as a checklist when designing an agent for a client.
The names are LangChain’s; what follows is one way to apply the four buckets to a client’s agent. Write, read this way, means saving information outside the window to reuse later, close to the memory that the Prompting Guide places within context engineering: short-term memory (managing state and history) and long-term memory.
Select means pulling in only the data relevant to the step being run. Compress means shrinking what is already there, for instance through the compaction described below. Isolate, as this checklist reads it, means splitting the work so that each part carries only its own context.
Two concrete techniques from Anthropic cover select and compress. The first is just-in-time retrieval: the agent keeps only lightweight identifiers, such as order IDs or document paths, and loads the real data when it needs it, instead of preloading everything.
The second is compaction: when a conversation nears the window limit, summarize its contents and continue with the summary.
Rebuilding the returns agent, line by line
Here is how the returns agent’s context is assembled after applying the checklist. The code is an illustrative sketch, but the structure can be used for real.
def build_context(ticket, state):
blocks = []
# Fixed, short instructions, kept separate from data
blocks.append(("instructions", RETURN_AGENT_RULES))
# Write: read the progress notes instead of the full history
blocks.append(("progress_notes", state.notes))
# Compress: replace a long history with a summary
history = state.history
if count_tokens(history) > HISTORY_LIMIT:
history = summarize(history)
blocks.append(("conversation", history))
# Select: only the policy passages that match the ticket
blocks.append(("policy", search_policy(ticket.text, top_k=3)))
# Just-in-time: pass only the ID, let the agent call a tool for details
blocks.append(("order_ref", {"order_id": ticket.order_id}))
return render_with_tags(blocks)
The first change is that the order tables disappear from the context. The agent sees only order_id, and when it genuinely needs a delivery date or payment status, it calls the tool get_order(order_id) to fetch that one record. Thousands of irrelevant rows no longer compete with the policy file for attention.
The second change is structure. The Prompting Guide lists structuring input and output, with delimiters or JSON schemas, as a component of context engineering. The render_with_tags function wraps each block in its own named tag, such as policy or conversation, so the model can tell system rules from what the customer said and from system data.
The output should have a schema too, for example {"decision": ..., "policy_clause": ...}, so you can check which clause the agent relied on.
The third change is isolation. If the agent has to both look up the policy and draft an email to the customer, split those into two steps, each with its own context. The email step needs only the final decision and the brand’s tone of voice, not ten pages of policy.
At the client, start with the log
Before changing anything, capture the exact context the model received on the call that went wrong. Reading that log is the fastest way to check two possibilities: the needed information was buried in the pile, or it was missing entirely.
Next, for each step of the agent, write one line describing what that step needs to know to get it right. Every block in the context must answer the question “which line does this block serve?”. Any block that cannot is the first candidate to drop, or to turn into a just-in-time reference.
Finally, measure. Each time you change the context, rerun the same eval set and record two numbers: accuracy and the average tokens per call. Those two numbers are what persuade the client, and they belong on your CV.
A line such as “redesigned the context for an order-support agent, cutting tokens per call while holding eval scores steady” carries far more weight than “experienced in prompt engineering”.
The mistakes that keep recurring
The most common mistake is fixing the prompt when the problem is the context. If the model cannot see the right clause, no instruction, however well written, will save it.
The next is letting conversation history grow without limit, until the agent starts forgetting what the customer said at the start. That is the moment for compaction: summarize the history before hitting the window limit, instead of waiting for the agent to forget.
The third is letting tools return raw records. A client API returns JSON with hundreds of fields, and it gets passed straight into the context because that is convenient. Write a thin layer that keeps only the fields the step needs.
The fourth is mixing data with instructions without delimiters, which makes it hard for the model to separate system rules from content the customer sent in.
At a client site, there is always more data than a model can attend to. The FDE’s job is to decide which parts go in, and to own that decision as they would any other piece of code.
Was this article useful?
Thanks for the feedback!
5 sources
- Effective context engineering for AI agents · 2025-09-29
- Context Engineering Guide
- Context engineering vs. prompt engineering · 2026-01-20
- Context Engineering vs. Prompt Engineering · 2026-04-20
- Context Engineering for Agents · 2025-07-02