Education

Context Engineering Best Practices Every Developer Should Follow

Krish Goyani

By Krish Goyani

Jul 29, 2026

Updated Jul 29, 2026

Context engineering is systems design for AI. It controls what information an LLM receives at runtime. Most agent failures are context failures, not model failures. Developers who master write, select, compress, and isolate strategies ship reliable AI products.

Context engineering is the discipline of designing dynamic systems that control what information an LLM receives, when it arrives, and how it is formatted, so AI agents succeed before they generate a single token. Most production AI failures trace back to context architecture, not model capability.

This guide covers the core layers, the four management strategies, production failure modes, and how platforms like Rocket.new implement context engineering at the infrastructure level.

Key takeaways

  • Context engineering is systems design, not prompt writing. It determines what enters the model's working memory at runtime

  • Every production context window has 7 distinct layers, each competing for the same token budget

  • The four management strategies are: write, select, compress, and isolate

  • Most agent failures in production are context failures, not model failures

  • Platforms that persist context across tasks eliminate the re-explanation tax that breaks most AI workflows

What Is Context Engineering and Why Does It Matter?

Context engineering is the discipline of designing dynamic systems that control what information, tools, and state an LLM receives at each step of a task. It moves past writing a single prompt to architecting entire pipelines that assemble the right data at runtime.

  • It moves past the prompt string. Tobi Lutke, CEO of Shopify, described it as "the art of providing all the context for the task to be plausibly solvable by the LLM." The focus shifts from clever wording to architectural decisions about data pipelines feeding the model.

  • Andrej Karpathy confirmed the shift. He noted that people associate prompts with short task descriptions, while in every industrial-strength LLM application, the real work involves filling the context window with just the right information for the next step.

  • It treats the context window like RAM. Karpathy's analogy frames the LLM as a CPU and its context window as working memory. Your job as a developer is to act like an operating system, loading the right code and data for each task at runtime.

The industry formalized the vocabulary in mid-2025. Simon Willison observed that "prompt engineering" carried an unfortunate stigma of just typing into a chatbot. The inferred definition of "context engineering" maps closer to what practitioners actually do daily.

The broader shift from prompts to context systems is reshaping how developers approach AI reliability across every layer of the stack.

How Does Context Engineering Differ from Prompt Engineering?

The difference is structural, not cosmetic. Writing clear prompts still matters at the instruction layer, but prompt engineering is just one layer inside context engineering, where prompts and system instructions both sit within the larger runtime context.

Bad prompting produces awkward outputs. Bad context produces confidently wrong outputs backed by missing information. A prompt is static text, fixed at authoring time. A context system adapts dynamically per request, and a language model or large language model often needs external data beyond its training data, pulled from retrieval systems or knowledge bases through context retrieval or retrieval-augmented generation to supply retrieved data and important context for the task.

Effective context engineering combines clear instructions, relevant tools, and the most relevant context from user input instead of passing along only what is available.

Context Engineering vs Prompt Engineering: architectural layer comparison

Context engineering adds six additional layers beyond the prompt, each competing for the same token budget, and structuring natural language inputs plus other relevant context into formats like JSON or Markdown can help the model produce the desired behavior.

DimensionPrompt EngineeringContext Engineering
ScopeSingle interactionFull session and system
FocusWording of inputInformation architecture
Skill typeWriting craftSystems design
Failure modePoor phrasingMissing or stale data
Production-readyRarely aloneYes, when designed well
DynamicNo, fixed textYes, adapts per request
Tool awarenessNoneTool definitions included

If your AI produces bad outputs and you keep rephrasing the prompt, you are probably fixing the wrong layer of the problem. Better context retrieval, relevant context selection, tool calls, and awareness of available tools often reduce hallucinations more than prompt edits alone. Understanding prompt engineering best practices is still valuable, but it is only one layer inside the broader context architecture.

What Are the Core Layers of a Context Window?

