【人工智能】什么是上下文工程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