Context Engineering

Selecting the context needed for the next decision without carrying the full repository, logs, and history into every call.
Updated 11 Oct 2026

A model can only use information that enters the current call. Context engineering is the work of selecting what it needs for the next decision and keeping the rest outside until it becomes relevant again.

The application can retain the repository, complete history, logs, and other artifacts without sending all of them on every inference. When something becomes useful later, it retrieves the specific part the model needs.

Select context for the next call The complete repository, long history, large log, and artifacts remain available outside context. Selection retrieves only applicable instructions, the current error, the relevant file, and the information needed for the next decision. Available outside context Complete repositoryLong history10,000-line logArtifacts and results Select / retrieve Only what is needed now Context for the next call Applicable instructionsCurrent errorRelevant fileInformation needed to decide More can be retrieved later Select context for the next call The complete repository, long history, large log, and artifacts remain available outside context. Selection retrieves only applicable instructions, the current error, the relevant file, and the information needed for the next decision. Available outside context Complete repositoryLong history10,000-line logArtifacts and results Select / retrieve Only what is needed now Context for the next call Applicable instructionsCurrent errorRelevant fileInformation needed to decide More can be retrieved later
Figure 1. The complete material remains available outside the call; only the information needed for the next decision enters context.

Context for the next decision

An agent fixing a test may need the applicable instructions, the current failure, the file it is changing, and decisions that still apply. The rest of the repository and an hour of discarded shell history can remain available outside context.

The selection changes as the task moves. After the code is edited, the old failure may stop mattering and the latest test result becomes the main evidence.

Files such as AGENTS.md are part of the same problem. Their rules need to reach the model when they apply, but oversized instruction files consume context repeatedly and make the relevant parts harder to find.

Large tool results

A tool can produce far more content than the next step needs. If a command returns 10,000 lines, the full log can remain as an artifact while deterministic filtering extracts errors, matches, or one relevant region.

Keep exact material when detail can change the decision: a stack trace, command, identifier, or code fragment. The model can receive only the needed region and retrieve the original later if more context becomes necessary.

Long sessions and compaction

A long session accumulates messages, results, and previous decisions. As it approaches the context limit, the harness can compact part of that history into a smaller representation.

To continue, the model usually needs the goal, changes already made, constraints that still apply, and unresolved problems. A summary can preserve those while still losing one exact stack-trace line or the original output of a command.

Details that must remain recoverable should live in files, commits, test output, or other external artifacts. Compaction keeps the session usable; artifacts preserve exact evidence.

Handoffs

The same selection applies when another session or agent continues the work. A useful handoff includes the objective, current state, decisions that still apply, and references to important artifacts. It does not need to replay the full conversation for the work to continue.

References