游乐游手机版
首页/AI热点日报/热点详情

Cline源码中Prompt设计机制解析

类型:热点整理2026-07-18
Cline的SystemPrompt为核心资产,动态生成,涵盖XML格式工具调用、逐步推理、文件编辑、Act Plan模式、规则定制及Claude4优化。扩展模块含SlashCommand、Workflow、@引用和MemoryBank,共同构成高效Agent开发关键要素。
本教程深入解析 Cline 源码中的 Prompt 设计精髓,帮助开发者掌握高效 Agent 开发的关键要素。我们从 System Prompt 的核心地位入手,逐步拆解其结构、工具调用机制、模式切换、规则定制等,并延伸至 Command、Workflow、Mention 和 Memory Bank 等扩展模块,最后总结设计思想与实践要点。

1. System Prompt

System Prompt 是 Agent 的 核心资产,Github 上 system-prompts-and-models-of-ai-tools 仓库收集了各类 AI 应用的 System Prompt,已有 56.6K Star,可见其重要性。

Cline 的 System Prompt 位于 src/core/prompts/system.ts,根据上下文信息、工具及模型信息动态生成。基础身份设定如下:

You are Cline, a highly skilled software engineer with extensive knowledge in many programming languages, frameworks, design patterns, and best practices.

1.1 工具 TOOL USE

Cline 要求模型一次使用一个工具,每步都基于上一步的结果。工具调用格式使用 XML 语法:


value1
value2
...

工具列表

Cline 内置十多个工具,覆盖命令行、文件操作、浏览器、MCP 等。以 write_to_file 为例:

## write_to_file
Description: Request to write content to a file at the specified path. If the file exists, it will be overwritten with the provided content. If the file doesn't exist, it will be created. This tool will automatically create any directories needed to write the file.
Parameters:
- path: (required) The path of the file to write to (relative to the current working directory ${cwd.toPosix()})
- content: (required) The content to write to the file. ALWAYS provide the COMPLETE intended content of the file, without any truncation or omissions. You MUST include ALL parts of the file, even if they ha ven't been modified.
Usage:

File path here

Your file content here

工具调用示例

展示多个样例供模型参考:

# Tool Use Examples

## Example 1: Requesting to execute a command


npm run dev
false

工具使用指引(思维链 CoT)

Cline 手把手教会模型逐步思考:

  • 1)首先评估已掌握信息,使用标签包裹。
  • 2)根据任务和工具描述选择最合适的工具。
  • 3)一次只用一个工具,每步依赖上一步结果。
  • 4)使用指定 XML 格式构建调用。
  • 5)每次工具后等待用户回复结果,据此继续任务。
  • 6)每次使用工具后必须等待用户确认。

这能确保模型按步骤拆解任务,实时调整,保证正确性。

来源:https://www.53ai.com/news/tishicijiqiao/2025072078915.html

相关热点

继续查看同栏目近期热点。

延伸阅读

补充最近整理过的热点入口。