Agentic & Tool-Use

Context Engineering

As agents run over many turns, writing one clever prompt stops being the job. Context engineering is the discipline of curating the whole set of tokens an agent sees, its system instructions, tools, examples, message history, retrieved data, and memory, and keeping that set as small and high-signal as possible. The guiding idea is that attention is a finite resource, so every token in the window should earn its place.

*These are learning tools, not prompts. They teach you to write your own, think of them as training wheels that guide you while you learn, then fall away once you can ride on your own.

The Core Insight

From Prompt Engineering to Context Engineering

Prompt engineering asks how to word a single instruction well. That matters, but it is only part of the picture once you are building an agent that runs for many turns, calls tools, retrieves documents, and remembers things between steps. At that point the model's context is not one prompt; it is an evolving pile of instructions, tool definitions, past messages, and fetched data. Managing that pile is a discipline in its own right.

Context engineering treats the context window as a finite, precious resource. A model's attention is limited, and cramming the window with everything that might be relevant makes it harder, not easier, for the model to find what matters. The goal is to curate the smallest possible set of high-signal tokens: the instructions the agent actually needs now, the tools it will actually use, the history that still matters, and nothing else.

Because the context changes at every turn, this is ongoing work rather than a one-time setup. Practitioners compact long histories into summaries, let the agent take notes it can reload later, retrieve information just in time rather than dumping it all up front, and isolate sub-tasks in their own context so one job's clutter does not crowd another. Guidance on this discipline comes directly from the teams building agents, making it a first-party account of what works.

A Discipline, Not a Single Trick

Context engineering is a practice, drawn from official guidance by teams building production agents, rather than one algorithm. It spans system instructions, tools, examples, message history, retrieved data, and memory. The through-line is a mindset: attention is finite, so curate the fewest high-signal tokens the agent needs at each step.

Practices of Context Engineering

Four ways to keep the context small, current, and high-signal

1

Curate What Goes In

Include only the system instructions, tools, and examples the agent needs for the current work. Trim redundant tool definitions and over-long instructions, since every extra token competes for the model's attention.

Example

An agent that only reads files does not need write or delete tools in its context, so they are left out to reduce noise and risk.

2

Compact the History

When the message history grows long, summarize the older turns into a compact record and drop the raw detail. The agent keeps what it learned without carrying every word of the conversation forward.

Example

Twenty turns of debugging are compacted into a short summary of what was tried and what remains, freeing the window.

3

Retrieve Just in Time

Rather than loading everything the agent might need up front, fetch information at the moment it is needed and let the agent take notes it can reload later. The window holds what is relevant now, not everything that could ever be relevant.

Example

The agent looks up a specific API reference when it is about to call that API, instead of pasting the whole documentation in advance.

4

Isolate Sub-Tasks

Give a distinct sub-task its own context, so its working detail does not crowd the main agent's window. The main agent receives only the sub-task's result, keeping its own context clean.

Example

A sub-agent researches a topic in its own window and returns a short summary, sparing the main agent the raw search results.

See the Difference

Dumping everything in versus curating the context

Everything in the Window

Load It All Up Front

Every tool, all the documentation, and the full history are packed into the context in case they are needed, leaving the model to find the signal in the noise.

Effect

Attention is spread thin, relevant details get buried, cost rises, and long runs eventually overflow the window.

Signal lost in a crowded window
VS

Context Engineering

Curate for Each Turn

The window holds the smallest high-signal set: the needed tools and instructions, a compacted history, and information retrieved just in time.

Effect

The model's attention lands on what matters, cost stays controlled, and long-running agents keep working without overflowing.

High-signal window, sustainable long runs

Practice Responsible AI

Always verify AI-generated content before use. AI systems can produce confident but incorrect responses. When using AI professionally, transparent disclosure is both best practice and increasingly a legal requirement.

Most US states are actively legislating AI transparency and accountability. Critical thinking remains your strongest tool against misinformation.

Context Engineering in Action

See the practices applied to real agent problems

Problem

An agent has forty tools in its context and keeps picking the wrong one for the task.

Context Engineering

Curate: expose only the handful of tools relevant to the current workflow, and clarify each tool's description.

Result: with a smaller, clearer tool set, the agent selects the right tool far more reliably, because there is less to confuse it.

Problem

A support agent's session grows so long the earliest, important context is about to fall out of the window.

Context Engineering

Compact: summarize the resolved parts of the conversation into a short record and keep the open issue in full.

Note-take: the agent writes down the customer's key facts so it can reload them later.

Result: the session continues coherently without carrying every prior message.

Problem

A task needs facts from many documents, but pasting them all would overflow the context.

Context Engineering

Retrieve just in time: fetch a document only when the agent is ready to use it, then set it aside.

Isolate: hand deep reading to a sub-agent that returns a summary.

Result: the main agent works from concise findings, never drowning in raw sources.

When to Practice Context Engineering

Essential for agents; lighter touch for single prompts

Perfect For

Multi-Turn Agents

Any agent that runs over many turns needs its context managed, since the window fills with tool calls, results, and history over time.

Tool-Heavy Systems

When an agent has many tools or connects to external services, curating which are in context keeps selection accurate and the window lean.

Long-Running Sessions

Conversations and tasks that outgrow the window rely on compaction and note-taking to keep the important context alive.

Cost and Latency Control

Because tokens drive both cost and speed, keeping the window small and relevant is a direct lever on how much an agent costs to run.

Lighter Touch When

Single-Shot Prompts

For a one-off request with no tools or history, ordinary prompt engineering covers most of what you need.

Small, Fixed Context

If everything the task needs comfortably fits and never changes, elaborate curation adds effort without much payoff.

Short Interactions

Brief exchanges rarely approach the window limit, so compaction and just-in-time retrieval have little to manage.

Use Cases

Where context engineering delivers the most value

Production Agents

Keep deployed agents reliable and affordable by curating their context every turn instead of packing the window and hoping.

Long Conversations

Sustain assistants through extended sessions with compaction and note-taking, so early context is not lost as the chat grows.

Multi-Agent Systems

Isolate each agent's working context so sub-tasks return clean summaries rather than flooding a shared window.

Retrieval Systems

Fetch information just in time and set it aside after use, so a knowledge-heavy agent stays within its window.

Cost Optimization

Cut the token bill of an agent by trimming its window to the high-signal essentials rather than paying for unused context.

Coding Agents

Load the relevant files and references on demand, keeping a software agent focused on the code that matters right now.

Where Context Engineering Fits

The agent-era successor to prompt engineering

System Prompting Set the Role Standing instructions
Context Structure Organize the Input Order and delimit content
Context Engineering Manage the Whole Context Curate across the agent loop
Agentic Context Engineering Evolve a Playbook Self-improving context
Chain These

Context engineering builds on system prompting and context structure and extends them across a whole agent loop. Pair it with strong tool design, so the tools you keep in the window are ones the agent can use well.

Curate What the Model Sees

Explore how a lean, high-signal context improves an agent in the Prompt Builder, or see related agentic techniques.