概念
Context engineering
Choosing what goes into the model's context so it can give better answers.
本课尚未翻译,暂以英文显示。
- 1Instructions are chosen.
- 2Retrieved data is added.
- 3Relevant history is kept.
- 4Tool results are added.
- 5The model answers using that context.
分步说明
- 1Instructions are chosen.
- 2Retrieved data is added.
- 3Relevant history is kept.
- 4Tool results are added.
- 5The model answers using that context.
Four sources fill the context that the model sees with each request.
Scope
- Prompt engineering
- One prompt
- Context engineering
- Everything the model sees
Focus
- Prompt engineering
- Wording and examples
- Context engineering
- What to include and when
Example
- Prompt engineering
- Add a few examples to the prompt
- Context engineering
- Fetch the right policy page and trim old turns
| Compare | Prompt engineering | Context engineering |
|---|---|---|
| Scope | One prompt | Everything the model sees |
| Focus | Wording and examples | What to include and when |
| Example | Add a few examples to the prompt | Fetch the right policy page and trim old turns |
是什么
A model only knows what it learned in training and what is in its context for this request. Context engineering is the work of deciding what goes into that context: instructions, data fetched from your own sources, the conversation so far and the tools the model may call. The goal is the right information, in the right amount, at the right time.
是什么
It grows out of prompt engineering. Prompt engineering is about how you word the request. Context engineering looks wider. It builds the whole package around the request. This matters most for agents and long conversations, where the context fills up and has to be managed: keep what helps, trim or summarize what does not.
Because the context window is limited and tokens cost money, more is not better. Irrelevant text can confuse the model and raises the bill. Good context is relevant, short and current.
要记住
- Context = instructions + retrieved data + conversation history + tool results.
- Context engineering decides what to include, what to leave out and when.
- It builds on prompt engineering and goes beyond the wording of one prompt.
- Retrieved data (RAG) is one source of context.
要记住
- Too much context costs more and can lower answer quality.
考试中
- “Decide what information, history and tools the model sees” points to context engineering.
- “Improve answers by giving the model your company data at request time” points to adding retrieved context.
- “Wording and examples inside a prompt” points to prompt engineering.
别和这些弄混
- Prompt engineeringSteer a foundation model with better instructions, without training it.
- Retrieval Augmented Generation (RAG)Look up facts first, add them to the prompt, then let the model answer from them.
- Tokens and the context windowThe small pieces of text a model reads and writes, and the limit on how many fit in one request.