链载Ai

标题: Context Engineering上下文工程的5W1H [打印本页]

作者: 链载Ai    时间: 昨天 21:58
标题: Context Engineering上下文工程的5W1H

ingFang SC", system-ui, -apple-system, BlinkMacSystemFont, "Helvetica Neue", "Hiragino Sans GB", "Microsoft YaHei UI", "Microsoft YaHei", Arial, sans-serif;color: rgb(31, 35, 41);margin: 0px;word-break: break-all;min-height: 20px;">

ingFang SC", system-ui, -apple-system, BlinkMacSystemFont, "Helvetica Neue", "Hiragino Sans GB", "Microsoft YaHei UI", "Microsoft YaHei", Arial, sans-serif;color: rgb(31, 35, 41);margin: 0px 0px 4px;word-break: break-all;min-height: 20px;">🖌️ 本文目录:

ingFang SC", system-ui, -apple-system, BlinkMacSystemFont, "Helvetica Neue", "Hiragino Sans GB", "Microsoft YaHei UI", "Microsoft YaHei", Arial, sans-serif;letter-spacing: 0.578px;margin-top: 0px;margin-bottom: 0px;font-size: 22px;padding-bottom: 12px;">本文缘起

ingFang SC", system-ui, -apple-system, BlinkMacSystemFont, "Helvetica Neue", "Hiragino Sans GB", "Microsoft YaHei UI", "Microsoft YaHei", Arial, sans-serif;color: rgb(31, 35, 41);margin: 0px 0px 4px;word-break: break-all;min-height: 20px;">6.25 Karpathy转发Shopify CEO的一条推文表达对"Context engineering"重要性的强调,7.19 Manus Peak发布一篇构建Agent Context engineering的经验分享文章,CE开始替代PE,成为每个能够处理好复杂任务的Agent必备的技术。

ingFang SC", system-ui, -apple-system, BlinkMacSystemFont, "Helvetica Neue", "Hiragino Sans GB", "Microsoft YaHei UI", "Microsoft YaHei", Arial, sans-serif;color: rgb(31, 35, 41);margin: 0px 0px 4px;word-break: break-all;min-height: 20px;">无论Manus的工程经验是否能在每个Agent产品中复用,但Karpathy的观点足够引起我的重视,毕竟他是少见的在x上不吹逼说实话又有前瞻性的人。

ingFang SC", system-ui, -apple-system, BlinkMacSystemFont, "Helvetica Neue", "Hiragino Sans GB", "Microsoft YaHei UI", "Microsoft YaHei", Arial, sans-serif;letter-spacing: 0.578px;margin-top: 0px;margin-bottom: 8px;font-size: 22px;padding-bottom: 12px;">什么是CE

ingFang SC", system-ui, -apple-system, BlinkMacSystemFont, "Helvetica Neue", "Hiragino Sans GB", "Microsoft YaHei UI", "Microsoft YaHei", Arial, sans-serif;color: rgb(31, 35, 41);margin: 0px 0px 4px;word-break: break-all;min-height: 20px;">context中文称为“上下文”,不止用户发送给模型的内容,而是指模型生成输出前接收的所有内容。上图是目前公认的context范围,以下逐一表述:

ingFang SC", system-ui, -apple-system, BlinkMacSystemFont, "Helvetica Neue", "Hiragino Sans GB", "Microsoft YaHei UI", "Microsoft YaHei", Arial, sans-serif;letter-spacing: 0.578px;margin-top: 0px;margin-bottom: 8px;font-size: 22px;padding-bottom: 12px;">CE和PE的区别

CE代表了传统PE的范式转变。CE是一个系统,而不是一个静态的提示词模版,是在调用LLM之前的系统性的输出。

PE

CE

CE有什么作用

之前为提升 Agent 输出效果,主要focus在提升输出方式的路径上,例如ReAct框架,但CE强调除了关注如何响应,收集LLM完全实现其目标所需的信息也非常重要,然后才调用LLM。

如果Agent是一个厨师,炒菜过程的火候和调料顺序重要,但炒菜前的食谱、原料准备也很重要。

CE使得关注点不再focus在更智能的模型和更聪明的算法上,而是关注在为目标任务提供更准确的上下文上。

如何使用CE

构建CE包含哪些方面——完整的CE应该在建设时check:

以下用n8n构建的Agent为例,阐述CE的内容。

