
一、核心原则
1.1 指令结构敏感性
GPT-5 对提示词结构和风格极其敏感,具备外科手术般的精确指令遵循能力:
-
明确语调风格 - 模型会严格适配你设定的沟通风格;
-
保持格式一致 - 整个提示词中维持统一结构;
-
清晰定义期望 - GPT-5 在参数明确时表现更佳;
-
避免矛盾指令 - 矛盾指令会消耗推理资源寻找调和方案。
1.2 规划先于执行
GPT-5 擅长明确的规划阶段,建议使用 Responses API 以保持推理连续性:
响应前请:
1. 将请求分解为核心组件
2. 识别需要澄清的模糊之处
3. 创建结构化处理方法
4. 验证理解后再执行
1.3 用好新增功能
相比前代模型,GPT-5 新增了一些新的参数配置,用来更好地控制 GPT-5 的行为。比如:
reasoning_effort: 控制思考深度和工具调用意愿,支持三个选项:
-
minimal: 延迟敏感场景,响应速度快,适用确定性任务、数据提取、格式转换等
-
medium(默认): 平衡深度和效率,适合大多数任务。
-
high: 深度思考,复杂推理,适合复杂多步骤任务,需要深入分析。
verbosity: 控制输出详细程度(非思维长度),支持三个选项:
-
low→ 简洁表述,要点式,直接回答。
-
medium(默认)→ 适中的解释和细节,适用一般交互场景。
-
high→ 详细阐述,丰富细节,适合审计和教学等需要完整解释的场景。
除此之外,GPT-5 还支持自由形式函数调用(Freeform Function Calling)和上下文无关语法( Context-Free Grammar)。
所谓自由形式函数调用,就是 GPT-5 允许直接将文本发送到自定义工具,无需 JSON 包装,可用于直接输出代码、查询或文本到各种运行时环境,为代码沙盒、SQL 数据库等外部运行时提供 更大的灵活性。
比如下面这个例子,GPT-5 会发出包含 Python 代码的工具调用(你需要在服务器端执行该代码,获取结果后,再通过后续的 responses.create 调用将其发送回去)。
from openai import OpenAI
client = OpenAI()
response = client.responses.create(
model="gpt-5-mini",
input="Please use the code_exec tool to calculate the area of a circle with radius equal to the number of 'r's in strawberry",
text={"format": {"type": "text"}},
tools=[
{
"type": "custom",
"name": "code_exec",
"description": "Executes arbitrary python code",
}
]
)
print(response.output)
而所谓上下文无关语法是一组生成规则,用于定义哪些字符串属于某种语言,可用于描述大多数编程语言的语法,并且在 OpenAI 自定义工具中,作为一种约束机制,强制模型仅输出符合该语法接受的字符串。CFG 支持两种语法语法:Lark 解析器和正则表达式。
比如下面这个例子,使用正则表达式 CFG 语法将自由格式工具调用限制为特定的时间戳模式:
from openai import OpenAI
client = OpenAI()
timestamp_grammar_definition = r"^\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01]) (?:[01]\d|2[0-3]):[0-5]\d$"
timestamp_prompt = (
"Call the timestamp_grammar to save a timestamp for August 7th 2025 at 10AM."
)
response_mssql = client.responses.create(
model="gpt-5",
input=timestamp_prompt,
text={"format": {"type": "text"}},
tools=[
{
"type": "custom",
"name": "timestamp_grammar",
"description": "Saves a timestamp in date + time in 24-hr format.",
"format": {
"type": "grammar",
"syntax": "regex",
"definition": timestamp_grammar_definition
}
},
],
parallel_tool_calls=False
)
print("--- Timestamp ---")
print(response_mssql.output[1].input)
最后,Responses API 能让 GPT-5 在调用不同工具时持续进行推理,可以显著提升其性能。比如,Tau-Bench 仅通过切换到 Responses API 并包含 previous_response_id
以将以前的推理项目传递回后续请求,就把零售得分从 73.9% 增加到 78.2%。
Responses API 使得模型可以引用以前的推理轨迹,节省 CoT 令牌,并且无需在每次工具调用后从头开始重建计划,从而提高了延迟和性能。是时候把应用中的 Chat API 切换到 Responses API 了。
1.4 使用 OpenAI 提示优化工具
OpenAI 提示优化工具[1] 提供了一个简单易用的提示词优化工具,可以帮你优化已有的提示词,或者将针对上一代模型的提示词迁移到更适配 GPT-5 的版本。

