liveBook · Manning

Chapter 3: Context fabric: optimizing context for AI agents

What you will learn in chapter 3 of Vibe Engineering

The introduction explains why agents often fail because of the context they receive, distinguishes context engineering from prompt engineering, and defines a shared Context Fabric.

After this chapter you will be able to

What it builds on

Section by section

Introduction

The introduction explains why agents often fail because of the context they receive, distinguishes context engineering from prompt engineering, and defines a shared Context Fabric.

Key terms: context failure, context vacuum, context rot, poisoning, lost in the middle, prompt engineering, context engineering, context, Context Fabric, agent-consumable context

3.1 Vibe Coding traps: garbage in, garbage out

The section uses a vague login-fix request to show how missing context leads to unreliable AI-generated code and why developers remain responsible for supplying relevant information.

Key terms: context, garbage in, garbage out, clarifying questions, logical and semantic errors, incomplete code, hallucinations, invariants

3.2 Context vacuum: first potential mistake

This section explains how sharing code without its project context can lead an AI agent to make confident but unsuitable changes, while noting when a narrow context is useful.

Key terms: Context Vacuum, invisible dependencies, hallucinate, focused context, context-ignorant, context-blind, automated context retrieval

3.2.1 From a single-shot to multi-shot examples

The section shows why adding files to a coding prompt is not enough: useful context needs relevant examples and clear labels for each fragment’s role.

Key terms: dependencies, dependency graph, multishot, multifile, reference points, context engineering, curating examples, annotating, framing

3.2.2 Good multishot prompt vs bad multishot prompt

This section shows why labeled, explained code examples give an LLM more useful context than the same snippets presented without structure.

Key terms: multishot prompt, context engineering, Service Layer Example, Domain Model Example, Error Handling Example

3.2.3 Let the model do the gap analysis

The section shows how to ask an AI model for a prioritized list of missing context before it writes code, while recognizing the limits of that gap analysis and using it as part of a short exchange.

Key terms: gap analysis, unknowns, hallucinations, context vacuum, User schema, rate limiter, rough notes, constraints, proper prompt, short exchange

3.3 Building context together with LLMs

The section explains why manually assembling context for complex coding tasks is slow and risky, why the right amount of context is hard to judge, and why connected tools are needed.

Key terms: multi-shot, multi-entity context, poisons the context, gap-analysis prompt, minimalists, maximalists, automated tooling, sources of truth, live data, lineage

3.3.1 Using Model Context Protocol to instrument LLMs

This section explains how MCP gives AI agents a standard way to access external tools and data, and why its architecture and newer features make those integrations practical.

Key terms: Model Context Protocol, MCP, JSON-RPC, universal interface, MCP client, MCP server, tools, OAuth 2.1, tool annotations, readOnlyHint

3.3.2 Building context for a UI component with MCPs

Shows how an MCP-enabled agent gathers design, codebase, and API context for a UI component, while distinguishing retrieved design tokens from a live design-system connection.

Key terms: MCP, Figma Dev Mode, BaseCard, API response schema, design tokens, Figma variables, CSS custom properties, token export step, snapshot

3.3.3 Accessing external knowledge through MCPs

The section shows how MCP lets an agent discover and document a new library needed for a component, while leaving the developer responsible for checking the choice and its fit.

Key terms: MCP, library research MCP, Context7 MCP, UserProfileCard, documentation server, official API contract

3.3.4 Deep integration with Language Server Protocol

The section shows how MCP access to an LSP server adds compiler-level context to an agent’s work, then uses a component prompt to show why source checks and explicit failure handling matter.

Key terms: Language Server Protocol, MCP, build-time truth, runtime truth, ClassPath, referenceable prompts, fully qualified type names, artifact versions, definition paths, Assumptions

3.3.5 MCP governance

This section explains how to govern MCP integrations so agents can reach live information without being overwhelmed by tools, wasting context, or gaining unsafe access.

Key terms: MCP servers, production dependencies, team-approved allowlist, deterministic context assembly, MCP registries, MCP Proxies, MCP Gateways, discovery and invocation, tool annotations, readOnlyHint

3.3.6 Agentic skills: procedure as loadable context

