liveBook · Manning

Chapter 7: Context management and orchestration

What you will learn in chapter 7 of Context Engineering

The introduction distinguishes the six sources of context from the two layers that handle context during execution: management for a single model call and orchestration across a multi-step execution.

After this chapter you will be able to

What it builds on

Section by section

Introduction

The introduction distinguishes the six sources of context from the two layers that handle context during execution: management for a single model call and orchestration across a multi-step execution.

Key terms: context sources, context window, context management, context orchestration

7.1 Context management

This section explains why each model call needs context management and introduces four complementary techniques for keeping its context useful.

Key terms: context window, token budget, attention budget, context management, selection, writing, compression, isolation, runtime pipeline

7.2 Context selection

Defines context selection as choosing useful information for each model invocation and explains why irrelevant context can distract an agent.

Key terms: context selection, context assembly, model context, invocation, irrelevant context, distraction, task-critical information

7.2.1 Principles

This section explains four principles for selecting useful context: keep it informative, place it where it will be noticed, revise it as work proceeds, and reveal detail only when needed.

Key terms: informativity over exhaustiveness, high-signal tokens, active prompt, position-aware placement, lost in the middle effect, attention-favored boundary positions, iterative curation, candidate context, working set, compact state

7.2.2 Techniques

This section explains how context selection retrieves candidates, filters them, and prioritizes what enters a prompt under a token budget.

Key terms: retrieval, just-in-time, lightweight references, context window, filtering, relevance filters, quality filters, trust filters, prioritization, token budget

7.3 Context writing

Defines context writing as a way to keep the active prompt compact without losing recoverable history, and explains why it should precede compression.

Key terms: context writing, active context window, active prompt, external storage, prompt utilization, context pressure, writing, compression, lossless action, recoverable state

7.3.1 Principles

This section sets out five principles for writing context to external stores so it remains usable, accurate, maintainable, and appropriately protected.

Key terms: recoverability, saved artifacts, context noise, fidelity at the boundary, lightweight reference, authoritative source of truth, separation of lifetimes, scratchpad data, session variables, durable user memory

7.3.2 Techniques

This section explains how agents write context to files, external stores, and scratchpads so useful information remains available without keeping it all in the prompt.

Key terms: filesystem-based context, instruction files, bounded file reads, external storage, vector databases, graph databases, relational databases, object stores, working scratchpads, structured JSON

7.4 Context compression

Defines context compression, explains when it is useful, and distinguishes it from deletion.

Key terms: context compression, active context, selection, state, next actions, compression, deletion, working memory

7.4.1 Principles

This section sets out principles for preserving useful information, deciding when to compress context, and checking whether compression still supports the task.

Key terms: task-critical detail, user constraints, current task state, freeform summaries, structured summary, explicit fields, incremental compression, summary drift, persistent summary, deduplicate

7.4.2 Techniques

This section explains three ways to compress active context—summarization, trimming, and observation masking—and the information each must preserve or make recoverable.

Key terms: summarization, anchored iterative summarization, summary drift, artifact trail, trimming, critical state, message list, observation masking, offloading, storage pointer

7.5 Context isolation

Context isolation divides work among bounded context windows and uses a coordinator to combine their results without bringing all local work into the parent context.

Key terms: context isolation, context windows, bounded execution contexts, working set, coordinator, subagent, parent context, compact result

7.5.1 Principles

This section explains how to isolate contexts by concern, limit their access and authority, exchange structured results, and weigh isolation against its coordination cost.

Key terms: one context, one concern, context bloat, authority confusion, least context, tool restrictions, harness, namespaces, workspaces, authority separation, privileged control paths

7.5.2 Techniques

This section explains three ways to isolate context: subagents, partitioned state, and sandboxed execution environments.

Key terms: subagents, coordinator agent, output contract, state partitioning, state object, context manager, structured fields, environment sandboxing, execution state, runtime state

7.6 Context orchestration

This section distinguishes context orchestration from context management and explains how they coordinate through runtime state as context changes during multi-step execution.

Key terms: context orchestration, context management, routing layer, runtime state object, execution plan, intermediate results, context manager, orchestrator, agentic orchestration, dynamic resource

7.6.1 Orchestration models

This section distinguishes four ways an agentic system can control execution at runtime and explains the trade-offs of each.

Key terms: orchestration model, framework taxonomy, intermediate context, imperative orchestration, control logic, control flow, graph-based orchestration, nodes, edges, state

7.6.2 Coordination and interoperability

Distinguishes the orchestration layer’s coordination and interoperability responsibilities and explains why the orchestrator is a source of telemetry.

Key terms: coordination, interoperability, context orchestration layer, orchestrator, telemetry, observability

7.7 Patterns for multi-agent coordination

This section frames multi-agent coordination patterns as choices about how work and context flow, then gives a principle for choosing among them.

