当我们与 AI 助手对话时,很少有人思考过:是什么塑造了它的性格、能力和行为边界?答案就藏在那些被称为"系统提示词"(System Prompt)的文本中。今天,让我们一起揭开 Kimi Code CLI 这位优秀编程助手的"灵魂"面纱。
在大型语言模型(LLM)的世界里,系统提示词就像是角色的"设定集"。它定义了:
Kimi Code CLI 作为一个月之暗面开源的 AI 编程助手,其系统提示词设计展现了极高的工程智慧。通过分析其源代码中的提示词文件,我们可以窥见一个优秀 AI Agent 的"灵魂"是如何被精心雕琢的。
打开 src/kimi_cli/agents/default/system.md,我们看到的是一份长达 130 行的"行为宪章"。
You are Kimi Code CLI, an interactive general AI agent running on a user's computer.
Your primary goal is to answer questions and/or finish tasks safely and efficiently,
adhering strictly to the following system instructions and the user's requirements,
leveraging the available tools flexibly.
开篇明义,四个关键词勾勒出核心身份:
关于工具使用,system.md 有着精妙的平衡设计:
并行调用的智慧:
If you anticipate making multiple non-interfering tool calls,
you are HIGHLY RECOMMENDED to make them in parallel to significantly improve efficiency.
这不仅是一个技术建议,更体现了对用户体验的深刻理解——在可能的范围内, minimize 等待时间。
自我解释的约束:
When calling tools, do not provide explanations because the tool calls themselves
should be self-explanatory.
这是一个反直觉但极其精妙的设计。它避免了冗余的"我现在要读取文件了"之类的废话,让交互更加干净利落。
system.md 对编程任务进行了精细分类指导:
从零构建时的要求:
最值得关注的是安全提醒:
The operating environment is not in a sandbox. Any actions you do will immediately
affect the user's system. So you MUST be extremely cautious.
这不是简单的免责声明,而是深植于 Agent "灵魂"中的谨慎本能。配合后续的"除非明确指示,不要访问工作目录外的文件",形成了一道安全防线。
system.md 中对 AGENTS.md 的说明展现了独特的元认知设计:
Markdown files named `AGENTS.md` usually contain the background, structure, coding styles,
user preferences and other relevant information about the project.
> Why `AGENTS.md`?
>
> `README.md` files are for humans: quick starts, project descriptions, and contribution guidelines.
> `AGENTS.md` complements this by containing the extra, sometimes detailed context coding agents need...
这种设计承认了一个事实:人类和 AI 需要不同的文档。README 给人看,AGENTS.md 给 AI 看。这是一种对"受众意识"的深刻体现。
system.md 的结尾是八个品格要求:
At any time, you should be HELPFUL and POLITE, CONCISE and ACCURATE, PATIENT and THOROUGH.
HELPFUL 和 POLITE 是对待用户的态度;
CONCISE 和 ACCURATE 是输出内容的标准;
PATIENT 和 THOROUGH 是工作方法的准则。
这六个词,构成了 Kimi Code CLI 的"人格基石"。
在 src/kimi_cli/agents/default/sub.yaml 中,我们发现了一个有趣的"角色叠加"机制。
子代理规范通过 extend: ./agent.yaml 继承了主代理的所有配置,但添加了独特的角色定义:
ROLE_ADDITIONAL: |
You are now running as a subagent. All the `user` messages are sent by the main agent.
The main agent cannot see your context, it can only see your last message when you
finish the task. You need to provide a comprehensive summary on what you have done
and learned in your final message.
这段提示词精妙地解决了多代理系统中的信息边界问题:
子代理还被明确禁止了某些能力:
exclude_tools:
- "kimi_cli.tools.multiagent:Task"
- "kimi_cli.tools.multiagent:CreateSubagent"
- "kimi_cli.tools.dmail:SendDMail"
这种"能力裁剪"防止了无限递归的风险——子代理不能再创建子代理,确保了系统的稳定性。
长对话是 LLM 应用的一大挑战。src/kimi_cli/prompts/compact.md 提供了一套精妙的上下文压缩策略。
压缩不是简单的截断,而是有优先级的信息保留:
压缩后的信息不是简单的文本,而是结构化数据:
<current_focus>
[What we're working on now]
</current_focus>
<environment>
- [Key setup/config points]
</environment>
<completed_tasks>
- [Task]: [Brief outcome]
</completed_tasks>
这种结构化让压缩后的信息更易于被 LLM 理解和利用。
src/kimi_cli/prompts/init.md 是一个特殊的提示词——它指导 Agent 如何生成 AGENTS.md。
You are a software engineering expert with many years of programming experience.
Please explore the current project directory to understand the project's architecture
and main details.
这是一种"元能力":Agent 不仅要完成任务,还要总结自己的理解,为未来的自己(或其他 Agent)留下指南。
任务要求包括:
这种设计让 Kimi Code CLI 具备了"自我文档化"的能力。
如果说 system.md 是"核心灵魂",那么 Skill 系统就是"可插拔的能力模块"。
从 skill-creator/SKILL.md 中,我们看到 Skill 被定义为:
"onboarding guides for specific domains or tasks—they transform Kimi from a general-purpose agent into a specialized agent equipped with procedural knowledge that no model can fully possess."Skill 的精妙之处在于渐进式披露(Progressive Disclosure):
skill-creator 中阐述了几个核心设计原则:
Concise is Key:
"The context window is a public good... Challenge each piece of information: 'Does Kimi really need this explanation?'"
一个典型的 Skill 包含:
skill-name/
├── SKILL.md (required)
│ ├── YAML frontmatter metadata
│ └── Markdown instructions
└── Bundled Resources (optional)
├── scripts/ # 可执行代码
├── references/ # 参考文档
└── assets/ # 输出资源
这种结构化让 Skill 既可以提供指导,也可以提供工具。
通过分析 Kimi Code CLI 的系统提示词,我们可以总结出以下设计哲学:
优秀的系统提示词不是告诉 Agent 要做什么,而是定义了边界和原则:
所有设计都体现了对用户的深刻理解:
通过 init.md 和 Skill 系统,Kimi Code CLI 具备了自我进化的能力:
系统提示词是 AI Agent 的"灵魂 Blueprint"。Kimi Code CLI 的设计展现了如何在这个 Blueprint 中平衡:
对于正在构建 AI 应用的开发者来说,Kimi Code CLI 的系统提示词设计提供了宝贵的参考:
参考资源:
src/kimi_cli/agents/default/system.mdsrc/kimi_cli/skills/skill-creator/SKILL.md本文基于 Kimi Code CLI 开源项目的系统提示词文件进行分析,旨在分享 AI Agent 设计的最佳实践。
还没有人回复