---
title: "What is context engineering? | Snowplow Signals"
description: "Context engineering is deciding what an AI agent has in its context window at each step. What goes in, the main techniques, and how it fails."
source: https://signals.snowplow.io/learning/ai-agents-and-memory/what-is-context-engineering
---

[Learning](https://signals.snowplow.io/learning) / [AI agents and memory](https://signals.snowplow.io/learning/ai-agents-and-memory) 

# What is context engineering?

Context engineering is the work of deciding what information an AI agent has in its context window at each step, and getting it there in a shape the model can use. It covers instructions, tools, retrieved documents, memory, conversation history and live state about the user. For agents, it decides more of the answer than the wording of the prompt.

By [Alex Dean](https://signals.snowplow.io/blog/authors/alex-dean) Updated Oct 28, 2026 

## Where does the term come from?

Context engineering is the practice of filling an agent’s context window with the information it needs for the step in front of it, and leaving out what it does not. The model can only reason over what is in that window, so whoever assembles the window decides most of what the agent knows.

The term caught on in June 2025\. Shopify’s CEO Tobi Lutke [wrote](https://twitter.com/tobi/status/1935533422589399127) that he preferred “context engineering” over prompt engineering, because it describes “the art of providing all the context for the task to be plausibly solvable by the LLM.” Andrej Karpathy [agreed](https://twitter.com/karpathy/status/1937902205765607626), calling it “the delicate art and science of filling the context window with just the right information for the next step.” Simon Willison [collected both](https://simonwillison.net/2025/Jun/27/context-engineering/)and the term spread from there.

Two longer pieces gave it structure. LangChain’s [Context engineering for agents](https://www.langchain.com/blog/context-engineering-for-agents)sorted the techniques into four groups, and Anthropic’s [Effective context engineering for AI agents](https://www.anthropic.com/engineering/effective-context-engineering-for-ai-agents)defined it as “the set of strategies for curating and maintaining the optimal set of tokens (information) during LLM inference.” “Agentic context engineering” is the same idea applied to agents that run over many steps, where the window is rebuilt on every call.

## What goes into an agent’s context?

Everything the model reads on a call counts as context. For a typical agent that means:

1. **Instructions.** The system prompt: the agent’s role, its rules, the format it answers in.
2. **Tools.** The names, descriptions and parameters of the tools it may call, and the results of the calls it has made so far.
3. **Retrieved documents.** Help articles, policies, product records, pulled in because they match the question.
4. **Memory.** What the agent kept from earlier sessions, such as a preference the user stated or a decision already made. See [what is agent memory](https://signals.snowplow.io/learning/ai-agents-and-memory/what-is-agent-memory).
5. **Conversation history.** What the user and the agent have said in this session.
6. **Live state.** What is true about the user and the situation right now: the page they are on, what they did before they asked, a step that failed. This is [agentic context](https://signals.snowplow.io/learning/ai-agents-and-memory/what-is-agentic-context) in the narrow sense.

The first five are about the task and the words. The sixth is about the person, and it is the one most agents are missing, because nobody typed it into the chat. The rest of the [AI agents and memory](https://signals.snowplow.io/learning/ai-agents-and-memory) topic covers each part in more depth.

## What are the main context engineering techniques?

Most of the work is choosing, trimming and arranging. LangChain’s four groups are a useful map, with two additions that matter for customer-facing agents.

* **Selecting.** Pull in only what the step needs: the two relevant policy pages, the tools for this task, the memories that match this user. More is not better.
* **Compressing.** Summarize or trim what has grown long. Anthropic calls one version of this compaction: when the window fills, summarize it and continue from the summary.
* **Ordering.** Put the instruction and the most relevant facts where the model weighs them, and drop stale turns rather than letting them pile up in the middle.
* **Isolating.** Give sub-agents their own clean windows for subtasks and pass back a short result, so one agent’s exploration does not clutter another’s.
* **Retrieval.** Fetch documents or records at the moment they are needed, by search or a tool call, instead of loading everything up front.
* **Memory writes.** Decide what to save for later, and in what form. A note written now is context someone else selects next week.

## How is context engineering different from prompt engineering and RAG?

They overlap, and context engineering is the widest of the three. Prompt engineering works on the instruction. RAG is one technique for one kind of context. The comparison with prompt engineering has its own page: [context engineering vs prompt engineering](https://signals.snowplow.io/learning/ai-agents-and-memory/context-engineering-vs-prompt-engineering).

|                     | What it works on                                                                      | The question it answers               |
| ------------------- | ------------------------------------------------------------------------------------- | ------------------------------------- |
| Prompt engineering  | The wording of the instruction, examples and output format                            | How should I ask?                     |
| RAG                 | Documents retrieved by similarity to the query                                        | Which stored text is relevant?        |
| Context engineering | Everything in the window: instructions, tools, documents, memory, history, live state | What should the model know right now? |

A well-worded prompt over stale or missing state still guesses. RAG over a knowledge base will find the returns policy, but it cannot tell the agent that this customer has been on the returns page three times this visit, because that fact is not in any document.

## What goes wrong when context is engineered badly?

The failures fall into three kinds.

**Too much context.** Anthropic describes context rot: as the window grows, the model’s ability to recall what is in it falls, so context behaves like a budget with diminishing returns. LangChain points to Drew Breunig’s [list of how contexts fail](https://www.dbreunig.com/2025/06/22/how-contexts-fail-and-how-to-fix-them.html), including distraction, where a long history pulls the model away from the task, and clash, where two parts of the context disagree.

**Stale state.** The context describes a situation that has moved on. A profile loaded last night says the basket is empty, and the customer added three items an hour ago. The agent answers correctly for a customer who no longer exists. This is the case made in [why AI agents need real-time context](https://signals.snowplow.io/learning/ai-agents-and-memory/why-ai-agents-need-real-time-context).

**Missing state.** The agent has no view of what the user did. It opens with “how can I help?” and the customer explains what the site already recorded.

The first is fixed by removing things. The other two are fixed by adding the right thing.

## Example: what a support agent should see when a customer asks

A shopper on a clothing store opens the chat and types “your discount isn’t working.” Here is what the context for that call should contain, and what it should leave out.

* **Instructions.** The agent may explain why a code was rejected and can offer a named alternative for eligible customers. It cannot issue new codes.
* **Tools.** Look up a promotion’s terms, look up an order, hand over to a person.
* **Retrieved documents.** The terms of the promotion currently running, not the whole promotions archive.
* **Memory.** The customer said in a past chat that they prefer email updates.
* **Conversation history.** One message so far.
* **Live state.** Codes were rejected three times in this visit, the basket holds sale items, and the customer is on the payment page.

Leave out the full order history and every past chat transcript. They cost tokens on every call and say nothing about this question.

The live state is the part to engineer most carefully, because the customer will not supply it. Defined as an attribute, a value computed from events about one key, the rejection count could look like this, keyed on the session so the chat can read it the moment it opens:

```
from snowplow_signals import Attribute, Event, StreamAttributeGroup, domain_sessionid

promo_code_rejected = Event(name="promo_code_rejected", vendor="com.example", version="1-0-0")

promo_rejections_session = Attribute(
    name="promo_rejections_session",
    type="int32",
    events=[promo_code_rejected],
    aggregation="counter",
    default_value=0,
)

shop_support_promo = StreamAttributeGroup(
    name="shop_support_promo",
    version=1,
    attribute_key=domain_sessionid,
    owner="you@example.com",
    attributes=[promo_rejections_session],
)
```

With that value in context and the promotion terms beside it, the agent can open with the answer: the code excludes sale items, and these are the items it applies to. Without it, the agent asks which code and what happened, and the customer types it all out again.

## Where the live behavioral state comes from

Instructions, tools and documents are yours to write. Memory frameworks handle what the user said. The live behavioral state has to come from the events the user generates as they browse, computed and readable at the moment the agent calls. You can build that yourself on an event stream, or use a service for it. Snowplow Signals is one option: it collects behavioral events, computes attributes like the one above, and serves an agent the customer’s recent activity as JSON or a short narrative over a REST API or an MCP server. What the agent does with it stays in your code.

## Put it to work

* [Agentic context on Signals →](https://signals.snowplow.io/products/agentic-context)

## See it on your own traffic 

Add the SDK, define one attribute, and see an attribute updating against your own traffic in the first session. The free tier runs on the real engine: no card, no sales call.

[Start free](https://signals.snowplow.io/start) [Talk to an engineer](https://signals.snowplow.io/start?intent=engineer) 

More explainers in the [Learning Center →](https://signals.snowplow.io/learning)