Key terms: coordination patterns, context boundaries, shared state object, runtime coordination contract, sequential, parallel, loop, router, network, hierarchical

7.7.1 Sequential

Explains when to use a sequential pipeline and how to limit errors passed between its stages.

Key terms: sequential pipelines, clear phases, error propagation, status, confidence, unresolved assumptions

7.7.2 Parallel

Explains when parallel agent work is useful and what information should reach the coordinator when branches finish.

Key terms: parallel pipeline, fan-in step, coordinator, branch transcript

7.7.3 Loop

Explains how a loop pattern coordinates agents for iterative revision while controlling carried context and enforcing stopping limits.

Key terms: loop pattern, internal loop, writer agent, reviewer agent, current draft, latest critique, context discipline, stop conditions, orchestration code, cost

7.7.4 Router

Explains how a router directs requests to specialized agents and handles uncertain routing decisions.

Key terms: router, specialized agents, route name, confidence score, short reason, low-confidence routes, default agent, user clarification path

7.7.5 Network

Explains when a network pattern suits multi-agent work and why its flexible handoffs require explicit coordination information.

Key terms: Network patterns, specialists, fixed pipeline, supervisor, coordination risk, handoff, task owner, current state, relevant evidence, next action

7.7.6 Hierarchical

Explains how hierarchical agent coordination divides work and context across layers, and when the added complexity is worthwhile.

Key terms: hierarchical patterns, top-level coordinator, shared state, managers, workers, downward message, local state, constraints, output contract, structured summary

7.8 Interoperability protocols

This section explains why collaboration across system boundaries requires interoperability protocols rather than in-memory context sharing.

Key terms: coordination patterns, in-memory state objects, interoperability protocols, system boundaries

7.8.1 Agent-to-agent (A2A) protocol

This section explains how A2A lets independent agents discover one another, delegate work, track related tasks, and exchange relevant context and results.

Key terms: A2A, client agent, server agent, task context, agent card, capability manifest, skills, supported interfaces, security requirements, agent discovery

7.8.2 Agent-user interaction (AG-UI) protocol

This section explains how AG-UI connects backend agents with user interfaces so people can see, interact with, and influence agent workflows.

Key terms: AG-UI, A2A, event-driven protocol, agent execution context, Real-time streaming, Generative UI, execution events, structured UI payloads, Bidirectional state synchronization, active context

7.8.3 Agent client protocol (ACP)

Explains how ACP gives editors and coding agents a standard way to exchange workspace context and coordinate proposed actions.

Key terms: ACP, client, coding agent, uniform interface, capability negotiation, workspace context, active turns, explicit user permissions

7.8.4 Language server protocol (LSP)

Explains how LSP gives coding agents structured, language-aware code context and how that role complements ACP.

Key terms: LSP, client, language server, JSON-RPC, semantic code intelligence, ACP, workspace state, language-aware contextual evidence

7.9 Hands-on

Introduces practical exercises on context management and orchestration and points readers to their source code.

7.9.1 Context compression with LLMLingua

This section demonstrates compressing conversation history with LLMLingua while checking that information needed for a later LLM response survives.

Key terms: LLMLingua, context compression, target token size, sentinel facts, context overflow, deterministic assertions, regression check, sentinel set, exact identifiers, state markers

7.9.2 Filesystem context with OpenViking

This section shows how OpenViking uses a filesystem-like hierarchy and tiered loading to give agents relevant context without loading full documents immediately.

Key terms: OpenViking, hierarchical filesystem, virtual filesystem, ls, find, tiered context loading, progressive disclosure, L0, L1, L2

7.9.3 Multi-agent system based on the router pattern with LangGraph

Shows how a LangGraph customer-support router uses workflow state to send questions to specialized agents, and identifies safeguards needed for production routing.

Key terms: router pattern, AgentState, structured workflow state, routing function, LangGraph, confidence score, threshold, fallback branch

7.9.4 Collaborative agents with CrewAI

Shows how a CrewAI crew passes task outputs between specialized agents while keeping each agent’s context focused.

Key terms: crew, specialized agents, sequential pipeline, focused context, context argument, handoff contract, context isolation, task level

7.9.5 Orchestration with DeepAgents

Shows how DeepAgents combines planning, file-based context writing, and subagent isolation to support long-horizon tasks while keeping the active prompt compact.

Key terms: DeepAgents, todo list, scratchpad, virtual filesystem, subagents, context isolation

7.9.6 Simplified A2A communication in practice

This hands-on example traces a simplified A2A exchange in which a client discovers a server agent and requests a weather forecast, while distinguishing the teaching scaffold from a production implementation.

Key terms: agent card, discovery, message:send, task-shaped response, teaching scaffold, conformant implementation, protocol binding, authentication

7.10 Summary

Where this is used later

Concepts explained in this chapter

← Chapter 6: User prompts for LLMs Chapter 8: Evaluation and observability →

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.