← Back to LLMs Mind Map
⚡ LLMsID: context-engineering

Context Engineering

上下文工程
🎯Core Definition
context engineering treats the finite context window as a scarce resource to manage systematically — three pillars: (1) system prompts — fixed role, behavior rules, and format constraints stable across turns, versioned over time (e.g. "say so when unsure", output JSON structure); (2) memory tiers — layered by stability and recency: system rules > current user intent > conversation history > retrieved evidence and tool results, with long histories compressed (summarization-style context compaction) or truncated by relevance; (3) token budgets — explicit allocation of the window WW: instruction, history, retrieval, and reserved output WoutW_{\text{out}} such that ∑iti+Wout≤W\sum_i t_i + W_{\text{out}} \le W, with cost approximated by cost=cin⋅tin+cout⋅tout\text{cost} = c_{\text{in}} \cdot t_{\text{in}} + c_{\text{out}} \cdot t_{\text{out}} — over budget means truncation or summarization.
💡Use Cases
prompt architecture for long conversations, RAG Q&A, and agent systems; multi-turn memory pruning and compression; cost optimization under per-token pricing; a favorite interview question — design context management for a 200K-window agent.
⚡Key Problems Solved
unmanaged stuffing buries key instructions (echoing Lost-in-the-Middle), lets history bloat eat the budget, and scales cost linearly with context. Context engineering upgrades "how to write prompts" into "how to allocate the window", making the accuracy/cost/latency trade-off explicit.
🎯Core Interview Exam Points
Fundamentals · Production Scenarios · Deep Dive
Core Def
Explain the core definition, underlying mechanism/math, and key principles of Context Engineering.
Use Cases
In production engineering, what are the primary use cases for Context Engineering and what core pain points does it solve?
🔥 High-Frequency Deep-Dive Questions
1
What are the principles of system-prompt design, and how do you layer it against user input and retrieval to avoid override?
2
Typical memory tiers and their lifetimes; when and how does context compaction trigger?
3
For a 200K window, how do you budget instruction/history/retrieval/output, and why must output be reserved?
4
Under per-token pricing, when do you resend long history vs use summary/prompt caching?
5
Context engineering vs Lost-in-the-Middle: where in the window should critical info go to maximize usage?
Updated 2026-08-12
🎯
Verify Mastery: Practice Exam Questions for "Context Engineering"
Take pitfall multiple-choice questions with derivation options; mistakes are automatically logged.
🚀 Start Card Practice ➔
← Previous CardLong-Context ExtensionNext Card →Classic NLP Tasks

🔗 More LLMs Knowledge Cards

引用出处: TalentMe 450+ 工业级 AI 架构考点知识库 (Tech Vault) · 遵循 CC-BY-4.0 知识共享协议
URL: https://talentme.airsota.com/resources/tech/roadmap/mindmap/LLM/card/context-engineering
中文速览与面试要点

上下文工程 (Context Engineering)

定义: 上下文工程是把有限的上下文窗口当作稀缺资源来系统管理,三大支柱:(1) 系统提示——固定角色、行为规则与格式约束,独立于每轮对话,并随版本迭代(如"不确定时直说"、输出 JSON 结构);(2) 记忆分层——按稳定性与时效性分层:系统提示/规则 > 用户当前意图 > 对话历史 > 检索证据与工具结果,历史太长时压缩(摘要式 context compaction)或按相关度截断;(3) token 预算——显式分配窗口:窗口上限 W 内划分指令、历史、检索、输出预留 W_ out,确保 _i t_i + W_ out W,成本近似 cost = c_ in t_ in + c_ out t_ out,超预算即截断或摘要。 使用场景: 长对话助手、RAG 问答、Agent 系统的 prompt 体系设计;多轮记忆裁剪与上下文压缩;成本优化(按 token 计费);面试高频"给一个 200K 窗口的 Agent 设计上下文管理策略"。 解决的问题: 无管理的堆砌会让关键指令被淹没(呼应 Lost-in-the-Middle)、历史膨胀吃掉预算、成本随上下文线性上升;上下文工程把"提示词怎么写"升级为"窗口怎么分",在准确率、成本、延迟之间做显式权衡。

核心要点

  • 系统提示设计有哪些原则?如何与用户输入、检索内容分层避免互相覆盖?
  • 记忆分层的常见层级与各层寿命是什么?上下文压缩 (compaction) 何时触发、怎么触发?
  • 给一个 200K 窗口设计 token 预算:指令/历史/检索/输出各分多少?为什么必须预留输出?
  • 上下文成本模型:输入/输出 token 计费下,长历史重发 vs 摘要缓存(如 prompt caching)怎么选?
  • 上下文工程与 Lost-in-the-Middle 的关系:关键信息放窗口哪个位置最能保证被利用?