Ultralytics YOLO27: Join the waitlist.
License YOLO
Back to Ultralytics Glossary

Context Engineering

Context engineering decides what fills a model's context window at each step, from instructions and retrieved data to tool results and memory.

Context engineering is the practice of deciding what information goes into a model's context window at each step of an AI application: the instructions, examples, retrieved documents, tool definitions, tool results, memory, and conversation history, along with how much of each to include, in what order, and what to leave out. The term spread in mid-2025, as AI agents began running tasks with dozens or hundreds of steps. Andrej Karpathy called it "the delicate art and science of filling the context window with just the right information for the next step," and Anthropic's Effective Context Engineering for AI Agents describes it as curating "the optimal set of tokens" during inference. Prompt engineering, writing the instructions themselves, is one part of it.

Why Context Needs Engineering#

A large language model (LLM) knows only its training data and what is in its context, so missing context produces generic answers or hallucinations. Too much context fails too. Accuracy drops as inputs grow, the effect called context rot, and the Lost in the Middle study found that models use information best at the beginning or end of a long input and worst in the middle. Anthropic describes context as an attention budget with diminishing returns, where every added token draws it down. Every token also adds cost and inference latency. An agent makes the problem acute, because each step appends tool calls and their results, so the context grows with every action whether or not the new material still matters.

Core Strategies#

LangChain's context engineering overview groups the techniques into four strategies, which map onto the long-horizon methods Anthropic describes:

  • Write: Save information outside the context window, in a scratchpad, a notes file, or long-term memory, so it survives after the conversation moves on. Anthropic calls this structured note-taking.
  • Select: Pull in only what the current step needs, such as relevant passages, memories, or tool descriptions. Anthropic describes agents that keep lightweight references, such as file paths or queries, and load the content just in time.
  • Compress: Keep only the tokens the task needs, by summarizing or trimming. Compaction summarizes a nearly full context and continues in a fresh window from that summary.
  • Isolate: Split work across sub-agents with clean context windows that return condensed results to a lead agent, or keep bulky data in a sandbox or state object instead of the context.

Order and stability matter as well as content. Prompt caching reuses only an identical prefix, so contexts are usually laid out with fixed instructions and tool definitions first and changing material last. A survey of more than 1,400 papers by Lingrui Mei and colleagues organizes the field into context retrieval and generation, context processing, and context management, implemented in retrieval-augmented generation, memory systems, tool-integrated reasoning, and multi-agent systems.

Tools, Protocols, and Skills#

Much of an agent's context comes from tools, and the Model Context Protocol (MCP), which Anthropic introduced in November 2024 and later donated to a foundation under the Linux Foundation, standardizes how applications expose tools and data to models. Tool definitions are context too: every tool an agent can call takes up tokens in every request, so some agents load tool definitions only when a task needs them. Agent skills apply the same idea to instructions, packaging guidance and reference files as folders that an agent loads only when a task calls for them.

Ultralytics Agent Skills use this design for coding agents working with Ultralytics YOLO. The skills load only when a relevant task is requested, a yolo router skill maps each request to the lifecycle stage it involves, such as datasets, training, or export, and version-sensitive facts such as weight names, training arguments, and export formats live in catalogs grounded against a pinned ultralytics release, with every skill telling the agent to trust the installed package where the two differ.

  • Prompt engineering: Concerns how to word instructions and examples. Context engineering manages everything else that reaches the model too, across every step of an application.
  • Prompt enrichment: Adds data to a single request before it reaches the model, one of the select operations in context engineering.
  • Context window: The model's maximum input length, which sets the budget. Context engineering decides how to spend it, and a larger window does not remove the need, since accuracy declines as the window fills.
  • Fine-tuning: Changes what the model knows by updating its weights. Context engineering changes what the model sees at inference time and leaves the weights alone.

Explore solutions

Computer vision in sports

Computer vision in sports

Discover how Ultralytics YOLO powers sports vision with player and ball tracking, performance analytics, coaching insights, and athlete rehabilitation.
Learn more
Computer vision for aerial imagery

Computer vision for aerial imagery

Turn drone and aerial imagery into real-time insights for agriculture, aquaculture, conservation, and geospatial analysis with Ultralytics YOLO.
Learn more
Computer vision in aerospace

Computer vision in aerospace

Apply computer vision in aerospace with Ultralytics YOLO for aircraft inspection, runway FOD detection, airport ground operations, and composite defect detection.
Learn more
Computer vision in security

Computer vision in security

Protect every site with Ultralytics YOLO models. Vision AI powers perimeter monitoring, threat detection, license-plate recognition, and workplace safety.
Learn more
Computer vision in robotics

Computer vision in robotics

Power smarter machines with Ultralytics YOLO models. Vision AI in robotics drives autonomous navigation, perception, object tracking, and real-time control.
Learn more
Computer vision in logistics

Computer vision in logistics

Streamline logistics with Ultralytics YOLO models. Vision AI enables package inspection, sorting, vehicle tracking, and real-time warehouse safety monitoring.
Learn more
Computer vision in retail

Computer vision in retail

Reimagine retail with Ultralytics YOLO models. Vision AI powers inventory tracking, shelf monitoring, queue management, and smarter customer insights.
Learn more
Computer vision in healthcare

Computer vision in healthcare

Build healthcare solutions with Ultralytics YOLO models. Vision AI in healthcare powers faster medical imaging, smarter diagnostics, and patient monitoring.
Learn more
Computer vision in manufacturing

Computer vision in manufacturing

Optimize manufacturing with Ultralytics YOLO models. Vision AI drives quality control, defect detection, PPE compliance, and assembly line automation.
Learn more
Computer vision in automotive

Computer vision in automotive

Apply computer vision in automotive with Ultralytics YOLO models. Vision AI elevates road safety, driver assistance, and vehicle automation for smarter roads.
Learn more
Computer vision in agriculture

Computer vision in agriculture

Bring vision AI to smart agriculture with Ultralytics YOLO models. Power crop monitoring, livestock tracking, and precision farming for higher, smarter yields.
Learn more

Let's build the future of AI together!

Begin your journey with the future of machine learning