This section explains how agent skills load team-specific procedures only when needed, and how plugins package those procedures into a reusable team context fabric.

Key terms: tool description, Agent Skills, SKILL.md, YAML frontmatter, progressive disclosure, frontmatter, description field, Markdown body, references, scripts

3.4 Context rot: is too much context a bad thing?

This section defines the context window, illustrates how much it has grown, and cautions that larger windows still have drawbacks.

Key terms: context window, tokens, 1M-token modes

3.4.1 “Lost in the middle” problem

This section explains why large context windows can reduce an AI coding agent’s accuracy, especially when a critical instruction is buried in the middle of a long prompt.

Key terms: advertised context window, effective context window, context rot, lost in the middle, U-shaped performance curve

3.4.2 Manual reordering: "Sandwich" Method

3.5 Using AI coding tools to manage context

AI coding tools can automate tedious parts of context engineering without replacing the need to manage context.

Key terms: AI coding tools, context engineering

3.5.1 Automated retrieval: from RAG to agentic search

Explains how coding assistants select repository context, how developers can correct poor retrieval, and why agentic search is increasingly used alongside or instead of embedding-based RAG.

Key terms: pinning specific files, @-mentioning a directory, ignore file, clean session, Retrieval-Augmented Generation (RAG), chunks, embeddings, similarity search, augmentation, agentic search

3.5.2 Context anchor: todo list for LLM

This section explains why retrieval alone cannot preserve an agent’s focus across a long coding task and how plans, durable instructions, compaction, and subagents address different forms of context loss.

Key terms: RAG, amnesiac coder, sliding window of tokens, context rot, Context Anchor, Focus Engineering, to-do tool, execution plan, Context Compaction, lossy summarization

3.5.3 Beyond compaction: meta-prompting and state externalization

This section explains how meta-prompting frameworks counter context rot by storing project knowledge outside conversations, giving fresh agents focused context, and enforcing engineering workflows.

Key terms: state externalization, context window, Context Fabric, GSD, Discuss → Plan → Execute → Verify, CONTEXT.md, .planning/, Nyquist validation layer, git bisect, Verify phase

3.5.4 …can I be lousy again if I’m using coding AI?

Coding agents automate much of the work of assembling context, but developers remain responsible for the quality, direction, and correction of that context.

Key terms: Automated Retrieval, Automated Reordering, Memory Management, compaction, Garbage In, Garbage Out, knowledge base, context poisoning, Context Fabric, navigator, context failure

3.6 Context through reasoning

This section explains why aging codebases can corrupt an AI agent’s context and why reliable coding requires the agent to critique that context, not merely consume more of it.

Key terms: Software Aging, entropy, pockets of inconsistency, Conflicting Signals, Poisoning the Context, context vacuum, context overload, context corruption, critique

3.6.1 Chain-of-Thought: forcing the LLM to “show its work”

This section explains how stepwise reasoning and visible plans help AI coding agents handle complex tasks while giving developers a chance to inspect their assumptions before code is written.

Key terms: Chain-of-Thought, Context Anchoring, reasoning trace, intermediate steps, frontier models, reasoning effort, thinking budgets, visible trace, conflicting signals, auditability

3.6.2 Chain-of-Verification: internal fact-checking loop

This section explains how Chain-of-Verification challenges an agent’s first answer so that a plausible but mistaken line of reasoning does not become the final result.

Key terms: Chain-of-Verification, CoVe, baseline answer, verification questions, falsification, context poisoning, prepared statements, parameterized queries, objective outcomes

3.6.3 How to introduce self correction?

This section explains why AI self-correction needs an independently checkable specification and strong engineering feedback loops, not just another pass by the model.

Key terms: LLM-as-a-Judge, machine-checkable specification, self-correction, feedback loops, meaningful assertions, continuous integration, ADRs

3.6.4 Is reasoning always THE solution?

A debugging anecdote shows that elaborate AI reasoning is not always the best route to an answer, and that engineers must judge when to use it.

Key terms: Minus World glitch, reasoning chains, verification loops, retrieval

3.7 Summary

Where this is used later

Concepts explained in this chapter

← Chapter 2: Building a legacy modernization framework powered by Vibe Engineering Chapter 4: LLM-driven data science →

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.