Start with the context engineering guide
Read the overview, then note which kinds of information your application supplies beyond its prompt.
Start with: Effective context engineering for AI agents
RedLectern topic
Design the information supplied to a model across a workflow.
For: Application builders
After this page you can: Design the information supplied to a model across a workflow.
Page reviewed
Part of: Artificial Intelligence › Prompting and context
Context engineering is the work of deciding what information a model receives as an application runs. It includes more than the prompt: instructions, tool descriptions, external documents, conversation history, and other state can all shape what is available on a turn. The job is to select and maintain useful context for the task, then revisit that selection as the workflow changes.
A practical guide starts with three questions: what must the model know now, what can it retrieve or inspect when needed, and what should be carried forward when the interaction continues? Treat the context window as a limited working space. Keep the instructions clear, make tools and reference material relevant to the task, and avoid carrying forward information that no longer helps. For longer workflows, plan how to summarize or preserve important state. Measure changes on representative tasks: a shorter input is not automatically a better one, and useful information can be lost when context is compressed.
Read the overview, then note which kinds of information your application supplies beyond its prompt.
Start with: Effective context engineering for AI agents
Use the official guide to understand reusable prompt prefixes and the limits of cache reuse.
Start with: Prompt caching
Context is the information available to the model for a turn, not just the text of a prompt. In an application workflow it can include system instructions, tool definitions, external data, and message history. As an interaction proceeds, new information may become relevant, so context selection is a recurring design decision.
A useful starting principle is to keep the supplied information relevant and informative while avoiding needless bulk. Think about what the model needs to act on now, what it can look up when needed, and what must persist across turns. Context engineering does not by itself ensure a correct answer: judge the selection by how well the resulting workflow handles representative tasks.
A practical reference for prompt inputs and reusable prompt prefixes.
Context engineering
Designing which instructions, information, and state a model receives across a workflow.
Context compaction
Reducing stored context by summarizing or otherwise compressing it so a workflow can continue.
Prompt caching
Reusing computation for a matching prompt prefix in later requests.
For a support assistant answering a question about a customer’s order, name three pieces of context it may need on this turn and one piece it should not receive unless the question calls for it.
Useful context could include the support instructions, the customer’s relevant order record, and the current question. An unrelated customer’s records should not be included.
Instructions should make the desired behavior clear without encoding brittle rules for every possible case. Reference documents can be supplied directly or made available for retrieval; the right choice depends on what the task needs at that moment. Tool descriptions and results also take up space in the model’s context, so expose tools that help with the task and consider what information their results return.
For a workflow that searches a large document collection, retrieval can bring selected passages into the prompt instead of placing the entire collection there. The retrieved material still needs to be relevant and sufficient for the question. Try a small set of representative questions, inspect what the system retrieves, and adjust instructions, document selection, or tool outputs based on observed failures.
Discusses tool choice and how tool outputs use an agent’s limited context.
A help assistant can search a handbook but currently receives the entire handbook on every turn. Suggest one context change and one check to see whether it helped.
Retrieve passages relevant to the current question and supply those passages with the question. Check several representative questions to see whether the needed passages are retrieved and whether answers use them appropriately.
In a multi-turn workflow, history and tool results accumulate, but not all earlier information remains useful. Decide what should stay in the active conversation, what can be summarized, and what should be stored for later retrieval. Summaries can preserve important decisions or unresolved questions, but compression can also omit details; compare the compressed version with the information the next step actually needs.
Prompt caching is a separate concern: it can reuse processing for a matching prompt prefix, while a changed prefix may not match the earlier cache. Keep stable instructions and reference material together where practical, and place changing user-specific material later. Evaluate context management on task quality as well as input size and cache behavior, since compaction and retrieval can change what information is available.
Covers compaction and structured note-taking as ways to carry information through longer workflows.
A research assistant has accumulated many tool results and must continue in a fresh context. Name two details its summary should retain and one kind of material it could omit.
It should retain the research question and key findings or unresolved issues needed for the next step. It could omit redundant raw tool output if the relevant result is captured accurately in the summary.
No recent updates are available.
Chip Huyen · 2024
Use its application-development framework to connect prompt engineering, RAG, and agents. It covers durable design choices; check current documentation for fast-changing APIs.