Context engineering vs prompt engineering
Prompt engineering is writing the instruction a model follows, its wording, examples and output format, fixed before the agent runs. Context engineering is choosing what the model reads on each call, assembled at run time from documents, tool results, memory and the user's current state.
What is the difference between context engineering and prompt engineering?
Context engineering vs prompt engineering comes down to what you change. Prompt engineering changes the instruction: the words, examples and output format a model is given, written once and reused on every call. Context engineering changes the information: what the model reads on this particular call, assembled at run time from documents, tool results, memory and the state of the user. The prompt decides how the model answers. The context decides what it knows when it answers.
Anthropic draws the line in the same place. Its guide to context engineering describes prompt engineering as “methods for writing and organizing LLM instructions for optimal outcomes,” and says context engineering “is iterative and the curation phase happens each time we decide what to pass to the model.” LangChain’s post on the rise of context engineering goes further and calls prompt engineering “a subset of context engineering.”
Where the term came from, and the full list of what goes into a context window, are covered in what is context engineering. This page is about the difference in practice: who does each, when, and how each one breaks.
How do they compare side by side?
| Prompt engineering | Context engineering | |
|---|---|---|
| Unit of work | A prompt template: system prompt, examples, output format | The code that builds the window: retrieval, tool results, memory reads, state lookups, trimming |
| When it happens | At design time. The text is the same on every call | At run time, on every call. The window differs by user and by step |
| Who does it | Whoever owns the agent’s behavior, often with a domain expert writing examples | Engineers who own the data the agent reads: search indexes, memory stores, event data, APIs |
| What it optimizes | Instruction following: tone, format, policy, the steps the model takes | Grounding: the facts the model needs are present, current and few enough to use |
| How it fails | Vague or conflicting instructions, examples the model copies too literally, format drift after a model upgrade | Missing facts, stale state, too much text, two sources that disagree |
| How you test it | A fixed set of inputs scored against success criteria, rerun when the prompt or model changes | Read the assembled window in traces, and test across realistic user states, including empty and out-of-date ones |
| Typical tools | Playgrounds, versioned prompt templates, eval suites | Vector search, memory stores, tracing, event and attribute APIs, MCP servers |
The testing row is the one teams underestimate. OpenAI’s prompt engineering guide recommends pinning model snapshots and “building tests and evaluation suites that measure prompt behavior.” That works because a prompt eval holds the inputs fixed and varies the prompt. A context failure shows up only when the inputs vary: the customer with no history, the one whose basket changed a minute ago. Tracing tools such as LangSmith show the exact inputs the model received, and that is usually where a context bug becomes visible.
What does the difference look like on one customer question?
A shopper on an electronics store has spent ten minutes moving between two laptops, opened the spec comparison for them, and read the returns policy. Then they open the chat and type “which one should I get?”
With prompt engineering only, the team works on the system prompt until the agent behaves well:
You are the shopping assistant for Northfield Electronics.
Be concise and friendly. Recommend at most two products.
If the request is ambiguous, ask one clarifying question before
recommending. Never invent specifications.
The context window on this call holds that prompt and one user message. The reply is polite and correct, and it is the best the prompt can do:
Happy to help. Which laptops are you deciding between, and what
will you mainly use it for?
The customer now types out what the site already recorded.
With context engineering added, the system prompt stays the same. Before the call, the application reads the session and adds a short block to the window:
Customer session (this visit):
- Viewed: Aero 14 (three times), Vela 15 (twice)
- Opened the spec comparison: Aero 14 vs Vela 15
- Read the returns policy
- Basket: empty
Product facts:
- Aero 14: lighter, longer battery life, integrated graphics
- Vela 15: larger screen, dedicated graphics, heavier
The reply:
Between the Aero 14 and the Vela 15: the Aero is the easier one to
carry every day, and the Vela suits gaming or video editing. Which
matters more to you? Both are covered by the returns policy you read.
Not a word of the prompt changed. The answer improved because the model knew what “one” referred to, and the clarifying-question rule from the prompt still did its job: it asked a better question.
The session block is the part to build with care, because the customer will not type it. Defined as an attribute, a value computed from events about one key, the list of products viewed in this visit could look like this in the Signals Python SDK:
from snowplow_signals import Attribute, EntityProperty, Event, StreamAttributeGroup, domain_sessionid
product_view = Event(name="product_view", vendor="com.example", version="1-0-0")
products_viewed_session = Attribute(
name="products_viewed_session",
type="string_list",
events=[product_view],
aggregation="unique_list",
property=EntityProperty(vendor="com.example", name="product", major_version=1, path="name"),
)
shop_assistant_session = StreamAttributeGroup(
name="shop_assistant_session",
version=1,
attribute_key=domain_sessionid,
owner="you@example.com",
attributes=[products_viewed_session],
)
When is prompt engineering still the right lever?
When the model has the information it needs and still handles it badly. Typical cases:
- Format. The output breaks a parser, misses a JSON field, or runs too long for a chat bubble.
- Tone and policy. The agent apologizes too much, offers what it may not, or refuses what it may do.
- Procedure. The task has a fixed order, such as checking eligibility before quoting a price, and the model skips steps.
- Examples. Anthropic calls few-shot prompting “a well known best practice,” and a good example often fixes a format problem faster than more instructions.
- Self-contained tasks. Classifying a ticket or summarizing a document, where the input arrives whole with the request and there is nothing to assemble.
Prompt engineering has its own limit too. Anthropic’s prompt engineering overview notes that “not every success criterion or failing eval is best solved by prompt engineering,” and that latency and cost are sometimes easier to fix by choosing a different model.
A quick way to decide is to read the trace. If the fact the model needed was in the window and the answer was still wrong, work on the prompt. If the fact was missing, out of date or buried under unrelated text, no rewording will supply it. LangChain’s post argues the second case is the more common one as models improve.
How do the two work together?
The prompt and the context are written separately and read together, so each depends on the other.
- The prompt tells the model how to use the context. A line such as “The session block describes this visit. Prefer it to assumptions, and if it is empty, ask” stops the model from ignoring the block or treating it as something the customer claimed.
- The context decides which instructions can apply. “Offer free returns to members” is dead text unless membership is in the window when the question arrives.
- Each needs a stable shape. Version the prompt template and the format of the context block, so a change to either shows up in review and in your evals.
- Test them as a pair. Rerun the same evals over a spread of realistic states: a first-time visitor, a returning customer, an empty session, a profile from yesterday.
Conversation history sits on the line between the two. It is context, assembled per call, and also the agent’s short-term memory; short-term vs long-term agent memory covers how it differs from what persists across sessions. The structured picture of what the user is doing now is agentic context.
Where Signals fits
The prompt is text you write, and documents and conversation history are things you already
hold. The live session state in the example has to be computed from what the customer does as
they browse, and be readable at the moment the agent calls. You can build that on your own
event stream, or use a service. Snowplow Signals is one option: it collects behavioral events,
computes attributes like products_viewed_session, and serves an agent the customer’s recent
activity as JSON or a short narrative over a REST API or an MCP server. The prompt, and what the
agent does with the context, stay in your code. The rest of the
AI agents and memory topic covers memory, context and real-time
state in more depth.
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.