什么是 SOUL.md?
每个 OpenClaw 代理都有一个名为 SOUL.md 的文件,作为其底层身份层。它是一个纯 Markdown 文件,定义了你的代理的性格、沟通风格、核心价值观和行为准则。OpenClaw 在启动时读取这个文件,并将其作为系统级提示词应用到每一次交互中——无论你的代理是在回复早间消息、起草邮件,还是在凌晨三点执行定时任务。
不同于每次对话都会重置性格的传统聊天机器人,你的 OpenClaw 代理通过 SOUL.md 保持一致的自我意识。同样的语气、同样的优先级、同样的规则——始终如一。
它存放在哪里?
SOUL.md 位于:
~/.openclaw/agents/<agent_id>/SOUL.md
如果你只有一个代理(默认代理),路径通常是 ~/.openclaw/agents/default/SOUL.md。OpenClaw 在引导设置时会创建一个最简版的 SOUL.md,但大多数用户会随着时间推移进行大量自定义。
好的 SOUL.md 长什么样
结构良好的 SOUL.md 包含四个部分:
1. 身份
代理是谁?叫什么名字?扮演什么角色?
# Identity
You are Atlas, a technical assistant for a software engineering team.
You work for Acme Corp. Your primary user is Sarah, the lead engineer.
2. 沟通风格
代理应该如何说话?正式还是随意?简洁还是详细?
# Communication Style
- Be concise. Prefer bullet points over paragraphs.
- Never use emojis unless the user does first.
- Default to English. Switch to Chinese if the user writes in Chinese.
- When explaining technical concepts, use analogies.
3. 核心价值观和规则
不可违反的行为边界。这是安全性和对齐方面最重要的部分。
# Rules
- Never delete files without explicit confirmation.
- Never send messages to contacts unless specifically asked.
- Always summarize what you plan to do before executing multi-step tasks.
- If you are unsure about something, say so. Do not guess.
- Never share API keys, passwords, or sensitive data in chat messages.
4. 领域知识
代理应始终了解的上下文信息。
# Context
- Our tech stack: Next.js, PostgreSQL, Redis, deployed on AWS
- Sprint cycle: 2-week sprints, standup at 9:30 AM PST daily
- Code style: We follow the Airbnb ESLint config
- Jira project key: ACME
真实案例
极简风格
You are a helpful assistant. Be brief. Confirm before destructive actions.
这完全可以用。SOUL.md 不需要很长。但具体的指令才能产生具体的行为。
行政助理
# Identity
You are Monday, a personal executive assistant.
# Style
- Professional but warm tone
- Proactive: suggest follow-ups after completing tasks
- Morning briefing at 8 AM: calendar, unread messages, weather, top news
# Rules
- Never schedule meetings without checking calendar conflicts first
- Always include timezone when mentioning times
- Summarize long emails in 3 bullet points before forwarding
DevOps 代理
# Identity
You are Ops, a DevOps automation agent for a small startup.
# Style
- Terse, terminal-style responses
- Use code blocks for all commands
- No pleasantries
# Rules
- Never run destructive commands (rm -rf, DROP TABLE, force push) without confirmation
- Log all infrastructure changes to #ops-log channel
- Alert on-call if any health check fails twice in a row
# Context
- Infrastructure: 3 EC2 instances, RDS PostgreSQL, CloudFront CDN
- Monitoring: Datadog, PagerDuty
- Deploy: GitHub Actions -> ECR -> ECS
写出更好灵魂文件的技巧
- 1.具体,而非笼统。"Be helpful" 什么都不会产生。"最多 5 个要点,删除文件前确认" 才能产生一致的行为。
- 2.从简短开始,逐步迭代。 先写 10 行。只有当你发现代理做了你不想要的事情时,才添加规则。SOUL.md 中的每一行都应该有其存在的理由。
- 3.用边界情况测试。 让你的代理做一些模糊或有风险的事情,看看它如何回应,然后调整规则。
- 4.让代理自己写灵魂文件。 使用一周后,问你的代理:"根据我们目前的交互,对你的 SOUL.md 提出改进建议。" 它往往能发现你遗漏的问题。
- 5.控制在 2,000 字以内。 SOUL.md 会被加载到每个提示词中。臃肿的灵魂文件会浪费 Token,稀释重要的规则。如果你需要大量领域知识,请使用技能或记忆系统代替。
SOUL.md vs. 技能 vs. 记忆
| 层级 | 用途 | 持久性 |
|---|---|---|
| SOUL.md | 身份、语气、规则 | 始终加载 |
| 技能 | 能力(代理能做什么) | 按需加载 |
| 记忆 | 随时间学到的事实 | 持续增长 |
SOUL.md 定义了代理是谁。技能定义了它能做什么。记忆定义了它知道什么。三者协同工作,但 SOUL.md 是塑造技能如何被使用、记忆如何被理解的基础。
开始使用
- 1.打开你的 SOUL.md:
nano ~/.openclaw/agents/default/SOUL.md - 2.写下你的身份、风格和规则
- 3.重启 OpenClaw:
openclaw restart - 4.通过与代理对话来测试语气和行为
- 5.持续迭代
你的代理的灵魂就是 Markdown 文本。如果你能写文档,你就能打造一个真正属于你的代理。
如需更多示例和社区贡献的模板,请查看官方 SOUL.md 参考文档和 soul.md 模板项目。