Knowledge tree
On this page

Context Engineering

How to decide what the model needs now and what should remain outside context for later retrieval.
Updated 28 Aug 2026

A model only sees the information placed in the current call. Context engineering is the practical work of deciding what it needs now and what can remain outside.

The application can retain the repository, full transcript, logs, and other state without sending all of it to the model. If something becomes relevant later, the application can retrieve the useful part and add it back.

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

Consider an agent fixing a test. To choose the next step it needs the applicable instructions, the current failure, the file it is changing, and decisions that still apply. It does not need every file in the repository or an hour of discarded shell history.

That selection changes as the task moves. After the code is edited, the old failure may no longer matter and the latest test result becomes the important evidence.

Files such as AGENTS.md are part of the same problem. Their rules need to reach the model when applicable, but oversized instructions consume context on every call and make the relevant parts harder to find.

Large tool results

A tool can return far more than the model needs. If a command produces 10,000 lines, the next inference rarely needs all 10,000.

The complete log can be stored in a file. Deterministic filtering can extract errors or matching lines, and the model can work from that smaller result. The original remains available if exact detail is needed later.

Not everything should be summarized. A stack trace, command, identifier, or code fragment may lose important detail when paraphrased. Keep the source and select the exact region instead.

Long sessions and compaction

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

A useful summary preserves the goal, changes already made, current constraints, and unresolved problems. It is still not the original history. It may record that a test failed without retaining every line of the stack trace.

Details that must remain exact should therefore live in files, commits, test output, or another external artifact. Compaction preserves continuity; artifacts preserve exact evidence.

Handoffs

The same rule applies when another session or agent continues the work. A good handoff states the goal, relevant changes, decisions that still apply, and where important files live. It does not need to replay the complete conversation.

Tokens & Context covers window capacity and compaction. The Agent Harness is the program that assembles this information for each model call.

References