Agentic AI · Systems Design

What goes in front
of the model, matters.

Context engineering involves determining the precise information available to an LLM or agent during reasoning, such as instructions, memory, retrieved facts, and tools, to ensure a fixed, finite window results in a dependable answer rather than a mere estimation.

SLIDE 01 : KNOWLEDGE & CONTEXT ENGINEERING Cover slide: Knowledge and Context Engineering
Quick answer

Context engineering Curating and assembling all the information a model sees at inference time, including system instructions, user requests, memory, knowledge retrieval, and tools, allows an agent to reason with precision and efficiency, ensuring only the necessary information is utilized. This process differs from prompt engineeringContext engineering oversees the entire information lifecycle for a multi-step, sometimes multi-session task by crafting a single instruction. The widely recognized operating framework, popularized by LangChain, divides the discipline into four key steps: Write (save context for later), Select (pull in only what's relevant now), Compress (fit more meaning into fewer tokens), and Isolate (keep unrelated context from contaminating a task).

SLIDE 02 : CONTEXT VS. PROMPT ENGINEERING Diagram comparing prompt engineering and context engineering
A shift in scope, not just vocabulary

Bigger than a well-written prompt

Prompt engineering It involves carefully wording a single directive - the phrasing, examples, and formatting - a skill applied to individual messages.

Context engineering The architectural approach to information management encompasses the entire lifecycle of information, including selection, retrieval, filtering, construction, compression, evaluation, and refresh, ensuring seamless functionality throughout an agent's entire task rather than just its initial message, preventing issues such as missing critical documents or being overwhelmed by unnecessary information.

SLIDE 03 : THE CONSTRAINTS THAT MAKE IT HARD Four constraints of context engineering: tokens, cost, relevance, state
Why this became its own discipline

Four pressures pushing back

  • Token limits : even the most generous context windows have limits, requiring difficult decisions on what to include.
  • Cost : each processed token incurs a cost; unchecked context expansion leads to increased budget expenses.
  • Relevance : Superfluous information not only takes up space, it also diverts attention and diminishes the quality of reasoning.
  • State persistence : agents must retain user preferences and previous interactions across multiple sessions, not just within a single session.
Anatomy of a context window

Everything competing for the same budget

Consider a context window as a checklist for a task: guidelines, the current issue, recent observations, reliable information, and available resources all come from the same limited pool of tokens.

SLIDE 04 : SIX TYPES OF CONTEXT Six types of context in an agent's context window
A sample token allocation

Where the budget typically goes

Instructions User request Retrieved knowledge Memory Tools & state
15%
10%
45%
20%
10%

A knowledge-intensive agent task often fills up almost half of the window with retrieved documents, highlighting the importance of careful selection and compression over sheer window size.

The operating framework

Write, Select, Compress, Isolate

Four strategies, made famous by LangChain's research on agent engineering, that encompass nearly all the necessary tasks for a context-engineered system to maintain reliability as tasks become more lengthy and intricate.

SLIDE 05 : THE FOUR-PILLAR FRAMEWORK Write, Select, Compress, Isolate context engineering framework
One system, four responsibilities

Four verbs, one context budget

Every pillar addresses a unique failure mode: losing information, being overwhelmed by it, running out of space, or allowing unrelated tasks to overlap.

✍️
Write

Store interim discoveries in a separate scratchpad to ensure they can be accessed later, preventing loss of important information when the window refreshes.

🎯
Select

Only bring in information that is pertinent to the current task. Not every piece of stored data needs to be included, so retrieval should be both thorough and selective.

🗜️
Compress

Condense or rearrange lengthy information to maximize efficiency without sacrificing necessary details for future use.

🧱
Isolate

Prevent any unrelated information, such as another task, user, or document set, from influencing the current thought process.

SLIDE 06 : THE KNOWLEDGE LAYER Vector databases and RAG as the knowledge layer for context engineering
Where 'select' actually happens

Retrieval turns a library into a lookup

Agents cannot just copy and paste an entire external knowledge base into their window. Vector databases address this issue by representing documents, conversation history, and structured records as embeddings, allowing the system to retrieve only the pertinent passages for the current task.

When combined with a retrieval-augmented generation (RAG) pipeline, this enables 'select' to expand the agent's knowledge base beyond the limitations of a context window by loading only the necessary information at a time.

SLIDE 07 : KNOWLEDGE GRAPHS & GRAPHRAG Knowledge graphs and GraphRAG for structured context retrieval
When flat retrieval isn't enough

Facts that know how they connect

Vector search can identify passages that share similarities, but it may not recognize the connections between a customer's ticket, their subscription tier, and the relevant policy document. In contrast, knowledge graphs explicitly model these relationships, allowing agents to navigate from a customer to their tickets to the applicable SLA in a structured manner, rather than relying on chance for all three to be surfaced through a similarity search.

GraphRAG Integrating graph-aware traversal with retrieval helps pinpoint relevant facts and extract supporting text, minimizing errors and providing a clear path for answering complex, multi-source questions, especially important in environments with access restrictions or compliance regulations.

SLIDE 08 : PATTERNS SEEN IN PRODUCTION Practical context engineering patterns: scratchpad, sub-agents, memory tiers
What this looks like day to day

Three patterns worth borrowing

  • The scratchpad : as it operates, an agent records its discoveries in an external storage system, creating a lasting, searchable database to avoid starting from scratch every time.
  • Sub-agent isolation A complicated task is divided among multiple smaller agents, each operating within their own specific and isolated context, with only the end outcome being shared upwards.
  • Tiered memory Short-term memory stores the present conversation, while long-term memory retains lasting information and preferences, recalled selectively instead of replayed in its entirety each time.
SLIDE 09 : OWNING THE CONTEXT WINDOW Summary: owning your context window as a core design principle
The principle that ties it together

Treat the window as owned, not infinite

The enduring concept present in all frameworks like LangChain's four pillars, RAG, knowledge graphs, and tiered memory, is also found in the 12-Factor Agents design principles: an agent architecture should be robust. own its context window Instead of viewing it as an endless notepad, the model will autonomously organize itself.

This implies that each design choice regarding instructions, memory, and retrieval is done purposefully, with a defined responsibility and allocated resources, rather than relying on happenstance.

Quick reference

The six types of context, side by side

Context typeWhat it holdsPrimary pillar it feeds
System instructionsRole, goals, constraints, safety rulesWrite
User promptThe specific request and its stated constraintsSelect
Short-term memoryRecent conversation turns, current task stateCompress
Long-term memoryDurable facts, preferences, past sessionsSelect
Retrieved knowledgeDocuments, records, and graph facts pulled via RAGSelect / Compress
Tools & stateAvailable actions and the live state of the environmentIsolate
Frequently asked

Context engineering FAQ

Prompt engineering focuses on crafting the wording of individual instructions, while context engineering oversees the entire information lifecycle that an agent utilizes for a multi-step task, including instructions, memory, retrieved knowledge, and tools. Even a perfectly worded prompt can be ineffective if the surrounding context is inaccurate.

The framework, popularized by LangChain's agent research, includes: Store (save context for future use), Retrieve (select only relevant information), Condense (pack more meaning into fewer words), and Shield (prevent unrelated context from interfering with the task at hand).

Knowledge engineering involves organizing and saving data for easy retrieval by constructing a vector database or knowledge graph. Context engineering is the next level, determining during inference which information from the stored knowledge is relevant to the model's current context window.

GraphRAG integrates the explicit relationships of a knowledge graph with text lookup from retrieval-augmented generation, providing added complexity suitable for multi-source or time-sensitive inquiries, data with restricted access, or instances requiring explainable reasoning trails over single similarity-matched passages.

Short-term memory maintains the flow of conversation, while long-term memory stores important information to prevent repetitive learning. Selective retrieval of long-term memory prevents it from overwhelming the current task.

In the 12-Factor Agents methodology, the engineering team deliberately controls the contents of the model's context, treating it as a managed, finite resource instead of leaving it to the framework to decide.

Get started

Ready to design your agent's context budget?

Begin by identifying the six necessary types of context for your agent, then use Write, Select, Compress, and Isolate techniques to maintain a focused and relevant window as tasks become more complex.