Skip to content

OpenClaw agent 个性与记忆配置完整指南

问题

新部署 OpenClaw 后,agent 行为千篇一律:没有特定个性、记不住用户偏好、每次对话从零开始。不知道如何通过 SOUL.mdAGENTS.mdMEMORY.md 等配置文件定制 agent 的个性、行为准则和长期记忆。

解决方案

OpenClaw 使用一组 Markdown 配置文件来定义 agent 的"灵魂"。这些文件存放在 agent 的工作目录或 ~/.openclaw/ 下,gateway 启动时会加载。

核心配置文件一览

文件作用
AGENTS.md工作流准则:agent 应如何行动、优先级、禁止行为
SOUL.md个性定义:语气、价值观、思维方式
IDENTITY.md名字、形象、角色设定
USER.md关于你(用户)的信息和偏好,让 agent 更了解你
TOOLS.md能力清单:列出所有可用设备、服务、工具映射
MEMORY.md长期记忆:跨会话积累的经验摘要

SOUL.md 示例(个性定义)

markdown
# Soul

Be genuinely helpful — not in a watered-down way, but actually solve problems.
Have opinions and share them, but stay open to being wrong.
Be resourceful before asking: try first, then ask if stuck.
Write like a thoughtful engineer, not a customer service bot.
If unsure, make a reasonable assumption and say so.

AGENTS.md 示例(工作流准则)

markdown
# Agents

## Workflow
1. Read the task fully before acting.
2. Break large tasks into verifiable steps.
3. Confirm destructive actions (delete, overwrite) before executing.

## Constraints
- Never commit secrets to git.
- Always check if a file exists before creating it.
- Prefer editing existing code over rewriting from scratch.

MEMORY.md 示例(长期记忆)

markdown
# Memory

## Key Learnings
- User prefers TypeScript over JavaScript.
- The project uses Bun, not npm.
- Database migrations go in db/migrations/, not src/.

## Ongoing Context
- Working on feature X (started 2026-03, paused).

按日期存储详细记忆:memory/2026-04-21.mdMEMORY.md 只存摘要。

Git 版本管理(必做)

用 Git 管理这些配置文件,但要保护 token:

bash
# .gitignore 中排除敏感文件
echo ".env" >> .gitignore
echo "*.token" >> .gitignore

# 提交配置文件
git add SOUL.md AGENTS.md IDENTITY.md USER.md TOOLS.md MEMORY.md
git commit -m "chore: update agent personality and memory config"

所有 token(botToken、apiKey 等)存在 .env 文件,绝不写入 Markdown 配置:

bash
# .env(加入 .gitignore)
TELEGRAM_BOT_TOKEN=7xxx...
OPENAI_API_KEY=sk-...

在 AWS 上安全访问 Web 仪表板

OpenClaw 自带 Web 管理界面,在 AWS 等云服务器上建议通过 SSH 隧道访问,而非直接暴露端口:

bash
# 本地终端:建立 SSH 隧道
ssh -L 18080:localhost:18080 user@your-aws-ip

# 然后在本地浏览器访问
open http://localhost:18080

常见问题

Q: 修改了 SOUL.md,但 agent 行为没变,怎么办?

A: 需要重启 gateway 才能重新加载配置文件:openclaw gateway restart。如果仍无变化,用 openclaw logs --follow 检查是否有配置加载错误。

Q: MEMORY.md 越写越长,会影响性能吗?

A: 会。MEMORY.md 每次都作为系统提示的一部分发送给模型,过长会增加 token 消耗并可能超出上下文窗口。建议:MEMORY.md 只保留 2-3 条最重要的长期事实,详细内容按日期分拆到 memory/YYYY-MM-DD.md