Overview

3 Context fabric: optimizing context for AI agents

At the heart of the chapter is a simple warning: AI agents do not succeed because they are “smart” in the abstract, but because they are given the right context. The text distinguishes prompt engineering from context engineering and argues that most agent failures come from context problems such as too little information, too much irrelevant information, stale or incorrect inputs, or important details being buried where the model cannot effectively use them. In that sense, the quality of an agent’s output is a direct reflection of the quality, structure, and freshness of the information it receives.

The chapter then develops practical ways to build better context. It shows how to avoid isolated snippets, ambiguous multishot examples, and manually assembled prompts that can easily become misleading or outdated. Instead, it recommends shaping context deliberately: label examples, ask the model what it is missing, and use tools that pull live information from the repository, documentation, design systems, and other sources of truth. It also introduces the idea of a broader “fabric” of project knowledge: durable conventions, specs, and artifacts that live outside any single chat session and can be loaded when needed.

As the discussion expands, the chapter explains that more context is not always better, because long prompts can suffer from overload and the “lost in the middle” effect. To address this, it explores strategies like careful prompt ordering, retrieval systems, context anchors, compaction, subagents, and reasoning loops such as chain-of-thought and chain-of-verification. The overall message is that reliable agentic development depends on disciplined context management, strong feedback loops, and well-organized project knowledge, not on hoping the model will infer everything correctly from a vague request.

Configuring MCPs in Claude App.
MCPs and universal integration tools for agents - The MCP client (center) communicates with domain-specific servers via a standard protocol. Each server translates between the agent's requests and the external system's API, returning structured data the model can reason about.
Working with dependencies with Context7 MCP.
MCP ↔ LSP (Metals) with Claude Desktop as MCP Client.
MCP Governance layers - the agent communicates through an MCP Gateway (enforcing auth and policies), which routes to an MCP Proxy (aggregating multiple servers into a curated toolset), which connects to individual MCP servers registered in a central catalog. Each layer adds security and reduces context noise.
Loss of the accuracy as context size grows.
Context-aware assistance flow. The developer's query is converted into an embedding, matched against the indexed codebase, and the most relevant chunks are injected into the prompt before the model generates its response.
Tools like Cline allow you to track current context window fulfillment.
Execution plan of Claude Code.
Superpowers flow getting user through predefined workflow.
The context pyramid: five interdependent layers of the Context Fabric. Each layer rests on the ones below it - a gap low in the pyramid undermines everything above, no matter how complete the upper layers are.
Cline drafting plan of the execution.
Cline sharing plan for achieving the goal, waiting for human in the loop to approve.
Cline Chain-of-Verification - sharing the work done with the human operator.

Summary

  • Context engineering is an evolution of prompt engineering - it focuses on strategically selecting, structuring, and labeling information so the model can interpret it correctly.
  • Automated tools using protocols like MCP allow agents to independently retrieve current and precise data from various sources like Figma, code repositories, and documentation systems.
  • Skills package procedural knowledge as folders of Markdown that load progressively: a name and description at rest, the full instructions only when the task calls for them.
  • Skill plugins bundle skills, commands, subagents and MCP configuration into one installable, versioned unit, which turns one developer's context work into something the team shares.
  • Providing more context does not always lead to better results. Language models suffer from the "lost in the middle" problem
  • AI coding tools automate context engineering with techniques like Retrieval-Augmented Generation, Context Anchors and Context Compaction to manage conversation history.
  • AI tools do not eliminate the need for context engineering but instead shift the developer's role from a technician to a strategist.
  • To handle inconsistent or flawed context, agents must use advanced reasoning techniques. Chain-of-Thought compels the model to show its reasoning process, while Chain-of-Verification introduces a fact-checking loop, enabling a critical evaluation of the information it processes.
  • All of these practices accumulate into the Context Fabric - the persistent layer of specs, memory files, curated MCP integrations, and structured knowledge that lives outside any single session and gives every fresh context window immediate access to the project's accumulated intelligence.

FAQ

What is “context engineering” in AI agents?

Context engineering is the discipline of designing, selecting, structuring, and maintaining the information an AI system receives so it can produce reliable, high-quality output. It focuses on the whole information environment, not just the wording of the prompt.

How is context engineering different from prompt engineering?

Prompt engineering is about how you phrase an instruction. Context engineering is broader: it includes what data the model sees, in what order, at what level of detail, and from which sources. In short, prompt engineering is part of context engineering, but not the whole of it.

What are the main types of context failures?

The chapter identifies four common context failures: too little context, called a vacuum; too much context, called context rot; stale or wrong context, called poisoning; and correct context being placed where the model stops paying attention, known as lost in the middle.

Why does an isolated code snippet often lead to bad AI output?

An isolated snippet hides its dependencies, conventions, and surrounding architecture. The model may then invent missing details, change semantics, or produce incomplete code because it cannot see how the snippet fits into the larger system.

What is the “Context Vacuum” problem?

Context Vacuum happens when you give the model only a fragment of code without enough surrounding information. The agent becomes context-blind: it treats the snippet as the whole world and may confidently produce the wrong fix.

How does good multishot prompting help?

Good multishot prompting labels and explains each example so the model knows what role each fragment plays. This reduces ambiguity, helps the model infer project conventions correctly, and lowers the chance of hallucinations.

Why should you ask the model what it is missing before asking it to code?

Because identifying gaps is easier for the model than committing to specific wrong assumptions. A gap-analysis prompt helps surface the top unknowns first, so you can provide the most important missing context before the model writes code.

What is MCP and why is it useful?

Model Context Protocol (MCP) is a standard for connecting AI agents to external tools and data sources through a common interface. It helps agents retrieve structured, current information from systems like Figma, GitHub, documentation, and databases without custom integrations for every tool.

What are Agent Skills and plugins in this chapter?

Agent Skills are loadable instruction folders, usually centered on a SKILL.md file, that provide procedure as context. Plugins are broader packages that bundle skills, commands, subagents, MCP configs, and hooks into a versioned unit that teams can install and reuse.

Why is “more context” not always better?

Large context windows can still hurt accuracy. As context grows, models can become less reliable, slower, and more expensive, and key details may get “lost in the middle.” The chapter recommends curating context carefully rather than dumping everything into the prompt.

pro $24.99 per month

  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose one free eBook per month to keep
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime

lite $19.99 per month

  • access to all Manning books, including MEAPs!

team

5, 10 or 20 seats+ for your team - learn more


choose your plan

team

monthly
annual
$49.99
$499.99
only $41.67 per month
  • five seats for your team
  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose another free product every time you renew
  • choose twelve free products per year
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime
  • renews annually, pause or cancel renewal anytime
  • Vibe Engineering ebook for free
choose your plan

team

monthly
annual
$49.99
$499.99
only $41.67 per month
  • five seats for your team
  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose another free product every time you renew
  • choose twelve free products per year
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime
  • renews annually, pause or cancel renewal anytime
  • Vibe Engineering ebook for free