← Guides

Context Engineering: What It Is, the Four Core Techniques, and How to Do It for AI Agents (2026)

Context engineering explained for builders and teams: the practice of deciding what an AI model sees at every step (instructions, tools, retrieved data, memory and history). How it differs from prompt engineering, the four techniques (write, select, compress, isolate), common failure modes, a practical checklist, tools with November 2026 prices, and how SPIRITT gives every agent shared company context.

Flat risograph illustration of a smiling engineer and a friendly robot placing a few chosen cards, a document, a wrench and a notebook, into a tidy window frame while spare cards wait sorted in a box, navy and orange on cream

Context engineering is the practice of deciding what an AI model sees at every step of a task: its instructions, the tools it can call, the documents and data retrieved for it, its memory, and the conversation and tool history. Andrej Karpathy described it as "the delicate art and science of filling the context window with just the right information for the next step", and Anthropic frames the goal as the smallest set of high-signal tokens that makes the desired outcome most likely. Prompt engineering words the instructions; context engineering manages everything else. SPIRITT applies context engineering for you: every agent works from shared company context (your apps, docs, decisions and memory), pulls in only what each step needs, and codes, ships and runs the work end to end across 1,500+ apps. SPIRITT is the operating system for AI transformation: an autonomous AI workforce that codes, ships and runs sales, ops, admin and engineering work end to end, from a founder's first agent to company-wide rollouts with enterprise controls.

Why context engineering matters now

A single chat needs a good prompt. An agent that runs for an hour, calls 40 tools and reads 30 documents needs something more: it fills its own context window as it works. Two forces make that the main source of agent failures:

  • Context is finite and degrades. Models recall less precisely as the window fills, a pattern researchers call context rot. A bigger window delays the problem; it does not remove it.
  • Every token costs time and money. Re-sending a 100,000-token history on every step is slow and expensive, and most of it is irrelevant to the next step.

So the agents that work in production are rarely the ones with the cleverest prompt. They are the ones whose builders control what enters the window, when, and in what form.

Context engineering vs prompt engineering

Prompt engineeringContext engineering
QuestionHow should I word the instruction?What should the model see at this step, and what can be left out?
ScopeOne prompt or templateInstructions, tools, retrieved data, memory, history, across every step
WhenWritten before the runDecided during the run, often by the system itself
Typical failureAmbiguous or conflicting instructionThe right fact missing, buried or dropped when it was needed
How to debugRead the promptInspect what was actually in the window at the step that failed

Prompt engineering is part of context engineering: the system prompt is one of the things you place in the window.

What goes into an agent's context

  1. Instructions. The system prompt, rules, examples of good output.
  2. Tools. The definitions of the functions and apps the agent can call. Every tool description takes space and can distract.
  3. Knowledge. Documents, records and search results retrieved for the task.
  4. Memory. Durable facts about the user, the company, preferences and past decisions.
  5. State and history. The current task, previous steps, tool results and messages.

The four core techniques: write, select, compress, isolate

LangChain's widely used framing groups context engineering into four strategies; Anthropic's engineering guidance describes the same moves.

Write: keep information outside the window until needed. Agents take notes, save plans to a file or a to-do list, and store durable facts in long-term memory. The window holds a pointer, not the whole thing. For memory types and tools, see AI agent memory.

Select: pull in only what this step needs. Retrieve the three relevant policy paragraphs instead of the whole handbook; load only the tools this step can use; fetch "just in time" when the agent decides it needs a file, rather than front-loading everything.

Compress: shrink what must stay. Summarize long histories (compaction), clear old tool results that have already been acted on, and trim verbose outputs to the fields that matter.

Isolate: split the work. Give sub-agents their own clean windows for research, coding or review, and pass back only their conclusions. Sandboxes keep large data (a 50MB CSV) in a runtime the agent can query instead of in the window.

Common context failures and their fixes

FailureWhat happensFix
Context poisoningA wrong fact or hallucination enters the window and gets repeatedValidate tool outputs, keep sources attached, let the agent overwrite bad notes
Context distractionThe history grows so long the model leans on it instead of reasoningCompact regularly, start fresh sub-tasks with a summary
Context confusionIrrelevant documents or too many tools pull the answer off courseRetrieve less and better, load tools by route
Context clashTwo sources disagree (old and new policy)Date and rank sources, prefer the system of record, flag conflicts