Every production AI system fills its context window from multiple distinct layers. Each layer serves a different purpose and changes at a different frequency.

  • System prompt: Behavioral rules, constraints, and persona definitions that rarely change between requests. This is the foundation layer setting behavioral boundaries.

  • User prompt: The immediate task or question from the user. Changes every single request.

  • Conversation history: Prior exchanges maintaining session continuity. Accumulates over time and needs active management, including summarizing or trimming message history over long sessions.

  • Long-term memory: Preferences, decisions, and learned facts persisting across sessions. Enables personalization without repetition, and agent memory may rely on persistent memory or long-term memory storage outside the llm's context window.

  • Retrieved documents (RAG): External content fetched dynamically based on the current query. Changes every request, and retrieval-augmented generation depends on retrieval quality while often pulling from knowledge bases or vector databases.

  • Tool definitions: Functions the model can call, including search APIs, database queries, and code execution. Loaded per task based on required capabilities, with tool calls serving as the mechanism for accessing available tools during complex tasks.

  • Output schema: Format requirements like JSON structures or response templates. Set per task type.

Each layer competes for the same limited token budget. The model's context window functions like the model's short-term memory, so a limited context window and a hard context window limit force tradeoffs: if a 128K-token window is split unevenly, with 80K tokens of raw codebase and only 5K left for instructions, the model reasons on the wrong priorities. Overloading one layer starves the others.

Bigger context windows help, but they do not replace careful context ordering and selecting only the most relevant context.

The practical implication: audit what actually enters your context window for each request type. Most teams have never inspected the fully assembled prompt their agent constructs at runtime. Understanding how AI decodes multilayer app logic is directly connected to how well you manage these layers.

What Are the Four Strategies for Managing Context?

Four core strategies documented by the LangChain team address how to manage context across agent lifetimes. These categories work together as a cycle.

  • Write context: Save information outside the window for later use. Scratchpads, memory stores, and note-taking tools let agents persist key facts during long sessions without burning tokens on every turn.

  • Select context: Pull relevant information into the window at the right moment. RAG retrieval, memory selection, and tool filtering all address this. The challenge is selecting what matters, not everything available, so selection should fetch the right context from knowledge bases or retrieval systems, often with semantic search or hybrid search.

  • Compress context: Retain only the tokens required for the current step. Context compression summarizes message history or conversation contents as the window fills, and compaction creates high-fidelity summaries. Summarization, trimming older messages, and condensing tool outputs keep the window focused and performant.

  • Isolate context: Split work across sub-agents or sandboxed environments. Each agent gets its own window scoped to a narrower sub-task, and multi-agent designs help maintain coherence on long-horizon or complex tasks by narrowing each agent’s scope.

These write/select/compress/isolate tactics are practical context engineering principles for working within an llm's context window.

The 4 Context Management Strategies: Write, Select, Compress, Isolate as a connected cycle

The four strategies form a continuous cycle. Getting all four right separates agents that break after ten turns from agents that run reliably across hundreds.

These four strategies also map directly to how MCP workflows for AI agents operate in modern production systems. Each protocol step corresponds to one of these context management phases.

How Does Rocket.new Implement Context Engineering for Developers?

Most AI development tools start every session from zero. You describe your project, paste in requirements, and re-explain decisions you already made. Context evaporates at every handoff between tasks, team members, and work sessions. Rocket.new is built around the write/select/compress/isolate framework at the infrastructure level, so developers never pay the re-explanation tax.

How Rocket.new implements context engineering across four feature layers

Rocket.new maps each context management strategy to a named platform feature, from project memory to competitive intelligence.

Write: Project-level shared memory

Rocket.new groups related Solve and Build tasks inside a single project, which acts as a knowledge container. Files, connected services, and collaborators are shared across every task inside it. Upload your company overview or strategy deck once, and every task inside that project has that foundation from the start.

Select: Cross-task @-mentions

Cross-task context lets you reference any previous task with a single @-mention in the message input. Rocket.new retrieves the conversation, findings, and conclusions from that referenced task and applies them to your current one. You build on past work instead of re-explaining it, and this works in both Solve and Build tasks.

Compress: Prompt Intelligence

Before any task begins, Prompt Intelligence scores your input for completeness. If the score meets the minimum threshold, work starts immediately. If it falls below, Prompt Intelligence asks a short set of targeted questions to fill the gaps, then starts once it has enough to proceed. This prevents vague prompts from producing wasted token runs.

Isolate: Intelligence as a separate workspace layer

