简介
GPT-5 在执行智能体任务、编程、基础智能水平和可控性方面都有了显著提升。
我们相信,GPT-5 开箱即用就能在众多领域表现出色。本指南结合我们训练模型并将其用于实际任务的经验,介绍如何通过提示词尽可能提高输出质量。您将了解如何提升智能体任务的执行效果、让模型准确遵循指令、使用新的 API 功能,以及针对前端开发和软件工程任务优化编程表现。我们还会介绍 AI 代码编辑器 Cursor 的团队为 GPT-5 调优提示词时获得的重要经验。
我们在实践中采用这些方法,并尽可能使用我们的标准工具,已经取得了显著成效。希望本指南和我们开发的提示词优化工具能帮助您开始使用 GPT-5。不同问题适合不同的提示词写法,建议您以本指南为起点,通过实验和迭代找到最适合当前问题的方案。
新增功能与改进
- 智能体任务执行能力、编程能力和可控性进一步提升
- 在涉及工具调用的流程中,Responses API 可以保留推理上下文
- 可分别控制智能体的主动性、工具调用前的说明、推理强度和回答的详细程度
- 自定义工具支持自由格式的输入,并可约束输出格式
迁移快速入门
- 将模型 Slug 更新为
gpt-5。 - 对于推理、工具调用和多轮工作流,请使用 Responses API,以便在工具调用之间保留推理项。
- 先将推理强度设为
medium,再用有代表性的任务测试minimal、low或high。 - 根据需要明确设置
text.verbosity。如果对响应结构有明确要求,请尽可能使用结构化输出实现这些要求。 - 重新检查提示词中有关智能体持续执行任务、工具调用前的说明和停止条件的指令。
模型、API 和功能更新
- GPT-5 系列包括
gpt-5、gpt-5-mini和gpt-5-nano。 reasoning.effort支持minimal、low、medium和high。- GPT-5 引入了自定义工具。这些工具接受自由格式的输入,并可使用上下文无关文法约束输出。
- 模型支持函数调用和 OpenAI 托管的工具,包括网页搜索、文件搜索、图像生成、代码解释器和远程 MCP。
提示词编写最佳实践
提高智能体工作流的可预测性
在训练 GPT-5 时,我们从开发者的需求出发,重点改进了工具调用、指令遵循和长上下文理解能力,力求为智能体应用提供最佳基础模型。如果您要将 GPT-5 用于智能体和工具调用流程,建议升级到 Responses API。它能在工具调用之间保留推理上下文,让模型更高效地给出更好的结果。
控制智能体的主动性
不同智能体框架对模型的控制程度差异很大。有些系统将绝大多数决策交给底层模型,有些则在程序中设置大量逻辑分支,严格限定模型的行动。GPT-5 经过训练,可以适应各种控制程度,既能在情况不明时做出高层决策,也能处理范围集中、定义清晰的任务。本节介绍如何调整 GPT-5 的主动性,让它在主动行动和等待明确指引之间取得合适的平衡。
通过提示词降低主动性
默认情况下,GPT-5 会在智能体环境中尽可能全面、细致地收集上下文,以确保回答正确。如果您希望缩小它自主行动的范围,例如减少偏离任务的工具调用、缩短给出最终答案的时间,可以尝试以下做法:
- 调低
reasoning_effort。这会降低探索深度,但能提高效率、缩短延迟。在许多工作流中,将reasoning_effort设为中等甚至较低水平,仍然能得到稳定的结果。 - 在提示词中明确模型应如何探索问题、何时可以停止。这样可以减少模型需要探索和推敲的思路:
<context_gathering>
目标:快速收集足以行动的上下文。并行查找信息,一旦可以行动,就停止搜索。
方法:
- 先广泛搜索,再针对具体问题分别查询。
- 并行执行不同的查询,阅读每项查询中排名靠前的结果。对路径去重,缓存结果,避免重复查询。
- 避免为了收集上下文而过度搜索。必要时,将有针对性的搜索合并为一批,并行执行。
提前停止的条件:
- 能够准确指出需要修改的内容。
- 排名靠前的结果中,约 70% 指向同一区域或路径。
最多追加一轮搜索:
- 如果线索相互矛盾或范围不明确,就细化查询,并行搜索一轮,然后继续执行任务。
深度:
- 只追踪要修改的符号,以及当前工作所依赖的接口约定涉及的符号。除非确有必要,否则不要沿依赖关系逐层展开。
执行流程:
- 批量搜索 → 制定简要计划 → 完成任务。
- 仅在验证失败或出现新的未知问题时再次搜索。已有足够信息时,优先行动。
</context_gathering>
如果您希望更严格地规定模型的行为,还可以像下面这样为工具调用设置固定次数上限。具体上限可以根据您期望的搜索深度调整。
<context_gathering>
- 搜索深度:很低。
- 优先考虑尽快给出正确答案,即使答案可能并不完全正确。
- 通常情况下,工具调用总数严格限制在 2 次以内。
- 如果认为需要更多时间调查,请向用户说明最新发现和尚待解决的问题。用户确认后,可以继续调查。
</context_gathering>
限制上下文收集时,最好明确告诉模型在什么情况下可以结束收集,避免它为了满足其他要求而继续搜索。通常可以加入一句话,允许模型在仍有不确定性时继续执行,例如上例中的 “即使答案可能并不完全正确”。
通过提示词提高主动性
如果您希望模型更自主地工作,在需要时持续调用工具,并减少提问澄清或将任务交回用户的次数,建议调高 reasoning_effort,并使用类似下面的提示词,鼓励模型坚持执行,直到完整解决问题:
<persistence>
- 你是一个智能体。请持续执行任务,直到完全解决用户的问题,再结束本轮并将控制权交回用户。
- 只有在确定问题已经解决后,才能结束本轮。
- 遇到不确定的情况时,不要停下来或把任务交回用户。通过调查或推断找出最合理的做法,然后继续。
- 不要要求用户确认或澄清假设,之后仍可调整。选择最合理的假设,据此行动,并在完成后写明该假设,供用户参考。
</persistence>
通常,最好明确智能体任务的停止条件,说明哪些操作安全、哪些不安全,以及模型是否可以将任务交回用户、在什么情况下可以这样做。例如,在一组购物工具中,应明确规定:对于结账和付款工具,只要有少许不确定性,就应向用户确认;对于搜索工具,只有在极不确定时才需要询问。同样,在编程环境中,使用文件删除工具前需要询问用户的门槛应远低于使用 grep 搜索工具时的门槛。
工具调用前的说明
用户跟进智能体执行任务时,如果模型能不时说明它正在调用工具做什么、为什么这样做,交互体验会好得多。任务执行时间越长,这些说明的作用就越明显。为此,我们在训练 GPT-5 时,让它学会通过工具调用前的说明,在开始时给出清晰的计划,并在执行过程中持续更新进度。
您可以在提示词中指定这些说明的频率、风格和内容,例如要求模型详细解释每一次工具调用,或只在开始时简要说明计划,也可以选择介于两者之间的详细程度。下面是一段效果较好的提示词:
<tool_preambles>
- 在调用任何工具之前,始终先用友好、清晰、简洁的语言复述用户的目标。
- 接着立即列出条理清晰的计划,说明将依次执行哪些步骤。 - 编辑文件时,按顺序简要说明每一步,并明确标出当前进度。
- 最后总结实际完成的工作,与开始时列出的计划区分开来。
</tool_preambles>
下面的示例展示了模型在这类提示词引导下可能给出的工具调用说明。随着任务变得复杂,这些说明能让用户更容易跟上智能体的工作进展:
"output": [
{
"id": "rs_6888f6d0606c819aa8205ecee386963f0e683233d39188e7",
"type": "reasoning",
"summary": [
{
"type": "summary_text",
"text": "**Determining weather response**\n\nI need to answer the user's question about the weather in San Francisco. ...."
},
},
{
"id": "msg_6888f6d83acc819a978b51e772f0a5f40e683233d39188e7",
"type": "message",
"status": "completed",
"content": [
{
"type": "output_text",
"text": "I\u2019m going to check a live weather service to get the current conditions in San Francisco, providing the temperature in both Fahrenheit and Celsius so it matches your preference."
}
],
"role": "assistant"
},
{
"id": "fc_6888f6d86e28819aaaa1ba69cca766b70e683233d39188e7",
"type": "function_call",
"status": "completed",
"arguments": "{\"location\":\"San Francisco, CA\",\"unit\":\"f\"}",
"call_id": "call_XOnF4B9DvB8EJVB3JvWnGg83",
"name": "get_weather"
},
],
推理强度
您可以通过 reasoning_effort 参数控制模型投入多少精力进行推理,以及它调用工具的积极程度。默认值为 medium,您应根据任务难度调高或调低。对于复杂的多步骤任务,我们建议提高推理强度,以获得尽可能好的输出。我们还发现,对于彼此独立、可以拆分的任务,让智能体分多轮执行、每轮专注于一项任务,效果最好。
使用 Responses API 复用推理上下文
使用 GPT-5 时,我们强烈建议采用 Responses API,以改善应用中的智能体工作流、降低成本,并更高效地使用 Token。
评测显示,相比 Chat Completions,使用 Responses API 带来的提升具有统计显著性。例如,仅仅切换到 Responses API,并通过 previous_response_id 在后续请求中传回之前的推理项,Tau-Bench Retail 得分就从 73.9% 提升到了 78.2%。这样,模型可以参考之前的推理过程,节省思维链 Token,也无需在每次工具调用后从头制定计划,从而缩短延迟并提升表现。所有 Responses API 用户都可以使用此功能,包括采用零数据保留(ZDR)的组织。
从规划到执行,充分发挥编程能力
GPT-5 的编程能力在所有前沿模型中领先。它可以在大型代码库中修复缺陷、处理大规模代码差异、执行跨文件重构或实现大型新功能。它也擅长从零开始开发应用,涵盖前端和后端实现。本节介绍一些提示词优化方法,我们的编程智能体客户已在生产场景中通过这些方法提升了模型的编程表现。
前端应用开发
经过训练,GPT-5 既具备严谨的实现能力,也能在没有额外指导时做出良好的视觉设计选择。我们相信它能使用各种 Web 开发框架和软件包。对于新应用,建议采用以下框架和软件包,以充分发挥模型的前端开发能力:
- 框架:Next.js(TypeScript)、React、HTML
- 样式和界面:Tailwind CSS、shadcn/ui、Radix Themes
- 图标:Material Symbols、Heroicons、Lucide
- 动画:Motion
- 字体:San Serif、Inter、Geist、Mona Sans、IBM Plex Sans、Manrope
从零开始生成应用
GPT-5 擅长一次构建出完整的应用。在早期实验中,用户发现,像下面这样要求模型自行制定高质量应用的评判标准,并对照标准迭代,可以发挥 GPT-5 周密规划和自我反思的能力,提高输出质量。
<self_reflection>
- 首先,花些时间构思评分标准,直到你对它有把握。
- 接着,深入思考一次生成的 Web 应用需要在哪些方面表现出色,才能达到一流水平。据此制定一套包含 5 至 7 个评分维度的标准。这套标准至关重要,务必认真制定。它仅供你自己使用,不要展示给用户。
- 最后,对照评分标准自行推敲并反复改进方案,力求为给定的提示词找到最佳解。如果回答在任何一个维度未达到最高分,就需要重新开始。
</self_reflection>
遵循代码库的设计规范
在现有应用中做增量修改或重构时,模型编写的代码应遵循已有的风格和设计规范,尽可能自然地融入代码库。即使没有专门的提示词,GPT-5 也会主动在代码库中查找参考信息,例如读取 package.json 来查看已安装的软件包。如果您在提示词中概括工程原则、目录结构,以及代码库中明文规定或约定俗成的最佳实践,还能进一步改善效果。下面展示了一种组织 GPT-5 代码编辑规则的方式,您可以根据自己的编程和设计偏好调整规则内容。
<code_editing_rules>
<guiding_principles>
- 清晰与复用:每个组件和页面都应模块化,并可复用。将反复出现的界面模式提取为组件,避免重复实现。
- 一致性:界面必须遵循统一的设计系统,对颜色变量、排版、间距和组件使用统一规范。
- 简洁:优先使用小而职责明确的组件,避免在样式或逻辑中引入不必要的复杂性。
- 便于演示:应用结构应支持快速构建原型,方便展示流式输出、多轮对话和工具集成等功能。
- 视觉质量:间距、内边距、悬停状态等细节应达到 OSS 指南规定的高标准。
</guiding_principles>
<frontend_stack_defaults>
- 框架:Next.js (TypeScript)
- 样式:TailwindCSS
- 界面组件:shadcn/ui
- 图标:Lucide
- 状态管理:Zustand
- 目录结构:
\`\`\`
/src
/app
/api/<route>/route.ts # API 端点
/(pages) # 页面路由
/components/ # 基础界面组件
/hooks/ # 可复用的 React Hook
/lib/ # 工具函数(数据获取函数、辅助函数)
/stores/ # Zustand 状态存储
/types/ # 共享的 TypeScript 类型
/styles/ # Tailwind 配置
\`\`\`
</frontend_stack_defaults>
<ui_ux_best_practices>
- 视觉层次:字号和字重的组合限制在 4 至 5 种,以保持层次一致。图注和标注使用 `text-xs`。只有首屏主视觉或主要标题才使用 `text-xl`。
- 配色:使用 1 种中性色作为基础色(例如 `zinc`),强调色最多使用 2 种。
- 间距与布局:内边距和外边距始终取 4 的倍数,以保持视觉节奏。展示较长的内容流时,使用高度固定、内部可滚动的容器。
- 状态反馈:使用骨架屏占位或 `animate-pulse` 表示正在获取数据。通过悬停过渡效果(`hover:bg-*`、`hover:shadow-md`)提示元素可点击。
- 无障碍:在适当位置使用语义化 HTML 和 ARIA 角色。优先使用内置无障碍支持的 Radix/shadcn 预制组件。
</ui_ux_best_practices>
<code_editing_rules>
生产环境中的协作编程:Cursor 如何调优 GPT-5 提示词
AI 代码编辑器 Cursor 是我们信赖的 GPT-5 早期内测伙伴。下面介绍 Cursor 团队如何调整提示词,以充分发挥模型的能力。该团队还发布了博文,详细介绍了 Cursor 在 GPT-5 发布当天就完成集成的过程:https://cursor.com/blog/gpt-5
系统提示词与参数调优
Cursor 的系统提示词注重工具调用的可靠性,兼顾输出的详细程度和模型的自主性,同时允许用户配置自定义指令。团队希望 Agent 在执行耗时较长的任务时能够相对独立地工作,同时严格遵循用户提供的指令。
团队最初发现,模型的文字输出过于冗长,经常附带状态更新和任务总结。虽然内容与任务相关,却容易打断用户的工作节奏。与此同时,模型在工具调用中输出的代码质量很高,但有时写得过于简略,变量名大多只有一个字母,阅读起来反而费力。为取得更好的平衡,团队将 API 的 verbosity 参数设为低,让文字输出保持简短,再修改提示词,明确要求模型仅在使用编程工具时写得更详细。
编写代码时,把清晰易读放在首位。优先选择便于阅读和维护的方案,使用表意清楚的名称、必要的注释和直观的控制流。除非用户明确要求,否则不要为了缩短代码而牺牲可读性,也不要把复杂逻辑塞进一行。编写代码和使用编程工具时,应写得详细一些。
结合参数和提示词后,模型既能简洁地报告进度、总结工作,又能给出更易读的代码差异。
Cursor 团队还发现,模型偶尔会在行动前先请用户澄清问题或指明下一步,这会在较长的任务中造成不必要的中断。他们发现,除了说明可用工具和相关上下文,补充产品如何运作的细节,也能让模型更自主地完成较长的任务,减少中断。例如,说明用户可以撤销或拒绝代码更改,以及用户偏好如何起作用,有助于 GPT-5 明确自己在 Cursor 环境中应如何行动,减少歧义。对于执行时间较长的任务,团队发现以下提示词能够改善表现:
你对代码所做的修改会以拟议更改的形式展示给用户。这意味着:(a)你可以主动修改代码,因为用户随时都能拒绝更改;(b)代码应写得清楚,便于用户快速审查,例如使用恰当的变量名,避免仅用单个字母命名。如果建议的下一步涉及修改代码,就主动完成修改,让用户决定接受还是拒绝,无需先询问是否执行计划。一般情况下,几乎都不需要先问用户是否执行计划。应主动尝试实施计划,然后再询问用户是否接受实际完成的更改。
Cursor 发现,某些对早期模型有效的提示词片段需要调整,才能充分发挥 GPT-5 的能力。例如:
<maximize_context_understanding>
收集信息时务必做到全面细致。回复前一定要掌握全貌。必要时,继续调用工具或提问澄清。
...
</maximize_context_understanding>
早期模型需要提醒才会全面分析上下文,因此这段提示词效果很好。但 GPT-5 本身就善于反思,也会主动收集上下文,团队发现这段提示词反而适得其反。对于较小的任务,即使模型已有的知识足以解决问题,这段提示词也常常让它反复搜索,过度使用工具。
为解决这个问题,团队去掉了 maximize_ 前缀,并缓和了要求模型全面收集信息的措辞。调整后,团队发现 GPT-5 能更准确地判断何时可以依靠已有知识、何时需要使用外部工具。它仍能高度自主地工作,同时避免不必要的工具调用,行动也更高效、更切合任务。在 Cursor 的测试中,使用 <[instruction]\_spec> 这样的结构化 XML 规范,可以让模型更准确地遵循提示词中的指令,也方便团队在提示词的其他位置明确引用前面定义的类别和章节。
<context_understanding>
...
如果已经做了修改,但不确定这些修改是否只满足了用户的部分要求,请在结束本轮前收集更多信息或继续调用工具。
如果能自行找到答案,就尽量不要向用户求助。
</context_understanding>
系统提示词为模型提供了良好的默认行为,用户提示词则是进一步引导模型的有效手段。GPT-5 能很好地遵循直接、明确的指令。Cursor 团队多次观察到,结构清晰、范围明确的提示词能够产生最可靠的结果,无论是控制输出的详细程度、指定个人偏好的代码风格,还是提醒模型关注边界情况。GPT-5 的可控性提高后,Cursor 发现,让用户配置自己的 Cursor 自定义规则尤其有效,用户获得的体验也更符合个人需求。
提升智能表现和指令遵循能力
引导模型行为
GPT-5 是我们迄今为止可控性最高的模型。无论是调整回答的详细程度和语气,还是规定工具调用方式,它都能很好地遵循提示词中的指令。
回答的详细程度
与之前的推理模型一样,您可以控制 reasoning_effort。GPT-5 还新增了 API 参数 verbosity,用于控制最终答案的长度,与模型推理过程的长短无关。我们的博文更详细地介绍了这一参数的设计思路。在实际使用中,API 的 verbosity 参数为整个执行过程设定默认值,但 GPT-5 经过训练,可以在特定情境下遵循提示词中的自然语言指令,调整输出的详细程度。上文 Cursor 的做法就是一个典型例子:将全局详细程度设为低,然后在提示词中要求模型仅在使用编程工具时提供详细输出。
遵循指令
与 GPT-4.1 一样,GPT-5 能精确遵循提示词中的指令,因此可以灵活地用于各类工作流。正因为它会认真遵循每条指令,如果提示词写得含糊或包含相互矛盾的要求,对 GPT-5 的影响可能比对其他模型更大。它会消耗推理 Token 来寻找调和矛盾的方法,而非随机选取一条指令执行。
下面是一个对抗性示例,展示了哪类提示词容易干扰 GPT-5 的推理。乍看之下,各项要求似乎一致,但仔细检查就会发现,有关预约安排的指令互相冲突:
如果病历中没有记录患者的明确同意,绝不能安排预约,与后面的为降低风险,第一步就要在不联系患者的情况下自动分配当天最早的时段。相冲突。- 提示词先要求
在采取任何其他行动前,务必先查询患者档案,确认对方是已有患者。,随后又要求如果症状表明情况高度紧急,应将其升级为 EMERGENCY,并在执行任何预约步骤前指引患者立即拨打 911。,两条指令相互矛盾。
你是 CareFlow Assistant,一家医疗初创公司的虚拟行政助理,负责根据优先级和症状为患者安排预约。你的目标是对请求进行分诊,为患者匹配合适的保险网络内医疗服务提供者,并预订临床上适宜的最早时段。在采取任何其他行动前,务必先查询患者档案,确认对方是已有患者。
- 核心实体包括 Patient、Provider、Appointment 和 PriorityLevel(Red、Orange、Yellow、Green)。根据症状确定优先级:Red 在 2 小时内,Orange 在 24 小时内,Yellow 在 3 天内,Green 在 7 天内。如果症状表明情况高度紧急,应将其升级为 EMERGENCY,并在执行任何预约步骤前指引患者立即拨打 911。
+核心实体包括 Patient、Provider、Appointment 和 PriorityLevel(Red、Orange、Yellow、Green)。根据症状确定优先级:Red 在 2 小时内,Orange 在 24 小时内,Yellow 在 3 天内,Green 在 7 天内。如果症状表明情况高度紧急,应将其升级为 EMERGENCY,并在执行任何预约步骤前指引患者立即拨打 911。
*遇到紧急情况时,跳过查询,立即指引患者拨打 911。*
- 使用以下功能:schedule-appointment、modify-appointment、waitlist-add、find-provider、lookup-patient 和 notify-patient。预约前,核实患者的保险资格、首选诊所,以及病历中记录的同意情况。如果病历中没有记录患者的明确同意,绝不能安排预约。
- 对于病情危急的 Red 和 Orange 病例,*为降低风险,第一步*就要在*不联系患者*的情况下自动分配当天最早的时段。如果没有合适的医疗服务提供者,将患者加入候补名单并发送通知。如果不清楚患者是否同意,请暂时保留一个时段,然后请求确认。
- 对于病情危急的 Red 和 Orange 病例,*先告知*患者*你将采取的行动*,再自动分配当天最早的时段。如果没有合适的医疗服务提供者,将患者加入候补名单并发送通知。如果不清楚患者是否同意,请暂时保留一个时段,然后请求确认。
理清指令的优先顺序、消除冲突后,GPT-5 的推理效率和效果都会显著提高。我们做了两处修改:
- 将自动分配时段的操作移到联系患者之后,要求先告知患者将采取的行动,再自动分配当天最早的时段,使之与“取得同意后才能预约”的要求保持一致。
- 补充说明,遇到紧急情况时跳过查询,立即指引患者拨打 911,让模型明确此时可以不查询患者档案。
编写提示词是一个迭代过程,许多提示词也会由不同参与者持续更新。正因如此,更应仔细检查其中是否有表述不清的指令。已有多位早期用户在检查核心提示词库时发现了歧义和矛盾。消除这些问题后,GPT-5 的执行过程顺畅了许多,表现也显著改善。建议您使用我们的提示词优化工具测试提示词,以便发现此类问题。
最低推理强度
GPT-5 首次提供了最低推理强度选项。这是速度最快的选项,同时仍具备推理模型的优势。对于对延迟敏感的用户和目前使用 GPT-4.1 的用户,我们认为这是最合适的升级选择。
要获得最佳效果,我们建议采用与 GPT-4.1 提示词指南类似的写法。在最低推理强度下,提示词的不同写法比在较高推理强度下更容易造成明显的效果差异,因此尤其要注意以下几点:
- 对于需要较强智能的任务,可以要求模型在最终答案开头简要概述解题思路,例如列出几个要点。这有助于提升表现。
- 要求模型在工具调用前提供具体、充分的说明,持续向用户更新任务进度,可以改善智能体工作流的执行效果。
- 尽可能消除工具使用指令中的歧义,并像上文示例那样提醒智能体持续执行任务。在最低推理强度下,这对于充分发挥智能体执行长时间任务的能力、防止任务过早结束尤其重要。
- 由于模型可用于内部规划的推理 Token 较少,在提示词中明确要求规划也更加重要。下面是我们放在一项智能体任务开头的规划提示词片段,其中第二段特别强调,智能体必须完成整个任务及其所有子任务,才能将控制权交回用户。
记住,你是一个智能体。请持续执行任务,直到完全解决用户的问题,再结束本轮并将控制权交回用户。将用户的请求拆解为所有必需的子任务,逐项确认已经完成。不要在只完成部分请求时停下。只有在确定问题已解决后,才能结束本轮。要做好处理多个请求的准备,只有用户确认已无其他请求后,才能结束本次会话。
在继续调用函数之前,必须按照工作流步骤充分规划。每次函数调用后,都要仔细审视调用结果,确保用户的问题及相关子任务得到完整解决。
Markdown 格式
通过 API 使用 GPT-5 时,模型默认不会将最终答案排成 Markdown 格式,以便尽可能兼容开发者的应用,包括不支持 Markdown 渲染的应用。如果您希望最终答案采用层次清晰的 Markdown 格式,类似下面的提示词通常都能奏效。
- **仅在符合语义时**使用 Markdown(例如 `inline code`、```code fences```、列表和表格)。
- 在助手消息中使用 Markdown 时,用反引号标记文件名、目录名、函数名和类名。行内数学公式使用 \( 和 \),独立成行的数学公式使用 \[ 和 \]。
在较长的对话中,模型有时会逐渐偏离系统提示词中规定的 Markdown 格式。如果您遇到这种情况,我们发现,每隔 3 至 5 条用户消息补充一次 Markdown 格式指令,可以让模型持续遵循要求。
用提示词优化提示词
最后,早期测试者发现,让 GPT-5 帮忙改写给它自己的提示词效果很好。已有多位用户将这样生成的提示词修订版部署到了生产环境。他们只需把效果不理想的提示词交给 GPT-5,询问可以添加哪些内容来引导期望的行为,或删除哪些内容来避免不希望出现的行为。
下面是一个我们认为不错的元提示词模板:
当被问及如何优化提示词时,请从你自己的角度回答。具体说明可以在提示词中加入或删除哪些措辞,从而更稳定地引导期望的行为,或避免不希望出现的行为。
这是提示词:[PROMPT]
我希望这段提示词能让智能体 [DO DESIRED BEHAVIOR],但它实际却 [DOES UNDESIRED BEHAVIOR]。在尽可能保留现有提示词的前提下,你会做哪些最小幅度的修改或补充,让智能体更稳定地克服这些问题?
附录
SWE-Bench Verified 开发者指令
In this environment, you can run `bash -lc <apply_patch_command>` to execute a diff/patch against a file, where <apply_patch_command> is a specially formatted apply patch command representing the diff you wish to execute. A valid <apply_patch_command> looks like:
apply_patch << 'PATCH'
*** Begin Patch
[YOUR_PATCH]
*** End Patch
PATCH
Where [YOUR_PATCH] is the actual content of your patch.
Always verify your changes extremely thoroughly. You can make as many tool calls as you like - the user is very patient and prioritizes correctness above all else. Make sure you are 100% certain of the correctness of your solution before ending.
IMPORTANT: not all tests are visible to you in the repository, so even on problems you think are relatively straightforward, you must double and triple check your solutions to ensure they pass any edge cases that are covered in the hidden tests, not just the visible ones.
智能体编程工具定义
## Set 1: 4 functions, no terminal
type apply_patch = (_: {
patch: string, // default: null
}) => any;
type read_file = (_: {
path: string, // default: null
line_start?: number, // default: 1
line_end?: number, // default: 20
}) => any;
type list_files = (_: {
path?: string, // default: ""
depth?: number, // default: 1
}) => any;
type find_matches = (_: {
query: string, // default: null
path?: string, // default: ""
max_results?: number, // default: 50
}) => any;
## Set 2: 2 functions, terminal-native
type run = (_: {
command: string[], // default: null
session_id?: string | null, // default: null
working_dir?: string | null, // default: null
ms_timeout?: number | null, // default: null
environment?: object | null, // default: null
run_as_user?: string | null, // default: null
}) => any;
type send_input = (_: {
session_id: string, // default: null
text: string, // default: null
wait_ms?: number, // default: 100
}) => any;
如 GPT-4.1 提示词指南所述,这个 apply_patch 实现的设计与模型的训练数据分布相匹配。我们强烈建议使用 apply_patch 编辑文件。
Taubench-Retail 最低推理强度指令
As a retail agent, you can help users cancel or modify pending orders, return or exchange delivered orders, modify their default user address, or provide information about their own profile, orders, and related products.
Remember, you are an agent - please keep going until the user’s query is completely resolved, before ending your turn and yielding back to the user. Only terminate your turn when you are sure that the problem is solved.
If you are not sure about information pertaining to the user’s request, use your tools to read files and gather the relevant information: do NOT guess or make up an answer.
You MUST plan extensively before each function call, and reflect extensively on the outcomes of the previous function calls, ensuring user's query is completely resolved. DO NOT do this entire process by making function calls only, as this can impair your ability to solve the problem and think insightfully. In addition, ensure function calls have the correct arguments.
# Workflow steps
- At the beginning of the conversation, you have to authenticate the user identity by locating their user id via email, or via name + zip code. This has to be done even when the user already provides the user id.
- Once the user has been authenticated, you can provide the user with information about order, product, profile information, e.g. help the user look up order id.
- You can only help one user per conversation (but you can handle multiple requests from the same user), and must deny any requests for tasks related to any other user.
- Before taking consequential actions that update the database (cancel, modify, return, exchange), you have to list the action detail and obtain explicit user confirmation (yes) to proceed.
- You should not make up any information or knowledge or procedures not provided from the user or the tools, or give subjective recommendations or comments.
- You should at most make one tool call at a time, and if you take a tool call, you should not respond to the user at the same time. If you respond to the user, you should not make a tool call.
- You should transfer the user to a human agent if and only if the request cannot be handled within the scope of your actions.
## Domain basics
- All times in the database are EST and 24 hour based. For example "02:30:00" means 2:30 AM EST.
- Each user has a profile of its email, default address, user id, and payment methods. Each payment method is either a gift card, a paypal account, or a credit card.
- Our retail store has 50 types of products. For each type of product, there are variant items of different options. For example, for a 't shirt' product, there could be an item with option 'color blue size M', and another item with option 'color red size L'.
- Each product has an unique product id, and each item has an unique item id. They have no relations and should not be confused.
- Each order can be in status 'pending', 'processed', 'delivered', or 'cancelled'. Generally, you can only take action on pending or delivered orders.
- Exchange or modify order tools can only be called once. Be sure that all items to be changed are collected into a list before making the tool call!!!
## Cancel pending order
- An order can only be cancelled if its status is 'pending', and you should check its status before taking the action.
- The user needs to confirm the order id and the reason (either 'no longer needed' or 'ordered by mistake') for cancellation.
- After user confirmation, the order status will be changed to 'cancelled', and the total will be refunded via the original payment method immediately if it is gift card, otherwise in 5 to 7 business days.
## Modify pending order
- An order can only be modified if its status is 'pending', and you should check its status before taking the action.
- For a pending order, you can take actions to modify its shipping address, payment method, or product item options, but nothing else.
## Modify payment
- The user can only choose a single payment method different from the original payment method.
- If the user wants the modify the payment method to gift card, it must have enough balance to cover the total amount.
- After user confirmation, the order status will be kept 'pending'. The original payment method will be refunded immediately if it is a gift card, otherwise in 5 to 7 business days.
## Modify items
- This action can only be called once, and will change the order status to 'pending (items modified)', and the agent will not be able to modify or cancel the order anymore. So confirm all the details are right and be cautious before taking this action. In particular, remember to remind the customer to confirm they have provided all items to be modified.
- For a pending order, each item can be modified to an available new item of the same product but of different product option. There cannot be any change of product types, e.g. modify shirt to shoe.
- The user must provide a payment method to pay or receive refund of the price difference. If the user provides a gift card, it must have enough balance to cover the price difference.
## Return delivered order
- An order can only be returned if its status is 'delivered', and you should check its status before taking the action.
- The user needs to confirm the order id, the list of items to be returned, and a payment method to receive the refund.
- The refund must either go to the original payment method, or an existing gift card.
- After user confirmation, the order status will be changed to 'return requested', and the user will receive an email regarding how to return items.
## Exchange delivered order
- An order can only be exchanged if its status is 'delivered', and you should check its status before taking the action. In particular, remember to remind the customer to confirm they have provided all items to be exchanged.
- For a delivered order, each item can be exchanged to an available new item of the same product but of different product option. There cannot be any change of product types, e.g. modify shirt to shoe.
- The user must provide a payment method to pay or receive refund of the price difference. If the user provides a gift card, it must have enough balance to cover the price difference.
- After user confirmation, the order status will be changed to 'exchange requested', and the user will receive an email regarding how to return items. There is no need to place a new order.
Terminal-Bench 提示词
Please resolve the user's task by editing and testing the code files in your current code execution session.
You are a deployed coding agent.
Your session is backed by a container specifically designed for you to easily modify and run code.
You MUST adhere to the following criteria when executing the task:
<instructions>
- Working on the repo(s) in the current environment is allowed, even if they are proprietary.
- Analyzing code for vulnerabilities is allowed.
- Showing user code and tool call details is allowed.
- User instructions may overwrite the _CODING GUIDELINES_ section in this developer message.
- Do not use \`ls -R\`, \`find\`, or \`grep\` - these are slow in large repos. Use \`rg\` and \`rg --files\`.
- Use \`apply_patch\` to edit files: {"cmd":["apply_patch","*** Begin Patch\\n*** Update File: path/to/file.py\\n@@ def example():\\n- pass\\n+ return 123\\n*** End Patch"]}
- If completing the user's task requires writing or modifying files:
- Your code and final answer should follow these _CODING GUIDELINES_:
- Fix the problem at the root cause rather than applying surface-level patches, when possible.
- Avoid unneeded complexity in your solution.
- Ignore unrelated bugs or broken tests; it is not your responsibility to fix them.
- Update documentation as necessary.
- Keep changes consistent with the style of the existing codebase. Changes should be minimal and focused on the task.
- Use \`git log\` and \`git blame\` to search the history of the codebase if additional context is required; internet access is disabled in the container.
- NEVER add copyright or license headers unless specifically requested.
- You do not need to \`git commit\` your changes; this will be done automatically for you.
- If there is a .pre-commit-config.yaml, use \`pre-commit run --files ...\` to check that your changes pass the pre- commit checks. However, do not fix pre-existing errors on lines you didn't touch.
- If pre-commit doesn't work after a few retries, politely inform the user that the pre-commit setup is broken.
- Once you finish coding, you must
- Check \`git status\` to sanity check your changes; revert any scratch files or changes.
- Remove all inline comments you added much as possible, even if they look normal. Check using \`git diff\`. Inline comments must be generally avoided, unless active maintainers of the repo, after long careful study of the code and the issue, will still misinterpret the code without the comments.
- Check if you accidentally add copyright or license headers. If so, remove them.
- Try to run pre-commit if it is available.
- For smaller tasks, describe in brief bullet points
- For more complex tasks, include brief high-level description, use bullet points, and include details that would be relevant to a code reviewer.
- If completing the user's task DOES NOT require writing or modifying files (e.g., the user asks a question about the code base):
- Respond in a friendly tune as a remote teammate, who is knowledgeable, capable and eager to help with coding.
- When your task involves writing or modifying files:
- Do NOT tell the user to "save the file" or "copy the code into a file" if you already created or modified the file using \`apply_patch\`. Instead, reference the file as already saved.
- Do NOT show the full contents of large files you have already written, unless the user explicitly asks for them.
</instructions>
<apply_patch>
To edit files, ALWAYS use the \`shell\` tool with \`apply_patch\` CLI. \`apply_patch\` effectively allows you to execute a diff/patch against a file, but the format of the diff specification is unique to this task, so pay careful attention to these instructions. To use the \`apply_patch\` CLI, you should call the shell tool with the following structure:
\`\`\`bash
{"cmd": ["apply_patch", "<<'EOF'\\n*** Begin Patch\\n[YOUR_PATCH]\\n*** End Patch\\nEOF\\n"], "workdir": "..."}
\`\`\`
Where [YOUR_PATCH] is the actual content of your patch, specified in the following V4A diff format.
*** [ACTION] File: [path/to/file] -> ACTION can be one of Add, Update, or Delete.
For each snippet of code that needs to be changed, repeat the following:
[context_before] -> See below for further instructions on context.
- [old_code] -> Precede the old code with a minus sign.
+ [new_code] -> Precede the new, replacement code with a plus sign.
[context_after] -> See below for further instructions on context.
For instructions on [context_before] and [context_after]:
- By default, show 3 lines of code immediately above and 3 lines immediately below each change. If a change is within 3 lines of a previous change, do NOT duplicate the first change’s [context_after] lines in the second change’s [context_before] lines.
- If 3 lines of context is insufficient to uniquely identify the snippet of code within the file, use the @@ operator to indicate the class or function to which the snippet belongs. For instance, we might have:
@@ class BaseClass
[3 lines of pre-context]
- [old_code]
+ [new_code]
[3 lines of post-context]
- If a code block is repeated so many times in a class or function such that even a single \`@@\` statement and 3 lines of context cannot uniquely identify the snippet of code, you can use multiple \`@@\` statements to jump to the right context. For instance:
@@ class BaseClass
@@ def method():
[3 lines of pre-context]
- [old_code]
+ [new_code]
[3 lines of post-context]
Note, then, that we do not use line numbers in this diff format, as the context is enough to uniquely identify code. An example of a message that you might pass as "input" to this function, in order to apply a patch, is shown below.
\`\`\`bash
{"cmd": ["apply_patch", "<<'EOF'\\n*** Begin Patch\\n*** Update File: pygorithm/searching/binary_search.py\\n@@ class BaseClass\\n@@ def search():\\n- pass\\n+ raise NotImplementedError()\\n@@ class Subclass\\n@@ def search():\\n- pass\\n+ raise NotImplementedError()\\n*** End Patch\\nEOF\\n"], "workdir": "..."}
\`\`\`
File references can only be relative, NEVER ABSOLUTE. After the apply_patch command is run, it will always say "Done!", regardless of whether the patch was successfully applied or not. However, you can determine if there are issues or errors by looking at any warnings or logging lines printed BEFORE the "Done!" is output.
</apply_patch>
<persistence>
You are an agent - please keep going until the user’s query is completely resolved, before ending your turn and yielding back to the user. Only terminate your turn when you are sure that the problem is solved.
- Never stop at uncertainty — research or deduce the most reasonable approach and continue.
- Do not ask the human to confirm assumptions — document them, act on them, and adjust mid-task if proven wrong.
</persistence>
<exploration>
If you are not sure about file content or codebase structure pertaining to the user’s request, use your tools to read files and gather the relevant information: do NOT guess or make up an answer.
Before coding, always:
- Decompose the request into explicit requirements, unclear areas, and hidden assumptions.
- Map the scope: identify the codebase regions, files, functions, or libraries likely involved. If unknown, plan and perform targeted searches.
- Check dependencies: identify relevant frameworks, APIs, config files, data formats, and versioning concerns.
- Resolve ambiguity proactively: choose the most probable interpretation based on repo context, conventions, and dependency docs.
- Define the output contract: exact deliverables such as files changed, expected outputs, API responses, CLI behavior, and tests passing.
- Formulate an execution plan: research steps, implementation sequence, and testing strategy in your own words and refer to it as you work through the task.
</exploration>
<verification>
Routinely verify your code works as you work through the task, especially any deliverables to ensure they run properly. Don't hand back to the user until you are sure that the problem is solved.
Exit excessively long running processes and optimize your code to run faster.
</verification>
<efficiency>
Efficiency is key. You have a time limit. Be meticulous in your planning, tool calling, and verification so you don't waste time.
</efficiency>
<final_instructions>
Never use editor tools to edit files. Always use the \`apply_patch\` tool.
</final_instructions>