精读 Cursor、v0 提示词: 如何编写强大的 Agent 系统提示词
发布于 2025年4月28日
这里总结目前流行的 Agent 系统提示词遵循 8 个实践要点:
- 明确的目标、角色和范围
- 结构化的指令与任务分解
- 明确工具集成与使用指南
- 逐步推理、规划
- 环境和上下文
- 特定领域的专业知识和限制
- 安全、对齐、拒绝协议
- 设定语气和互动风格
遵循这些要点,可以显著提升 Agent 的性能、可靠性和用户体验。
后面围绕着这些内容进行解析,并给出实际的 AI agent 系统(v0 和 Cursor Agent 模式) 的提示词是怎么描述的。
一步一步解析
一、明确的目标、角色和范围
明确界定 AI 的身份定位、核心功能及运作领域,能有效锚定其行为模式,设定用户预期,并防止功能范围的无序扩张或产生无意义的反馈。这相当于为 AI 确立了身份标识与职责边界。
v0: 明确了 AI 是谁
## Core Identity
You are v0, Vercel's AI-powered assistant.
Cursor Agent: 明确了 AI 是谁,设定用户可能会做什么并要求他做什么事
You are a powerful agentic AI coding assistant, powered by Claude 3.7 Sonnet. You operate exclusively in Cursor, the world's best IDE.
You are pair programming with a USER to solve their coding task.
The task may require creating a new codebase, modifying or debugging an existing codebase, or simply answering a question.
Each time the USER sends a message......
......
Your main goal is to follow the USER's instructions at each message, denoted by the <user_query> tag.
二、结构化的指令与任务分解
结构化的使用标题、列表、代码块或自定义标签,能帮助Agent 的维护者清晰理解,也能协助 AI 更精确地解析、区分不同规则或信息集的优先级,减少歧义。
v0: 使用了 markdown 的结构,大量的使用 ## Instructions
、## Code Project Instructions
指定标题来区分规则,使用 - useXXX
项目符号一条一条的罗列规则。
Cursor Agent: 使用类似 XML 的结构进行组织,使用 1. xxx 2.xxx
来罗列规则
<tool_calling>
You have tools at your disposal to solve the coding task. Follow these rules regarding tool calls:
1. xxx
2. xxx
</tool_calling>
三、明确工具集成与使用指南
对于 Agent 的行为,需要向 AI 描述清楚:它们是什么,它们做什么,如何调用它们(语法、参数),所需的格式(例如XML、JSON),以及至关重要的是,何时不使用它们。这需要详细的描述、清晰的模式和明确的规则。
v0: 明确使用 MDX Components 作为核心工具 , <CodeProject>
用来组织文件结构, <DeleteFile />
文件操作组件 (<DeleteFile />
, <MoveFile />
)
# Available MDX Components
You have access to custom code block types that allow it to execute code in a secure, sandboxed environment the user can interact with.
......
### File Actions
1. v0 can delete a file in a Code Project by using the <DeleteFile /> component.
...
2. v0 can rename or move a file in a Code Project by using the <MoveFile /> component.
...
......
Cursor Agent: 在 tool_calling 标签中定义了工具调用的规则,在 functions 中每个 function 清晰的定义了可以调用的描述、出参入参的描述。
<tool_calling>
You have tools at your disposal to solve the coding task. Follow these rules regarding tool calls:
1. ALWAYS follow the tool call schema exactly as specified and ...
2. The conversation may reference tools that are no longer available...
3. ...
4. ...
</tool_calling>
<functions>
<function>
{
"description":"...",
"name": "codebase_search",
"parameters": {
"properties": {
"explanation": {
"description": "...",
"type": "string",
},
...
}
},
}
</function>
<function>{"description":..."}</function>
</functions>
四、逐步推理、规划
复杂任务需要需要进行拆解。需要引导 AI 有条理地思考、规划行动、迭代执行,并在进行下一个任务前,等待用户的反馈或结果,从而减少错误并提升连贯性。
v0: 要求事前规划和事后建议,创建项目前,需要使用 <Thinking>
标签进行规划。在完成响应后,会进行下一步的建议。
### Planning
BEFORE creating a Code Project, v0 uses <Thinking> tags to think through the project structure, styling, images and media, formatting, frameworks and libraries, and caveats to provide the best possible solution to the user's query.
### Suggested Actions
1. After responding, v0 suggests 3-5 relevant follow-up actions.
2. ...
3. ...
4. ...
Cursor Agent: 做了过程控制和前置条件检查,规定每次最多使用一次代码编辑工具。在编辑文件之前必须先读一遍文件等等。
<making_code_changes>
When making code changes, NEVER output code to the USER, unless requested. Instead use one of the code edit tools to implement the change.
Use the code edit tools at most once per turn.
1...
...
5. Unless you are appending some small easy to apply edit to a file ...
...
</making_code_changes>
五、环境和上下文
Agent 会在各种特定环境(如操作系统、集成开发环境、浏览器沙箱、特定库)中运行。提供这些上下文信息能让 AI 生成兼容的代码、使用合适的命令,以及理解环境的限制。
v0: 规定了 <Next.js>
运行时环境,<current_time>
提供当前时间等等
<Next.js>
- Code Projects run in the "Next.js" runtime.
- The "Next.js" runtime is a lightweight ...
...
<working_in_next_lite>
- Next.js cannot infer props for React Components, so v0 MUST provide default props.
...
</working_in_next_lite>
</Next.js>
Cursor Agent: 提供了用户的环境信息,提示词会根据真实用户的环境进行替换{os}
、{workspace}
、{shell}
<user_info>
The user's OS version is {os}. The absolute path of the user's workspace is {workspace}. The user's shell is {shell}.
</user_info>
六、特定领域的专业知识和限制
需要告诉 Agent 需要处理的特定领域(如网页开发、数据分析等)。需要在提示词中加入领域专业知识、最佳实践、风格指南以及约束条件,以确保输出内容既高质量又符合上下文的需求。
v0: 限定了领域在 Vercel、Next.js、AI SDK 等中,使用 Tailwind css shadcn/ui 等技术栈.
You are always up-to-date with the latest technologies and best practices.
...v0 defaults to the Next.js App Router; other frameworks may not work in the v0 preview.
...
Next.js comes with Tailwind CSS, Next.js, shadcn/ui components, and Lucide React icons pre-installed
...
Cursor Agent: 不能调用规定之外的 tools。限定了代码引用格式。规定了代码块的格式。
NEVER call tools that are not explicitly provided.
You MUST use the following format when citing code regions or blocks:
\`\`\`startLine:endLine:filepath
// ... existing code ...
\`\`\`
七、安全、对齐、拒绝协议
负责任的 Agent 需要明确的界限。提示词需要界定负面的请求,并规定 AI 应如何拒绝此类请求。也要确保如何正确安全地做事。
v0: 如果用户需要帮助就会支持导航到指定页面,也会用户负面输入时进行拒绝回复。
- If users are frustrated or need human support, direct them to open a support ticket at vercel.com/help.
# Refusals
REFUSAL_MESSAGE = "I'm sorry. I'm not able to assist with that."
1. If the user asks for violent, harmful, hateful, inappropriate, or sexual/unethical content, v0 responds with a refusal message.
2. When refusing, v0 MUST NOT apologize or provide an explanation...
Cursor Agent: 确保用户可以立即运行生成的代码;在修复同一文件上的错误时,不要循环超过 3 次。可选参数不要询问等等。
It is *EXTREMELY* important that your generated code can be run immediately by the USER
...
...And DO NOT loop more than 3 times on fixing linter errors on the same file...
...
...DO NOT make up values for or ask about optional parameters...
八、设定语气和互动风格
设定一致的角色定位(例如友善的专家、风趣的助手、直率的工程师)能打造更具可预测性和吸引力的用户体验。具体实施时,可从宽泛的指导原则延伸至非常细致的风格化指令。
v0: 在 ### Suggested Actions
定义了互动风格,会给用户下一步的建议。强调了非常多的专业术语,暗示了一种技术性强、精确、聚焦于开发者需求的互动风格。
Cursor Agent: 调用工具前跟用户先解释;要求创建漂亮现代的 UI、UX;使用了非常多的 ALWAYS
、NEVER
、MUST
、EXTREMELY
等词汇,向 AI 传达重要性和不可协商性。
...
Before calling each tool, first explain to the USER why you are calling it.
...
If you're building a web app from scratch, give it a beautiful and modern UI, imbued with best UX practices.
参考
- 参考完整的 v0 提示词
- 参考完整的 Cursor agent 提示词
- agents 系统提示词库:wesome-ai-system-prompts
- agents 系统提示词库:system-prompts-and-models-of-ai-tools