Rocket Intelligence operates at the workspace level, entirely separate from projects. It watches competitors across nine signal pillars, including Website, Social Media, News and Media, GTM, Product and Technology, People and Hiring, Business and Finance, Reviews and Community, and more. It delivers findings as Intel cards: structured reads that connect signals into meaning, not raw alerts. Intelligence uses absence detection and cross-pillar patterns to surface what matters.

Where other tools start from blank prompts, Rocket.new retains project-level decisions, research outputs, and competitor signals as persistent context across the full product lifecycle. Teams already optimizing context for production apps see immediate gains from this architecture.

Stop re-explaining your project to your AI tools. Start building on Rocket.new and experience what context-first AI development actually feels like.

How Do You Avoid Common Context Failures in Production?

Failures in production agents fall into predictable patterns. Knowing these patterns helps you build defenses into your context architecture from the start.

As Philipp Schmid of Hugging Face notes in his research, most agent failures are not model failures anymore. They are context failures. When agents break in production, the root cause is almost always what the model never received: missing project details, stale documents, absent tool definitions, irrelevant details, or badly ordered context.

Four context failure modes: Poisoning, Distraction, Confusion, and Clash as a 2x2 grid

Each failure mode has a distinct cause and a specific architectural fix. Treating them as one problem leads to the wrong solution.

Failure ModeWhat HappensFix
Context PoisoningA hallucinated fact from an earlier turn contaminates all subsequent reasoningValidate context inputs before passing them forward to the next agent step
Context DistractionToo much irrelevant information overwhelms the model's trained behaviorScope retrieved documents tightly to the current task and pull only the most relevant context from retrieved data
Context ConfusionSuperfluous information in the window influences responses unpredictablyRemove stale or duplicate entries on every turn
Context ClashDifferent parts of the window contradict each otherTimestamp context sources and prioritize recent information when system instructions, message history, or tool outputs conflict

Selecting high-signal tokens and excluding low-value context improves desired behavior and reduces hallucinations.

*"+1 for 'context engineering' over 'prompt engineering.' People associate prompts with short task descriptions. In every industrial-strength LLM app, it is the delicate art and science of filling the context window with just the right information for the next step." — Andrej Karpathy, *via Simon Willison's blog

Teams applying production-ready development practices with context-first thinking consistently ship AI products that survive real-world conditions. The same discipline that prevents context failures also underpins how AI improves backend performance and API reliability in production systems.

Context Engineering Best Practices: Summary Table

PracticeLayer AffectedImpact
Audit assembled prompts at runtimeAll layersReveals hidden token waste
Validate context inputs before forwardingSystem and retrieved docsPrevents context poisoning
Scope RAG retrieval to current taskRetrieved documentsReduces context distraction
Timestamp and prioritize recent sourcesLong-term memoryEliminates context clash
Summarize conversation history on long sessionsConversation historyUses context compression by summarizing contents near the context window limit
Use sub-agents for complex multi-step tasksIsolationSupports multi-agent isolation for complex tasks and helps maintain coherence
Load tool definitions only when neededTool definitionsKeeps only relevant tools and available tools in the window

Why Context Engineering Is the Defining Developer Skill of 2026

The shift from prompts to context systems is not a temporary trend. It is the maturation of an entire industry. Every production AI application that works reliably in 2026 has a context architecture behind it, whether the team calls it that or not, especially in agentic systems where the core challenge is curating relevant context for the language model across long-running workflows.

Research shows that context window utilization directly correlates with task completion rates in multi-step agent workflows, but bigger context windows alone do not solve a limited context window without deliberate memory architecture. Separately, studies on long-context LLM behavior confirm that models perform significantly worse when irrelevant content fills more than 40% of the available token budget.

Effective context engineering matters because the model still needs structured context, persistent memory, and retrieval beyond training data. Context architecture is not optional infrastructure. It is the primary determinant of whether your AI product works in production.

The question is not whether to invest in this discipline. It is whether you want to build context pipelines yourself or let a platform handle it at the infrastructure level while you focus on your product.

About Author

Photo of Krish Goyani

Krish Goyani

Research Engineer

He is the engineer behind Rocket's Agent v2, the core agentic system that powers everything the platform builds. From app-wide code generation to website rebuilds, his agents handle thousands of requests a day across some of the largest codebases in the vibe solutioning ecosystem.

Decorative background for the call-to-action section

The work is only as good as the thinking before it.

You already know what you're trying to figure out. Type it. Rocket handles everything after that.