Chapter 7: Context management and orchestration
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
- Context management and orchestration. Distinguish context management from context orchestration, and explain how both relate to the six context sources.
- Three model call limits. Distinguish the context window, token budget, and attention budget, and explain why filling the available window can still make a call slower, costlier, or less focused.
- Integrated context management techniques. Explain how context management uses selection, writing, compression, and isolation together to shape the context for an individual invocation.
- Context selection purpose. Explain that context selection, or context assembly, decides what information enters the model context for a specific invocation and aims to maximize the utility of its tokens rather than the amount of information supplied.
- Informativity Over Exhaustiveness. Explain why the active prompt should contain only high-signal information sufficient for the next decision, and describe the test for excluding material.
- Position Aware Context Placement. Explain how the lost-in-the-middle effect informs where critical and supporting material should go in a long prompt.
- Iterative Context Curation. Describe why selected context must be revised during an agent's work and what kinds of changes that revision can make.
- Progressive Context Disclosure. Explain how progressive disclosure delays token costs until information is needed, using the three agent-skill layers and an example beyond skills.
- Just-in-time candidate retrieval. Explain how retrieval finds candidate information outside the context window and why an agent may load it only as the task unfolds.
- Candidate filtering dimensions. Describe how filtering screens retrieved candidates before prompt assembly across relevance, quality, and trust.
- Token-budget context prioritization. Explain how prioritization allocates limited prompt space among filtered candidates, including current needs and tool outputs.
- Recoverable context outside the prompt. Explain how context writing saves useful information outside the active context window while leaving the agent a compact prompt it can work from.
- Writing before lossy compression. Distinguish writing from compression as ways to relieve context pressure, and explain why writing should come first.
- Recoverable written context. Explain why saved context must be easy to find, inspect, and reload, and how artifact metadata helps make that possible.
- Fidelity across the writing boundary. Explain what the external store must preserve when information is offloaded before summarization or masking, and how its role differs from the prompt's.
- Separate context lifetimes. Describe why temporary, session, durable user, and compliance information should be kept in distinct stores or namespaces.
- Controlled store mutation. Explain why written context should be updated and organized rather than left as an ever-growing append-only log.
- Least exposure of records. Explain why a system should limit which persistent records it exposes for a task and where access controls should be enforced.
- Offloading And Prompt References. Explain how context writing handles a large order history and identify the limit of preserving it outside the prompt.
- Purpose and timing of compression. Explain why compression is useful when active context keeps growing but its contents remain relevant: it saves tokens without losing the state and next actions needed to continue the task.
- Task-critical detail preservation. Explain why compression must protect details that cannot easily be reconstructed, such as constraints, decisions, identifiers, and current task state.
- Structured summary fields. Explain how a structured summary exposes omissions that a freeform summary can hide, using the section's example fields.
- Incremental compression and drift. Describe how compressing only newly accumulated messages and merging them into a persistent summary avoids repeatedly rewriting history.
- Explicit compression triggers. Describe why compression should have a visible trigger and distinguish the trigger options given in the section.
- Task-continuation evaluation. Explain why compression quality is judged by whether the task can continue, rather than by textual similarity alone, and what probes can check.
- Anchored iterative summarization. Explain how summarization shortens prior interactions, tool outputs, or phase results while retaining information needed to continue the task. Describe why a long session is better served by merging a summary of only the newly removed span into the existing summary.
- Trimming and critical state. Distinguish trimming from summarization and explain when removing messages is safe enough to use. Describe why critical task state should remain available outside the message list.
- Observation masking and offloading. Explain how observation masking reduces the prompt cost of bulky tool results while retaining a way to recover them. Distinguish masking from offloading and identify which observations should remain unmasked.
- Distinct bounded working contexts. Distinguish context isolation from selection, writing, and compression: isolation separates work across context windows rather than managing tokens within or around one context.
- Coordinator and local work. Describe how a coordinator and bounded execution contexts divide responsibilities, including what local work is returned to the parent context.
- One Context One Concern. Explain why research, coding, testing, and security should have separate contexts rather than sharing one.
- Least Context Boundaries. Describe how to limit an isolated unit to the context and access its objective requires, including enforceable tool, file, and memory boundaries.
- Separated Context Authority. Explain why instructions, evidence, observations, user data, and runtime configuration should remain distinguishable, and when runtime context should be exposed.
- Structured Output Contract. Describe what a subagent should return to its coordinator and what should remain in the child workspace unless requested.
- Justified Isolation Overhead. Justify when isolation is worth its coordination cost and when a single curated context is preferable.
- Bounded subagent context. Explain how a coordinator delegates a bounded task to a subagent without bringing the subagent’s full working history into its own context. Describe the focus gained and the coordination needed for dependent tasks.
- Selective state fields. Describe how state partitioning keeps different kinds of agent state in structured fields and exposes only the fields needed for a given model step.
- Sandboxed execution state. Explain how an agent can act on a live sandbox while keeping its runtime state out of prompt memory, and state the safety benefit described here.
- Orchestration and management roles. Distinguish context orchestration from context management: orchestration routes execution, delegation, and intermediate results, while management decides what enters a single context window.
- Runtime state coordination. Trace how the orchestrator and context manager use the runtime state object between invocations.
- Runtime models and framework categories. Explain what an orchestration model describes and distinguish it from a framework category. State that one framework or production system can use more than one orchestration model.
- Imperative code control flow. Describe how imperative orchestration expresses control in ordinary application code and explain its principal trade-off.
- Graph based state transitions. Explain how graph-based orchestration represents work, transitions, and state, and why that representation helps make execution understandable.
- LLM coordination and external guardrails. Describe who chooses the next action in agent-driven orchestration and why limits must be enforced outside the LLM's reasoning.
- Platform mediated control logic. Describe what controls execution in platform-mediated orchestration and distinguish supporting platforms from agent orchestration frameworks.
- Coordination and interoperability roles. Distinguish coordination of agents, tools, and workflows during execution from interoperability that structures and exchanges context across system boundaries.
- Coordination patterns and context boundaries. Explain how a coordination pattern distributes work and sets boundaries for context flowing between agents. Describe the shared state object's role as a runtime coordination contract.
- Complexity spectrum and pattern choice. Distinguish the broad complexity levels named here and justify choosing the most constrained pattern that meets the task's needs, starting with a single agent.
- Sequential pipeline fit. Describe why a sequential pipeline works well for a task with clear phases, using the section’s example of moving from evidence retrieval through drafting and citation validation to a final response.
- Error propagation safeguards. Explain why an early weak decision can affect later stages and what each stage should return to help contain that risk.
- Parallel branches and fan-in. Explain why independent subtasks suit a parallel pipeline and describe what the coordinator needs when their outputs are combined.
- Inter-agent revision loop. Explain how the loop pattern differs from an agent’s internal loop and how agents use it to improve work through revision.
- Code-enforced stop conditions. Explain where the loop’s stop conditions belong and why prompt instructions alone are insufficient.
- Specialized Agent Routing. Explain how a support assistant routes different kinds of requests to agents with the relevant specialty.
- Structured Routes and Fallbacks. Describe what a router output should contain and what should happen when its confidence is low.
- Unpredictable specialist paths. Explain why a network pattern fits work whose sequence of specialists cannot be known in advance, using the incident-response example.
- Explicit handoff information. Describe what each handoff must carry in a network pattern and what can go wrong if that information is missing.
- Hierarchical coordination roles. Describe how a top-level coordinator, managers, and workers divide responsibility in a hierarchical pattern.
- Downward and upward messages. Distinguish the context sent down the hierarchy from the information sent back up.
- Cross-boundary context exchange. Explain why agents can share context directly within one application but need interoperability protocols when collaboration crosses processes, services, frameworks, or organizations.
- A2A delegation and agent roles. Explain why agents need a standard way to share only relevant task context, and describe how client and server agents participate in an A2A interaction.
- Agent card capability manifest. Describe what an agent card is and how its operational information helps a client evaluate a potential collaborator before sending work.
- Tasks messages and artifacts. Distinguish the task, message, content part, and artifact in A2A execution, and explain why structured artifacts are returned.
- Task and context identifiers. Distinguish taskId from contextId and explain how a client uses each when coordinating related work.
- A2A communication patterns. Distinguish synchronous response, asynchronous polling, streaming, and push notifications by how updates reach the client and when each fits.
- AG-UI’s human interaction role. Explain why AG-UI is used between agents and user interfaces, in contrast to A2A communication between backend agents.
- User state and feedback. Explain how AG-UI keeps user interface changes aligned with agent state and lets people intervene in running workflows.
- ACP client server boundary. Explain the roles of the editor and coding agent in ACP and why a uniform interface is useful.
- ACP session and permissions. Trace a typical ACP session from capability negotiation through workspace-context exchange, proposed changes, and permission requests.
- LSP semantic code intelligence. Explain how an editor or coding harness uses LSP to obtain structured, language-aware information about a codebase instead of treating source files only as unstructured text.
- Token reduction with fact preservation. Explain how the example addresses context overflow by compressing a long conversation history to a target token size, checking that sentinel facts survive, and using the compressed context in an OpenAI LLM call.
- Tiered Context Loading. Explain what OpenViking’s L0, L1, and L2 levels contain and why an agent inspects cheaper levels before reading full content.
- Stateful customer support routing. Trace how the example classifies a customer question and routes it to the sales, technical support, or general agent using structured workflow state.
- Specialized sequential crew. Describe how specialized CrewAI agents work through a sequence of tasks, with each agent given its own role, goal, and backstory.
- Task output handoff boundary. Explain what the task’s context argument passes to the next agent and what it leaves out.
- DeepAgents context management patterns. Explain how DeepAgents uses a todo list, a virtual filesystem, and subagents to manage context during long-horizon tasks. Describe how keeping intermediate results in files leaves the active prompt with a compact working set.
- Simplified A2A message flow. Trace how the client uses the server’s agent card to discover its capabilities, select an interface, and send a request, and how the server returns a completed task-shaped response.
What it builds on
- Taxonomy for context sources (chapter 1) · Introduces the context sources that supply the raw material.
- The context window (chapter 1) · The context window as a limit on what a model call can carry.
- The anatomy of a skill (chapter 2) · The earlier introduction to the parts of an agent skill.
- Retrieval-augmented generation (chapter 3) · RAG as a way to retrieve external knowledge
- Memory vs state (chapter 5) · The distinction between memory and state helps frame why written information does not all have the same lifetime.
- State representation (chapter 5) · State representation provides the earlier treatment of how an agent’s state can be structured.
- State (chapter 5) · Introduces state in agentic systems.
- AI agents (chapter 1) · Introduces AI agents.
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.
- Context management and orchestration: Distinguish context management from context orchestration, and explain how both relate to the six context sources.
Why it matters: The distinction separates preparing one model call’s context from moving context through a larger 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.
- Three model call limits: Distinguish the context window, token budget, and attention budget, and explain why filling the available window can still make a call slower, costlier, or less focused.
Why it matters: A prompt can be within the model's limit yet still waste resources or weaken the material that matters. - Integrated context management techniques: Explain how context management uses selection, writing, compression, and isolation together to shape the context for an individual invocation.
Why it matters: These four moves give the system ways to manage limited space, cost, and attention for each call.
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.
- Context selection purpose: Explain that context selection, or context assembly, decides what information enters the model context for a specific invocation and aims to maximize the utility of its tokens rather than the amount of information supplied.
Why it matters: More context is not necessarily better context. - Distraction from irrelevant context: Explain why irrelevant context makes selection important, and describe the agent behaviors the section identifies as signs of distraction.
Why it matters: Recognizing distraction helps explain why selecting context matters even when relevant evidence is already present.
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.
- Informativity Over Exhaustiveness: Explain why the active prompt should contain only high-signal information sufficient for the next decision, and describe the test for excluding material.
Why it matters: This principle helps keep the model focused on evidence that matters for its next decision. - Position Aware Context Placement: Explain how the lost-in-the-middle effect informs where critical and supporting material should go in a long prompt.
Why it matters: Placement can affect whether the model gives decisive information enough attention. - Iterative Context Curation: Describe why selected context must be revised during an agent's work and what kinds of changes that revision can make.
Why it matters: An agent's useful context changes as its task progresses. - Progressive Context Disclosure: Explain how progressive disclosure delays token costs until information is needed, using the three agent-skill layers and an example beyond skills.
Why it matters: Staging detail avoids spending context-window space on resources the agent may never use.
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.
- Just-in-time candidate retrieval: Explain how retrieval finds candidate information outside the context window and why an agent may load it only as the task unfolds.
Why it matters: Just-in-time retrieval keeps potentially useful information available without putting it all in the prompt immediately. - Candidate filtering dimensions: Describe how filtering screens retrieved candidates before prompt assembly across relevance, quality, and trust.
Why it matters: Finding a candidate is not enough; filtering helps prevent unsuitable material from affecting the prompt. - Token-budget context prioritization: Explain how prioritization allocates limited prompt space among filtered candidates, including current needs and tool outputs.
Why it matters: Prioritization gives the next decision the context it needs without requiring every candidate to occupy prompt space.
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.
- Recoverable context outside the prompt: Explain how context writing saves useful information outside the active context window while leaving the agent a compact prompt it can work from.
Why it matters: The agent can keep working with a smaller prompt without giving up access to the saved information. - Writing before lossy compression: Distinguish writing from compression as ways to relieve context pressure, and explain why writing should come first.
Why it matters: Saving intact material first avoids losing details the agent might need later.
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.
- Recoverable written context: Explain why saved context must be easy to find, inspect, and reload, and how artifact metadata helps make that possible.
Why it matters: A saved detail cannot help the agent if it cannot find and reload it when needed. - Fidelity across the writing boundary: Explain what the external store must preserve when information is offloaded before summarization or masking, and how its role differs from the prompt's.
Why it matters: Offloading saves prompt space without sacrificing details the agent may need to recover later. - Separate context lifetimes: Describe why temporary, session, durable user, and compliance information should be kept in distinct stores or namespaces.
Why it matters: Keeping records with different lifetimes apart makes it possible to discard short-lived work without treating durable records the same way. - Controlled store mutation: Explain why written context should be updated and organized rather than left as an ever-growing append-only log.
Why it matters: A store that is not maintained can become harder to use as it grows. - Least exposure of records: Explain why a system should limit which persistent records it exposes for a task and where access controls should be enforced.
Why it matters: Limiting exposure reduces unnecessary access to sensitive information while the agent works.
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.
- Filesystem Context Storage: Explain how agents use files for overflow context and why structured directories make stored material practical to find and read.
Why it matters: Organized files let an agent keep bulky material available without placing it all in the prompt. - External Store Selection: Distinguish the access patterns served by the external storage options named in this section.
Why it matters: Choosing storage by access pattern makes preserved context useful when the agent needs it. - Working Scratchpad Use: Describe what an agent keeps in a working scratchpad and how it uses the scratchpad during a long workflow.
Why it matters: A scratchpad keeps intermediate work accessible across steps without repeatedly including the whole conversation. - Offloading And Prompt References: Explain how context writing handles a large order history and identify the limit of preserving it outside the prompt.
Why it matters: Preserving information outside the prompt helps with overflow, but the information needed right now must still be manageable.
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.
- Purpose and timing of compression: Explain why compression is useful when active context keeps growing but its contents remain relevant: it saves tokens without losing the state and next actions needed to continue the task.
Why it matters: It helps you recognize when shortening context is safer than discarding it. - Compression versus deletion: Distinguish compression from deletion and explain why the difference matters for later model decisions.
Why it matters: A compressed account still shapes the model’s behavior; deleted material does not remain in active context.
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.
- Task-critical detail preservation: Explain why compression must protect details that cannot easily be reconstructed, such as constraints, decisions, identifiers, and current task state.
Why it matters: A shorter context is not useful if it discards a constraint or identifier the task still needs. - Structured summary fields: Explain how a structured summary exposes omissions that a freeform summary can hide, using the section's example fields.
Why it matters: Explicit fields make it easier to spot a missing decision or next step before the task resumes. - Incremental compression and drift: Describe how compressing only newly accumulated messages and merging them into a persistent summary avoids repeatedly rewriting history.
Why it matters: Limiting rewrites reduces the chance that an earlier fact changes as summaries are updated. - Explicit compression triggers: Describe why compression should have a visible trigger and distinguish the trigger options given in the section.
Why it matters: An explicit trigger makes compression predictable and gives offloading a chance to help first. - Task-continuation evaluation: Explain why compression quality is judged by whether the task can continue, rather than by textual similarity alone, and what probes can check.
Why it matters: A faithful-looking summary can still fail at the moment the agent needs to act on it.
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.
- Anchored iterative summarization: Explain how summarization shortens prior interactions, tool outputs, or phase results while retaining information needed to continue the task. Describe why a long session is better served by merging a summary of only the newly removed span into the existing summary.
Why it matters: A useful short summary lets a long-running task continue without repeatedly carrying its full history. - Trimming and critical state: Distinguish trimming from summarization and explain when removing messages is safe enough to use. Describe why critical task state should remain available outside the message list.
Why it matters: Deleting low-value messages saves context, but an irreplaceable detail can disappear with them. - Observation masking and offloading: Explain how observation masking reduces the prompt cost of bulky tool results while retaining a way to recover them. Distinguish masking from offloading and identify which observations should remain unmasked.
Why it matters: Large tool outputs can leave the active prompt without sacrificing their provenance or recoverability.
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.
- Distinct bounded working contexts: Distinguish context isolation from selection, writing, and compression: isolation separates work across context windows rather than managing tokens within or around one context.
Why it matters: It explains why isolation is an architectural choice, not just a way to shorten a prompt. - Coordinator and local work: Describe how a coordinator and bounded execution contexts divide responsibilities, including what local work is returned to the parent context.
Why it matters: The division of responsibilities lets local work proceed without filling the parent context with every intermediate detail.
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.
- One Context One Concern: Explain why research, coding, testing, and security should have separate contexts rather than sharing one.
Why it matters: Separating concerns preserves the benefits that context isolation is meant to provide. - Least Context Boundaries: Describe how to limit an isolated unit to the context and access its objective requires, including enforceable tool, file, and memory boundaries.
Why it matters: A narrow, enforceable boundary keeps an isolated unit from receiving or changing more than its task calls for. - Separated Context Authority: Explain why instructions, evidence, observations, user data, and runtime configuration should remain distinguishable, and when runtime context should be exposed.
Why it matters: Keeping untrusted content out of control paths is a structural defense against prompt injection. - Structured Output Contract: Describe what a subagent should return to its coordinator and what should remain in the child workspace unless requested.
Why it matters: A structured handoff lets the coordinator use a subagent’s result without importing its entire context. - Justified Isolation Overhead: Justify when isolation is worth its coordination cost and when a single curated context is preferable.
Why it matters: Isolation is useful only when its benefits outweigh the extra coordination it creates.
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.
- Bounded subagent context: Explain how a coordinator delegates a bounded task to a subagent without bringing the subagent’s full working history into its own context. Describe the focus gained and the coordination needed for dependent tasks.
Why it matters: A well-bounded subagent can do its job without filling the coordinator’s context with its entire work or receiving unrelated capabilities. - Selective state fields: Describe how state partitioning keeps different kinds of agent state in structured fields and exposes only the fields needed for a given model step.
Why it matters: Separating stored state from prompt contents lets a step use what it needs without loading every prior result. - Sandboxed execution state: Explain how an agent can act on a live sandbox while keeping its runtime state out of prompt memory, and state the safety benefit described here.
Why it matters: A sandbox lets an agent work with persistent runtime resources without carrying their full contents in its prompt.
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.
- Orchestration and management roles: Distinguish context orchestration from context management: orchestration routes execution, delegation, and intermediate results, while management decides what enters a single context window.
Why it matters: The distinction separates decisions about what an invocation sees from decisions about what the system does next. - Runtime state coordination: Trace how the orchestrator and context manager use the runtime state object between invocations.
Why it matters: Runtime state lets routing decisions and invocation-specific context stay coordinated across steps. - Evolving agentic context: Explain why context changes during agentic execution, contrasting it with a simple single-turn application.
Why it matters: A changing context explains why an agentic system must keep coordinating decisions across steps.
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.
- Runtime models and framework categories: Explain what an orchestration model describes and distinguish it from a framework category. State that one framework or production system can use more than one orchestration model.
Why it matters: It lets you describe how a system runs without assuming its framework determines one fixed control pattern. - Imperative code control flow: Describe how imperative orchestration expresses control in ordinary application code and explain its principal trade-off.
Why it matters: This trade-off helps explain why direct code control may be attractive yet difficult to follow at scale. - Graph based state transitions: Explain how graph-based orchestration represents work, transitions, and state, and why that representation helps make execution understandable.
Why it matters: An explicit graph makes it easier to see and explain where execution and context go. - LLM coordination and external guardrails: Describe who chooses the next action in agent-driven orchestration and why limits must be enforced outside the LLM's reasoning.
Why it matters: Flexible LLM-directed execution needs controls the coordinator cannot merely promise to follow. - Platform mediated control logic: Describe what controls execution in platform-mediated orchestration and distinguish supporting platforms from agent orchestration frameworks.
Why it matters: It prevents treating every platform that runs or connects AI workflows as an agent orchestration framework.
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.
- Coordination and interoperability roles: Distinguish coordination of agents, tools, and workflows during execution from interoperability that structures and exchanges context across system boundaries.
Why it matters: This distinction clarifies whether an orchestration concern is about running work together or exchanging context between systems. - Orchestrator as telemetry source: Explain why the orchestrator is a primary telemetry source and describe the execution signals it tracks.
Why it matters: The orchestrator’s view of transitions provides signals for monitoring execution.
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.
- Coordination patterns and context boundaries: Explain how a coordination pattern distributes work and sets boundaries for context flowing between agents. Describe the shared state object's role as a runtime coordination contract.
Why it matters: A pattern changes not just who does the work, but how context and results move through the system. - Complexity spectrum and pattern choice: Distinguish the broad complexity levels named here and justify choosing the most constrained pattern that meets the task's needs, starting with a single agent.
Why it matters: Choosing only the complexity a task needs helps preserve predictability and debuggability.
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.
- Sequential pipeline fit: Describe why a sequential pipeline works well for a task with clear phases, using the section’s example of moving from evidence retrieval through drafting and citation validation to a final response.
Why it matters: Clear phases make it easier to see when this coordination pattern fits a task. - Error propagation safeguards: Explain why an early weak decision can affect later stages and what each stage should return to help contain that risk.
Why it matters: Making uncertainty visible at each stage helps keep an early mistake from silently shaping the rest of the pipeline.
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.
- Parallel branches and fan-in: Explain why independent subtasks suit a parallel pipeline and describe what the coordinator needs when their outputs are combined.
Why it matters: This keeps parallel work useful without burdening the coordinator with entire branch histories.
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.
- Inter-agent revision loop: Explain how the loop pattern differs from an agent’s internal loop and how agents use it to improve work through revision.
Why it matters: This distinguishes coordination between agents from the reasoning-and-action loop inside one agent. - Context carried between rounds: Describe what context should be carried into the next revision round and why.
Why it matters: Keeping only the relevant revision material prevents the loop’s context from growing with every round. - Code-enforced stop conditions: Explain where the loop’s stop conditions belong and why prompt instructions alone are insufficient.
Why it matters: A revision loop needs reliable limits even when the agents do not stop themselves.
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.
- Specialized Agent Routing: Explain how a support assistant routes different kinds of requests to agents with the relevant specialty.
Why it matters: Routing lets a support assistant hand a request to an agent suited to that type of problem. - Structured Routes and Fallbacks: Describe what a router output should contain and what should happen when its confidence is low.
Why it matters: A stated confidence and fallback path keep an uncertain routing choice from being treated as definite.
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.
- Unpredictable specialist paths: Explain why a network pattern fits work whose sequence of specialists cannot be known in advance, using the incident-response example.
Why it matters: This helps you recognize when flexible specialist-to-specialist routing is useful. - Explicit handoff information: Describe what each handoff must carry in a network pattern and what can go wrong if that information is missing.
Why it matters: Flexible routing only works if the next agent can pick up the case without losing its direction or prior decisions.
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.
- Hierarchical coordination roles: Describe how a top-level coordinator, managers, and workers divide responsibility in a hierarchical pattern.
Why it matters: The division of responsibilities explains how a large workflow can be organized across teams of agents. - Downward and upward messages: Distinguish the context sent down the hierarchy from the information sent back up.
Why it matters: Clear assignments and concise returns keep context useful across coordination layers. - Hierarchy suitability and cost: Explain when hierarchical coordination fits and what justifies adding another layer.
Why it matters: A hierarchy should solve a coordination or context problem, not add layers for their own sake.
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.
- Cross-boundary context exchange: Explain why agents can share context directly within one application but need interoperability protocols when collaboration crosses processes, services, frameworks, or organizations.
Why it matters: This distinction explains why an assistant needs a protocol to consult an agent in an external system.
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.
- A2A delegation and agent roles: Explain why agents need a standard way to share only relevant task context, and describe how client and server agents participate in an A2A interaction.
Why it matters: This explains how agents can collaborate without copying entire prompts or relying on custom integration code. - Agent card capability manifest: Describe what an agent card is and how its operational information helps a client evaluate a potential collaborator before sending work.
Why it matters: A client needs to judge what an agent can do and how to reach it before delegating. - Agent card discovery routes: Describe how a client obtains an agent card and distinguish the three discovery strategies given in the section.
Why it matters: Discovery supplies the information a client needs to identify and connect to a collaborator. - Tasks messages and artifacts: Distinguish the task, message, content part, and artifact in A2A execution, and explain why structured artifacts are returned.
Why it matters: These distinctions explain how A2A carries both ongoing work and usable results. - Task and context identifiers: Distinguish taskId from contextId and explain how a client uses each when coordinating related work.
Why it matters: Separate identifiers let a client track individual jobs without losing their shared conversational context. - A2A communication patterns: Distinguish synchronous response, asynchronous polling, streaming, and push notifications by how updates reach the client and when each fits.
Why it matters: The communication pattern determines when and how an agent receives another agent’s progress or result.
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.
- AG-UI’s human interaction role: Explain why AG-UI is used between agents and user interfaces, in contrast to A2A communication between backend agents.
Why it matters: The distinction clarifies which protocol supports interaction with a person rather than communication between backend agents. - Live and generated interfaces: Describe how real-time streaming and generative UI let a client display an agent’s progress and interactive content.
Why it matters: These capabilities make agent activity visible while allowing the interface to present useful controls. - User state and feedback: Explain how AG-UI keeps user interface changes aligned with agent state and lets people intervene in running workflows.
Why it matters: The interface is not just a display: user actions can change the context in which the agent continues working. - Client-side tool execution: Describe what frontend tool integration allows an agent to do.
Why it matters: Some agent-triggered actions need to happen in the user’s interface or device environment.
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.
- ACP client server boundary: Explain the roles of the editor and coding agent in ACP and why a uniform interface is useful.
Why it matters: This boundary lets coding agents use editor context without tying each agent to a particular IDE. - ACP session and permissions: Trace a typical ACP session from capability negotiation through workspace-context exchange, proposed changes, and permission requests.
Why it matters: The sequence shows how an agent receives relevant workspace information while keeping consequential actions subject to user permission.
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.
- LSP semantic code intelligence: Explain how an editor or coding harness uses LSP to obtain structured, language-aware information about a codebase instead of treating source files only as unstructured text.
Why it matters: It explains where a coding agent gets reliable information about code structure without relying solely on raw file text. - Complementary ACP and LSP roles: Distinguish ACP’s session and workspace coordination from LSP’s provision of language-aware evidence to a coding agent.
Why it matters: The distinction clarifies why an agentic development environment may use both protocols rather than treating them as substitutes.
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.
- Token reduction with fact preservation: Explain how the example addresses context overflow by compressing a long conversation history to a target token size, checking that sentinel facts survive, and using the compressed context in an OpenAI LLM call.
Why it matters: A shorter context is only useful if the model can still answer with the information the task requires. - Production compression regression checks: Describe why the example uses deterministic assertions as a regression check and why production sentinel facts should include exact identifiers and state markers, not just high-level facts.
Why it matters: A summary can sound correct while silently dropping the exact detail needed for the next action.
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.
- Filesystem-Based Context Navigation: Describe how OpenViking lets agents navigate knowledge, memory, and skills through a virtual filesystem rather than traditional flat vector storage.
Why it matters: The filesystem model explains how an agent can explore available context before choosing what to read. - Tiered Context Loading: Explain what OpenViking’s L0, L1, and L2 levels contain and why an agent inspects cheaper levels before reading full content.
Why it matters: Loading detail only when it is needed avoids filling the agent’s context with full documents from every candidate.
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.
- Stateful customer support routing: Trace how the example classifies a customer question and routes it to the sales, technical support, or general agent using structured workflow state.
Why it matters: The example makes the router pattern concrete: one decision directs each question to an appropriate agent. - Production routing safeguards: Explain how a production router should handle low-confidence or ambiguous classifications differently from the minimal example.
Why it matters: An explicit fallback keeps uncertain routing decisions from being treated as ordinary general questions.
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.
- Specialized sequential crew: Describe how specialized CrewAI agents work through a sequence of tasks, with each agent given its own role, goal, and backstory.
Why it matters: Specialization lets a crew handle multi-role work without putting every agent’s context into one window. - Task output handoff boundary: Explain what the task’s context argument passes to the next agent and what it leaves out.
Why it matters: An explicit handoff gives the next agent what it needs without carrying over the previous agent’s entire context.
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.
- DeepAgents context management patterns: Explain how DeepAgents uses a todo list, a virtual filesystem, and subagents to manage context during long-horizon tasks. Describe how keeping intermediate results in files leaves the active prompt with a compact working set.
Why it matters: These built-in patterns make DeepAgents a convenient starting point for long-horizon workflows.
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.
- Simplified A2A message flow: Trace how the client uses the server’s agent card to discover its capabilities, select an interface, and send a request, and how the server returns a completed task-shaped response.
Why it matters: The example shows how discovery information leads to an agent-to-agent request rather than being merely descriptive metadata. - Teaching scaffold versus production A2A: Distinguish the conceptual A2A ideas demonstrated by the example from the protocol features and safeguards a production implementation would need.
Why it matters: Treating the example as conceptual avoids mistaking a minimal demonstration for a deployable A2A 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
- Evaluation (chapter 8) · The idea that context is actively managed through operations such as selection, writing, compression, and isolation.
- Context rot (chapter 8) · Assumes that context can be selected for what a task needs.
- Context distraction (chapter 8) · Connects the symptoms described here to the later discussion of context distraction.
- Privacy (chapter 9) · Privacy considerations build on the need to restrict exposure of sensitive persistent context.
- Context management for coding agents (chapter 11) · the general idea of context compression
- Context selection and compression (chapter 12) · Prior discussion of context compression provides the operational background.
- Safety and security (chapter 9) · Connects context boundaries to safety and security concerns.
- Understanding the framework landscape (chapter 10) · Assumes familiarity with context orchestration across a workflow.
Concepts explained in this chapter
- context isolationSeparating work into distinct context windows so unrelated or competing information does not occupy the same working set.
- A2AA2A is an open protocol standard for interoperability and context exchange between independent agentic applications.
- context writingContext writing is the technique of moving information out of an active prompt into storage while retaining a reference to relevant stored information.
- agent cardAn agent card is a standardized capability manifest that describes an agent’s identity, capabilities, skills, interfaces, and security requirements.
- agent discoveryThe process by which a client agent retrieves another agent’s capabilities and connection parameters.
- client agentThe client agent is the example application’s agent that discovers the server agent and sends it a request.
- server agentA server agent is an A2A interaction role that exposes compatible endpoints, processes requests, and returns results.
- agent orchestrationAgentic orchestration coordinates an agent's actions, tools, and execution steps toward a task.
- context assemblyContext selection is the choice of which information enters an AI system's active context.
- compactionA process that summarizes an agent conversation and discards lengthy details while preserving high-level task information.
- artifactAn A2A artifact is a concrete output produced by a server agent, such as a report, diagram, data table, or code file.
- taskAn A2A task is a stateful unit of work with an explicit lifecycle that can support long-running operations and multi-turn collaboration.
- compressionThe process of representing information with fewer bits or tokens while retaining relevant information.
- context managementContext management is the shaping of context through selecting, writing, compressing, and isolating information before model consumption.
- routerA routing agent analyzes an incoming query and directs it to a specialized retrieval tool or knowledge store.
- sandboxingExecution of generated code or commands within a restricted environment that limits their access and effects.
- summarizationThe production of a shorter representation of information while retaining selected content.
- subagentA subagent is an agent assigned a subordinate task within a larger agent-driven process.
- attention budgetAn attention budget is the finite capacity a model has to distribute attention across the information it receives.
- context windowA context window is the bounded amount of token context a language model can process for an inference request.
- token limitA token budget is a limit on the tokens allocated to an AI system or request.
- interoperability protocolAn interoperability protocol is a standardized set of rules and formats for exchanging information across system boundaries.
- isolationSeparating context content or reasoning scopes to control information exposure.
- evaluationEvaluation is the structured testing and measurement of an AI system's behavior and performance.
- pipelineA pipeline is a sequence of connected computational components that passes data through processing steps.
- agent skillA reusable set of instructions and resources that extends an agent's capabilities for a specialized workflow.
- human-in-the-loopHuman oversight is the involvement of people in monitoring, reviewing, or controlling consequential AI decisions and actions.
- telemetryAutomatically collected runtime evidence about a software system's operation, including events, measurements, and request-flow data.
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.
