上下文是 AI 代理的关键但有限的资源。在这篇文章中,我们探讨了有效策划和管理驱动它们的上下文的策略。经过几年提示工程在应用 AI 领域成为关注焦点后,一个新术语脱颖而出:上下文工程。使用语言模型构建越来越不关乎为提示找到正确的词语和短语,而更多是关于回答更广泛的问题:“什么样的上下文配置最有可能生成我们模型期望的行为?”上下文指的是从大型语言模型(LLM)采样时包含的令牌集。当前的工程问题是在 LLM 固有的约束下优化这些令牌的效用,以持续实现期望的结果。有效驾驭 LLM 通常需要“在上下文中思考”——换句话说:考虑 LLM 在任何给定时间可用的整体状态以及该状态可能产生的潜在行为。
Context is a critical but finite resource for AI agents. In this post, we explore strategies for effectively curating and managing the context that powers them. After a few years of prompt engineering being the focus of attention in applied AI, a new term has come to prominence: context engineering. Building with language models is becoming less about finding the right words and phrases for your prompts, and more about answering the broader question of “what configuration of context is most likely to generate our model’s desired behavior?" Context refers to the set of tokens included when sampling from a large-language model (LLM). The engineering problem at hand is optimizing the utility of those tokens against the inherent constraints of LLMs in order to consistently achieve a desired outcome. Effectively wrangling LLMs often requires _thinking in context_— in other words: considering the holistic state available to the LLM at any given time and what potential behaviors that state might yield.
核心贡献 · Key contributions
提出上下文工程是提示工程的自然演进,适用于 AI 智能体。 Introduces context engineering as a natural progression from prompt engineering for AI agents.
将上下文定义为有限资源,由于 Transformer 中的注意力稀缺性,其边际收益递减。 Defines context as a finite resource with diminishing returns due to attention scarcity in transformers.
提出使用工具的即时上下文检索,实现动态高效的上下文管理。 Proposes just-in-time context retrieval using tools for dynamic, efficient context management.
描述了压缩、结构化笔记和多智能体架构,用于长周期任务。 Describes compaction, structured note-taking, and multi-agent architectures for long-horizon tasks.
强调找到最小的高信号词元集,以最大化期望结果。 Emphasizes finding the smallest set of high-signal tokens to maximize desired outcomes.
为系统提示、工具、示例和记忆管理提供实用指南。 Provides practical guidelines for system prompts, tools, examples, and memory management.
局限 · Limitations
上下文工程依赖模型能力;较弱模型可能需要更规范的工程。 Context engineering relies on model capabilities; weaker models may require more prescriptive engineering.
即时检索相比预计算数据检索引入延迟。 Just-in-time retrieval introduces latency compared to pre-computed data retrieval.
过度压缩可能丢失微妙但关键的上下文。 Compaction may lose subtle but critical context if overly aggressive.
多智能体架构在协调和子智能体设计上增加复杂性。 Multi-agent architectures add complexity in coordination and sub-agent design.
技术主要在 Claude 模型上验证;对其他 LLM 的泛化性未证明。 Techniques are validated primarily on Claude models; generalizability to other LLMs is not proven.
论文章节 · Sections(共 7)
概述Overview
上下文工程 vs. 提示工程Context engineering vs. prompt engineering
为什么上下文工程对于构建有能力的智能体至关重要Why context engineering is important to building capable agents
有效上下文的构成The anatomy of effective context
上下文检索与智能体式搜索Context retrieval and agentic search
长时域任务的上下文工程Context engineering for long-horizon tasks