Context writing preserves useful information outside an LLM agent’s active context window so the agent can recover it later. The prompt remains a compact working surface containing current state, references, and information needed for the next step; full-fidelity history stays in external storage. section 7.3
Writing is one part of context management. Selection decides what belongs in the active prompt; writing preserves useful material that does not need to remain there. An agent can recover stored information through a tool call, retrieval, or a direct file read. section 7.2.2 section 7.3
Figure 7.1 Context is managed through four complementary techniques: selection chooses relevant tokens for the active prompt, writing persists state to external storage, compression condenses verbose history, and isolation divides complex tasks across separate context windows
The four techniques address different context-management pressures: selection, external persistence, compression, and isolation. section 7.1
Storage choices depend on what the agent needs to preserve and how it will retrieve it:
- Vector databases support semantic similarity search across historical interactions and notes; graph databases preserve entity relationships and task dependencies. section 7.3.2
- Relational databases provide schema integrity, filtering, and auditability; object stores hold large binary payloads and raw documents. section 7.3.2
- Working scratchpads hold temporary artifacts such as partial calculations, checklists, and plans. An agent can re-read and update them as structured JSON or sectioned Markdown. section 7.3.2
Offloading an order history
A customer support assistant retrieves an extensive order history, stores the full record externally, and keeps only a reference pointer and the active order ID in the prompt. The full history remains available without being carried into every model call. section 7.3.2
Writing and compression relieve context pressure differently. Writing first moves material intact into storage; compression discards detail to reduce the active context. Compressing before writing can permanently destroy recoverable state. If the active working set is still too large after offloading, compression may still be necessary. section 7.3 section 7.3.2
