【人工智能】什么是上下文工程Context Engineering | 上下文Context | Agent的缺点 | 提示词工程 | RAG | MCP | 写入 | 选取 | 压缩 | 隔离

【人工智能】什么是上下文工程Context Engineering | 上下文Context | Agent的缺点 | 提示词工程 | RAG | MCP | 写入 | 选取 | 压缩 | 隔离

Understanding Context Engineering in AI Agents

Introduction to Context Engineering

  • The speaker introduces the concept of AI agents, noting that while they appear advanced, they often fail during complex tasks.
  • The failure is attributed not to model limitations but rather to failures in "Context Engineering."
  • Context Engineering is defined as a crucial aspect of optimizing how information is provided to language models for task completion.

Defining Context

  • The speaker clarifies what "context" means, emphasizing it as a comprehensive set of information given to language models for reasoning or generating tasks.
  • Three core categories of context are introduced:
  • Guiding Context: Sets frameworks and rules for model behavior (includes system prompts and task descriptions).
  • Informational Context: Provides necessary knowledge and facts (includes RAG and memory types).
  • Actionable Context: Informs the model about possible actions and their outcomes (includes tool definitions).

Understanding Context Engineering

  • The speaker explains that context engineering involves designing a dynamic system that optimally assembles context for each task step.
  • Tobi Lütke describes it as an art form focused on providing all necessary context for effective problem-solving by language models.
  • Andrej Karpathy adds that it's both an art and science aimed at filling the context window with appropriate information.

Distinction from Other Concepts

  • The relationship between context engineering, prompt engineering, and RAG is clarified; they are complementary rather than mutually exclusive.
  • Prompt engineering focuses on optimizing single interactions, while RAG retrieves relevant external information.

Importance of Context Engineering

  • Without effective context engineering, agents may output subpar results due to missing critical contextual information.
  • An example illustrates how a lack of sufficient context can lead to ineffective responses from AI assistants when handling simple requests.

Challenges in Providing Context

  • Simply providing all possible contexts isn't feasible due to limitations in model capacity and potential performance degradation over time.
  • A second example highlights issues arising from excessive historical data being passed into the model during long-term tasks.

Solutions Offered by Context Engineering

  • Effective context engineering aims to manage and compress contextual data intelligently, ensuring only high-value information is included.

Best Practices in Context Engineering

Key Components of Effective Context Management

Writing (Write)

  • Writing involves persisting contextual data beyond immediate use through session-level or persistent writes.

Selecting (Select)

  • Selection dynamically pulls relevant information before each model call, ensuring high signal-to-noise ratios. It includes deterministic selection based on preset rules or retrieval-based methods.

Compressing (Compress)

  • Compression reduces the amount of data entering the context window while retaining essential signals. Techniques include auto-compression strategies used by systems like Claude Code.

Isolating (Isolate)

  • Isolation sets boundaries between different streams of information within multi-agent systems, allowing sub-processes to digest details before presenting key insights back to main agents.

Conclusion on Best Practices

Video description

⭐️【官方商店 | 购买同款T恤】:https://go.bstp.hk/t-shirts 不知道大家有没有这种感觉,现在很多AI Agent看起来技术很先进,但是实际用起来却经常掉链子。那这是不是因为模型不够强呢?其实根据业内的观察,多数AI Agent的失败,并不是模型能力的失败,而是上下文工程的失败。那么,这个所谓的上下文工程,英文为"Context Engineering"的概念,它和我们熟悉的提示词工程(Prompt Engineering)、检索增强生成(RAG),甚至模型上下文协议(MCP),到底是什么关系呢?今天我们就用一期视频来彻底搞懂这个话题。 参考资料: https://www.philschmid.de/context-engineering https://rlancemartin.github.io/2025/06/23/context_engineering/ https://www.dbreunig.com/2025/06/22/how-contexts-fail-and-how-to-fix-them.html https://www.llamaindex.ai/blog/context-engineering-what-it-is-and-techniques-to-consider https://blog.langchain.com/the-rise-of-context-engineering/ https://cognition.ai/blog/dont-build-multi-agents#applying-the-principles