系统提示词,在System prompt里需要明确提供哪些上下文能有效地执行任务,把待解决的问题拆分成核心组件,这不仅是一个简单的提示和指令,输出system prompt的过程需要实验并为模型提供重要的上下文,以最佳方式执行任务。

-- Instructions用于准确提示System要做什么
-- 有助于模型理解用户输入是什么以及希望system输出什么内容
-- <user_query> What's the latest dev news from OpenAI? </user_query>
Youarean expert research planner. Your taskistobreak down a complex research query (delimitedby<user_query></user_query>)intospecificsearchsubtasks,eachfocusingona different aspectorsource type.
--调用工具
Thecurrentdateandtimeis: {{ $now.toISO() }}
--结构化输入
Foreachsubtask, provide:
1.Auniquestring IDforthe subtask (e.g.,'subtask_1','news_update')
2.Aspecificsearchquery that focusesononeaspectofthe main query
3.The source typetosearch(web, news, academic, specialized)
4.Timeperiodrelevance (today,lastweek, recent, past_year, all_time)
5.Domain focus if applicable (technology, science, health, etc.)
6.Priority level (1-highestto5-lowest)

Allfields (id, query, source_type, time_period, domain_focus, priority)arerequiredforeachsubtask,excepttime_periodanddomain_focus which can benullifnotapplicable.

Create2subtasks that together will provide comprehensive coverageofthe topic. Focusondifferent aspects, perspectives,orsourcesofinformation.
--结构化输出
Eachsubstask will include the following information:

id: str
query: str
source_type: str # e.g., "web", "news", "academic", "specialized"
time_period: Optional[str]=None # e.g., "today", "last week", "recent", "past_year", "all_time"
domain_focus: Optional[str]=None # e.g., "technology", "science", "health"
priority:int #1(highest)to5(lowest)

After obtaining the above subtasks information, you willaddtwo extra fields. Those correspondtostart_dateandend_date. Infer this information given thecurrentdateandthe time_period selected. start_dateandend_date should use the formatasinthe example below:

"start_date": "2024-06-03T06:00:00.000Z",
"end_date": "2024-06-11T05:59:59.999Z",

CE最佳实践

以互联网上现有的工程实践和学术研究为例,阐述CE的实现重难点以及通过什么技术手段解决Agent的什么问题。

重难点

Context engineering的核心在于巧妙地组织和呈现信息给AI Agent,以引导其行为和决策,区别于Prompt engineering,通过“对话”和“示例”来塑造AI的“思维过程”。虽然潜力巨大,但绝非易事。

关键技术

如何评估

对于用CE构建的一个更复杂的AI系统而言,其效果真的好吗?任务失败如何定位问题?

对于此类AI系统的评估,核心是测试模型在长序列中的信息保持、位置偏差和推理连贯性,可以使用现有的许多评测集来测试,也可以by modules测试单个模块的输入输出是否准确,或者构建一些评估专家的AI系统,用一个LLM去评价另一个LLM的输出,也能作为分数之外的另一个衡量标准。

最后想说

Context engineering的前提是大众已经认可了Agentic AI的长远价值,CE是对Multi-agent system应用现有问题打补丁的最佳工程实践。

如果把Agent应用比做一盘菜,那CE是让菜更加色香味俱全的调料,把现有的能吃但填不饱肚子也卖不起高价的菜做得更好吃更下饭更具备壁垒和商业价值。

但反过来想,Agentic AI并不是AGI最佳的呈现形式,完成复杂任务或许在目前的模型能力上始终无法尽善尽美,当有了更强的模型,CE价值会随着模型能力跃升而递减——当模型对上下文、工具、环境的理解趋近人类水平时,CE 会退到「安全护栏」与「个性微调」的位置,不再是“满汉全席全靠调料”。

AI更多的想象力或许不在处理复杂任务,而是更多的模态交互或更垂直的数据应用。更强的模型会让「任务完成」变得傻瓜化,Agent 的卖点不再是“能把事做完”,而是“让人愿意用它做更多事”。

因此 AGI 的额外价值空间会外溢到:

当模型逼近 AGI 时,“Agent=复杂任务执行器”的叙事会被淡化,AGI 的核心价值将转向「与人类共创意义」——让交互更自然,让决策更轻盈,让数据更增值;而 CE 则退居为「让 AI 更懂你我」的轻量旋钮,不再是撑起商业壁垒的那堵墙。






欢迎光临 链载Ai (https://www.lianzai.com/) Powered by Discuz! X3.5