ARCHITECTURE · CONTEXT ENGINEERING · 5 MIN READ

A context pipeline for a long-running agent

Select the right instructions, evidence, and state for each turn.

THE SYSTEM BLUEPRINTCOMPONENTS & DATA FLOW
progressrecalled factsobservationsassembled inputselection recordupdated stateTask stateCurrent goal and progressContext selectorRank + budget + compactModel callInstructions + evidenceMemory retrievalRelevant historical factsTool observationsFresh environment evidenceContext auditRecord selected inputs
A conceptual architecture. Each connection represents a responsibility to implement and validate.

Treat context as a compiled input

Gather the current task, relevant memories, recent tool results, and application instructions. Rank and filter each source, then build the input within a token budget. Preserve the distinction between trusted instructions and retrieved data.

Compact with a purpose

A summary should preserve decisions, unresolved questions, resource identifiers, and evidence needed to continue. Store references to large artifacts instead of repeatedly inserting their full contents. Test whether compaction removes information required later.

Measure useful context

Track retrieval relevance, repeated context, token use, and task success. A smaller prompt is only an improvement if the agent retains the information it needs to complete the task correctly.

Keep exploring

A layered architecture for agent memoryRetrieval that can ask a better questionThe real cost of an agent run