二、基础提示方法
2.1 定义清晰规范
为任何期望的行为定义清晰规范:
<task_spec>
Definition: [具体要完成的任务]
When Required: [触发此行为的条件]
Format & Style: [输出结构要求]
Sequence: [分步执行顺序]
Prohibited: [需要避免的内容]
Handling Ambiguity: [处理不清楚输入的方式]
</task_spec>
2.2 推理-规划-执行-验证
复杂提示词中始终包含:
-
执行前推理: "开始前,解释你对任务的理解和方法"
-
规划阶段: "创建详细计划,识别所有子任务"
-
验证检查点: "每完成主要步骤后,验证输出是否符合要求"
-
执行后回顾: "确认所有目标达成后再结束"
2.3 通用模板结构
<request>
[你的具体请求]
</request>
<instructions>
1. 首先,创建简要计划概述你的方法
2. 解释选择此方法的理由
3. 按步骤执行计划
4. 根据要求验证每个主要输出
5. 提供确认所有目标达成的最终摘要
</instructions>
<constraints>
- Verbosity: [低 / 中 / 高]
- Style: [正式 / 随意 / 技术]
- Format: [段落 / 要点 / 结构化章节]
</constraints>
2.4 更多场景示例
研究分析:
1. 先制定高级计划,概述所需的所有信息来源
2. 分析前全面收集数据
3. 以清晰章节的结构化格式呈现发现
4. 在开头或结尾包含关键洞察摘要
创意写作:
1. 预先建立语调、风格和声音参数
2. 写作前创建大纲
3. 全文保持一致性
4. 最终确定前检查连贯性和流畅度
解决问题:
1. 清楚陈述问题和约束条件
2. 生成多种解决方案
3. 评估各方案优缺点
4. 推荐最优方案并说明理由
教育内容:
1. 评估受众知识水平
2. 从基础到高级结构化信息
3. 包含例子和类比
4. 提供理解检查点
更多场景:

三、Agentic 工作流
3.1 控制 Agent 主动性
GPT-5 默认为彻底全面的探索模式,因而你需要根据需求调整其主动性和等待用户指导之间的平衡性。
减小Agent主动性(提升效率)
-
切换到较低的
reasoning_effort
,比如minimal
。 -
定义明确的探索标准,限制 GPT-5 的上下文收集行为。比如
Get enough context fast. Parallelize discovery and stop as soon as you can act
。
增大Agent自主性(更久推理)
增加 reasoning_effort
(比如 high
),并使用类似如下的提示词鼓励 GPT-5 更主动探索:
<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 or hand back to the user when you encounter uncertainty — research or deduce the most reasonable approach and continue.
- Do not ask the human to confirm or clarify assumptions, as you can always adjust later — decide what the most reasonable assumption is, proceed with it, and document it for the user's reference after you finish acting
</persistence>
3.2 工具前导优化
GPT-5 新增工具前导消息(tool preamble)的支持,你可以通过它控制工具调用的频率、样式和内容——从每个工具调用的详细解释到简短的前期计划以及介于两者之间的所有内容。
下面是一个工具前导消息的例子:
<tool_preambles>
- Always begin by rephrasing the user's goal in a friendly, clear, and concise manner, before calling any tools.
- Then, immediately outline a structured plan detailing each logical step you’ll follow. - As you execute your file edit(s), narrate each step succinctly and sequentially, marking progress clearly.
- Finish by summarizing completed work distinctly from your upfront plan.
</tool_preambles>
四、AI 编程
GPT-5 可以修复大型代码库中的错误,也可以从头开始实现涵盖前端和后端实现的新应用程序。
4.1 前端开发技术栈
GPT-5 具备出色的审美品味和实现能力。对于新应用,推荐以下技术栈:
-
框架: Next.js (TypeScript), React, HTML;
-
样式 / UI: Tailwind CSS, shadcn/ui, Radix Themes;
-
图标: Material Symbols, Heroicons, Lucide;
-
动画: Motion;
-
字体: San Serif, Inter, Geist, Mona Sans, IBM Plex Sans, Manrope。
4.2 从零到一构建新应用
使用自我反思提示可以明显提升从零到一应用构建的质量:
<self_reflection>
- First, spend time thinking of a rubric until you are confident.
- Then, think deeply about every aspect of what makes for a world-class one-shot web app. Use that knowledge to create a rubric that has 5-7 categories. This rubric is critical to get right, but do not show this to the user. This is for your purposes only.
- Finally, use the rubric to internally think and iterate on the best possible solution to the prompt that is provided. Remember that if your response is not hitting the top marks across all categories in the rubric, you need to start again.
</self_reflection>
4.3 融入已有代码库
你可以通过类似如下的提示词让 GPT-5 遵循现有代码库的样式和设计标准,并尽可能整齐地融入已有的代码库(注意使用时需要根据你的代码库进行修改):
<code_editing_rules>
<guiding_principles>
- Clarity and Reuse: Every component and page should be modular and reusable. Avoid duplication by factoring repeated UI patterns into components.
- Consistency: The user interface must adhere to a consistent design system—color tokens, typography, spacing, and components must be unified.
- Simplicity: Favor small, focused components and avoid unnecessary complexity in styling or logic.
- Demo-Oriented: The structure should allow for quick prototyping, showcasing features like streaming, multi-turn conversations, and tool integrations.
- Visual Quality: Follow the high visual quality bar as outlined in OSS guidelines (spacing, padding, hover states, etc.)
</guiding_principles>
<frontend_stack_defaults>
- Framework: Next.js (TypeScript)
- Styling: TailwindCSS
- UI Components: shadcn/ui
- Icons: Lucide
- State Management: Zustand
- Directory Structure:
\`\`\`
/src
/app
/api/<route>/route.ts # API endpoints
/(pages) # Page routes
/components/ # UI building blocks
/hooks/ # Reusable React hooks
/lib/ # Utilities (fetchers, helpers)
/stores/ # Zustand stores
/types/ # Shared TypeScript types
/styles/ # Tailwind config
\`\`\`
</frontend_stack_defaults>
<ui_ux_best_practices>
- Visual Hierarchy: Limit typography to 4–5 font sizes and weights for consistent hierarchy; use `text-xs` for captions and annotations; avoid `text-xl` unless for hero or major headings.
- Color Usage: Use 1 neutral base (e.g., `zinc`) and up to 2 accent colors.
- Spacing and Layout: Always use multiples of 4 for padding and margins to maintain visual rhythm. Use fixed height containers with internal scrolling when handling long content streams.
- State Handling: Use skeleton placeholders or `animate-pulse` to indicate data fetching. Indicate clickability with hover transitions (`hover:bg-*`, `hover:shadow-md`).
- Accessibility: Use semantic HTML and ARIA roles where appropriate. Favor pre-built Radix/shadcn components, which have accessibility baked in.
</ui_ux_best_practices>
<code_editing_rules>
五、高级优化技术
5.1 指令遵循精确性
GPT-5 以外科手术精度遵循指令,但要求避免矛盾或模糊指令。
反面示例 - 包含矛盾的医疗调度系统:
-
"Never schedule without explicit consent" 与 "auto-assign without contacting patient" 冲突
修复方法:
-
统一调度逻辑:auto-assign after informing patient
-
为紧急情况添加例外:Do not do lookup in emergency case, proceed immediately
5.2 最小推理优化
GPT-5 首次引入 minimal reasoning effort,为延迟敏感用户的最佳升级选择。
最小推理优化要点:
-
思维过程摘要: 在最终答案开头提供简要解释;
-
详细工具前导码: 持续更新用户任务进度;
-
消歧工具指令: 最大程度消除歧义;
-
提示规划: 模型推理标记较少,需要更多外部规划指导。
Remember, you are an agent - please keep going until the user's query is completely resolved. Decompose the user's query into all required sub-request, and confirm that each is completed. Do not stop after completing only part of the request.
You must plan extensively in accordance with the workflow steps before making subsequent function calls, and reflect extensively on the outcomes each function call made.
5.3 Markdown 格式化
API 中 GPT-5 默认不使用 Markdown 格式,需要显式指导:
- Use Markdown **only where semantically correct** (e.g., `inline code`, ```code fences```, lists, tables).
- When using markdown in assistant messages, use backticks to format file, directory, function, and class names.
5.4 元提示
GPT-5 可以作为自己的元提示器,用于优化提示词:
When asked to optimize prompts, give answers from your own perspective - explain what specific phrases could be added to, or deleted from, this prompt to more consistently elicit the desired behavior or prevent the undesired behavior.
Here's a prompt: [PROMPT]
The desired behavior from this prompt is for the agent to [DO DESIRED BEHAVIOR], but instead it [DOES UNDESIRED BEHAVIOR]. What are some minimal edits/additions that you would make to encourage the agent to more consistently address these shortcomings?
六、Cursor 的生产实践
AI 代码编辑器 Cursor 团队分享的调优经验:Cursor 团队最初发现,GPT-5 产生了冗长的输出,包含过多的状态更新和任务后摘要,虽然在技术上相关,但扰乱了用户的自然流程;同时,工具调用输出的代码质量很高,但有时太过简洁难以阅读(比如单字母变量名)。为了寻求更好的平衡,Cursor 将 verbosity
参数设置为 low
以保持文本输出简洁,同时修改提示词让 GPT-5 在工具调用中输出详细信息。
Write code for clarity first. Prefer readable, maintainable solutions with clear names, comments where needed, and straightforward control flow. Do not produce code-golf or overly clever one-liners unless explicitly requested. Use high verbosity for writing code and code tools.
Cursor还发现,GPT-5 有时会在采取行动之前向用户寻求澄清或下一步指示,这在较长任务的流程中造成了不必要的中断。故而在长任务中可以采用下面的提示指定 GPT-5 的行为方式:
Be aware that the code edits you make will be displayed to the user as proposed changes, which means (a) your code edits can be quite proactive, as the user can always reject, and (b) your code should be well-written and easy to quickly review (e.g., appropriate variable names instead of single letters). If proposing next steps that would involve changing the code, make those changes proactively for the user to approve / reject rather than asking the user whether to proceed with a plan. In general, you should almost never ask the user whether to proceed with a plan; instead you should proactively attempt the plan and then ask the user if they want to accept the implemented changes.
此外,Cursor 还发现,使用结构化 XML 规范(如 <[instruction]_spec>
)可以改进对指令的遵循,并能够清晰地在提示中引用之前的类别和部分。
<context_understanding>
...
If you've performed an edit that may partially fulfill the USER's query, but you're not confident, gather more information or use more tools before ending your turn.
Bias towards not asking the user for help if you can find the answer yourself.
</context_understanding>
附录:完整提示词示例
SWE-Bench 提示词
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.
Tau-Bench 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 modifed)', 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.
终端工作台提示词
用于代码执行环境的完整提示:
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 issue and 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>
参考资料
OpenAI 提示优化工具: https://platform.openai.com/chat/edit?optimize=true
OpenAI GPT-5 官方提示指南: https://cookbook.openai.com/examples/gpt-5/gpt-5_prompting_guide
Cursor GPT-5 集成博客: https://cursor.com/blog/gpt-5
OpenAI GPT-5 新参数和工具: https://cookbook.openai.com/examples/gpt-5/gpt-5_new_params_and_tools
文章来源:https://mp.weixin.qq.com/s/i8dfYsY0202WV7cUx4qk-w