liveBook · Manning

Context engineering

As explained in Build an AI Agent (From Scratch)

The discipline of designing which information is provided to a language model, when it is provided, and how it is represented for task completion.

Context engineering is the discipline of providing a language model with the information it needs, at the right time and in the right form. Context includes system prompts, user messages, conversation history, tool results, and retrieved documents. Because the model generates a response from information in its context window, missing information can prevent it from completing a task. section 1.5 section 1.5.2

Unlike prompt engineering alone, context engineering manages information that changes as an agent works. It determines how to process tool results, how much history to retain, and when to retrieve external knowledge. section 1.5.2

Five strategies organize the work:

  • Generate: Add model-produced plans or reflections to help structure and revise a task. section 1.5.4
  • Retrieve: Bring in external information through searches, queries, files, or document retrieval. section 1.5.4
  • Write: Save useful information outside the context, such as memories, intermediate results, or generated code. section 1.5.4
  • Reduce: Summarize, delete, or filter information to keep the context focused. section 1.5.4
  • Isolate: Separate tasks or tools into environments, such as sandboxes or specialized agents, so each context remains manageable. section 1.5.4

Curating an agent request

An agent can keep execution state in an ExecutionContext while constructing an LlmRequest containing only what the model needs for a particular call. Tool results return to the execution state; the next request selects and formats the relevant information rather than sending everything automatically. section 4.2.2

Figure 4.3 Information flow in the agent architecture. ExecutionContext sits at the center, managing all execution state. Arrows show (1) context to LlmRequest to LlmClient for outgoing LLM calls, (2) LlmResponse back to context for incoming responses, and (3) bidirectional flow between context and tools for tool execution.
Shape

Description automatically generated with low confidence

Follow the flow between execution state, model requests and responses, and tools. section 4.2.2

Offloading tool details

A workspace can keep detailed tool definitions outside the prompt. Core tools remain available directly, while skill names and short descriptions point the agent to files it can read when needed. The agent can also generate code for one-time functionality, leaving tool information and results that do not require model judgment outside the context. section 8.5.5 section 8.6

Context engineering is part of the broader agent harness: the tools, memory, execution environment, and other support surrounding the model. Separating these concerns helps diagnose whether a failure came from missing or misinterpreted context, an unexpected tool result, or another part of the agent. section 1.5.5 section 1.0

How Build an AI Agent (From Scratch) covers it

How deep it goes
Defines five strategies and traces request construction, with further implementation distributed across agent components.
Examples
Uses a curated LLM request and workspace-based skill disclosure to illustrate context selection.
What you can do after
Evaluate and understand which information to include, omit, or format for a model call.
How it connects
Connects context engineering to prompt engineering, agent memory, retrieval, planning, and harness engineering.

Also explained in

Compare how 2 books explain context engineering →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Build an AI Agent (From Scratch). The section links point to the parts of the book it draws on.