A practical context engineering checklist

  1. Write the system prompt at the right altitude: clear goals and rules, a few canonical examples, no wall of edge cases.
  2. Keep the tool set small and distinct. If a human cannot tell two tools apart from their descriptions, the model cannot either.
  3. Retrieve with metadata. Source, date, owner and permissions travel with every chunk, so the agent can cite and you can audit.
  4. Respect permissions in retrieval. An agent should never see a document the requesting user could not open.
  5. Plan for long runs. Decide when to compact, what to pin (instructions, IDs, limits) and what to drop.
  6. Use sub-agents for wide tasks and pass back short, structured results.
  7. Log the window. When a run fails, inspect exactly what the model saw at that step. For tracing, see AI agent observability.
  8. Measure. Track success rate, tokens per task and cost per task as you change context rules.

Context engineering tools (November 2026 prices)

ToolRolePrice (US list)
SPIRITTAgents that run on shared company context: connected apps, docs, long-term memory, sub-agents and budgets, with no context plumbing to buildFree to start; Starter $32, Pro $256, Max $1,024 a month; Enterprise custom
Claude APIBuilt-in compaction, context editing (clearing old tool results) and a memory tool for long-running agentsPay per token; Claude Pro for the app is $20 a month ($17 billed annually)
LangChain / LangGraph + LangSmithFramework for building agents with state, memory and sub-graphs; LangSmith for tracing what each step sawDeveloper free (1 seat, 5k traces); Plus $39 per seat a month plus usage
Mem0Memory layer that stores and retrieves user and agent memoriesFree plan (with your own model key after 30 days); custom plans by quote

Prices read on vendor pricing pages and docs on November 25, 2026. Mem0 stopped selling its former $19 and $249 self-serve plans to new accounts in October 2026.

How SPIRITT handles context for you

Building context plumbing (indexes, memory stores, permissions, compaction rules, traces) is real engineering work. SPIRITT ships it as part of the product, so teams get the benefit without building it:

  • Shared company context. Agents work from the same connected apps, docs and decisions, so the sales agent and the support agent agree on the price list.
  • Memory that lasts. Short and long-term memory of people, preferences and decisions, corrected when you correct it.
  • Just-in-time retrieval. The agent searches your connected systems and the web when a step needs it, with sources attached.
  • Isolation built in. Sub-agents and swarms work in their own windows, on their own secure cloud computer, and report back conclusions.
  • Model composition. SPIRITT composes models inside one task, so long-context reading, fast extraction and careful writing each go to the model suited for it, at the optimal mix of capability and price.
  • Governed access. Permissions per integration, keys kept out of the agent's reach, and a full audit trail of what each agent read and did.

FAQ

What is context engineering?

Context engineering is the practice of designing and managing everything an AI model sees on each call: instructions, tool definitions, retrieved documents, memory, conversation history and tool results. The aim is the smallest set of relevant, high-signal information that lets the model do the next step well.

What is the difference between context engineering and prompt engineering?

Prompt engineering focuses on wording the instructions. Context engineering covers the whole input across a multi-step task, including which documents, tools, memories and history are included, compressed or left out at each step. Prompt engineering is one part of context engineering.

Who coined the term context engineering?

The term spread in June 2025 when Shopify CEO Tobi Lütke and Andrej Karpathy endorsed it on X, with Karpathy calling it "the delicate art and science of filling the context window with just the right information for the next step." LangChain and Anthropic published detailed guides later in 2025.

What are the main context engineering techniques?

Write (store notes and memory outside the window), select (retrieve only what the step needs), compress (summarize and trim history and tool results) and isolate (split work across sub-agents and sandboxes).

Why do bigger context windows not solve the problem?

Models recall less precisely as the window fills, irrelevant tokens can distract them, and every token adds cost and latency. Curating context beats stuffing it.

What is context engineering for AI agents specifically?

For agents, context engineering happens on every turn of a long run: the agent's own actions keep adding tool results and history, so the system must decide continuously what to keep, summarize, fetch or hand to a sub-agent.

Do I need to do context engineering myself?

If you build agents from scratch, yes. If you use a platform like SPIRITT, the context layer (connected data, memory, retrieval, sub-agents and permissions) is built in, and you describe the job in plain words.

How we checked

We read Anthropic's "Effective context engineering for AI agents" and its context-management cookbook, LangChain's context engineering guide, and Karpathy's original post, and reviewed the current Google top results for "context engineering" on November 25, 2026. Tool prices come from the LangChain and Mem0 pricing pages and Anthropic's plan pages on that date. SPIRITT capabilities and prices come from spiritt.ai and the SPIRITT plan catalog.

Give your agents the right context

Buy from builders who use what they sellBuilt usingSPIRITT