AGENTS.md 模板
AGENTS.md 是 OpenClaw Agent 的行为指令文件,定义了 Agent 应该如何响应用户、使用哪些工具以及遵循哪些约束。它是系统提示词(System Prompt)的核心组成部分。
模板
markdown
# AGENTS.md Template
This file defines your agent's behavior and instructions.
## Agent Instructions
- Be helpful and concise
- Always verify before taking destructive actions
- Prefer reading files before editing them
## Tools
- Use web_search for current information
- Use file operations carefully
## Constraints
- Never expose API keys or secrets
- Ask for confirmation before sending messages各节详解
Agent Instructions(行为指令)
这是 AGENTS.md 的核心部分,直接注入模型的系统提示词。
markdown
## Agent Instructions
- 使用简洁、专业的语言回答问题
- 对于不确定的信息,明确告知用户
- 代码相关问题优先提供可运行的示例
- 遇到敏感操作前先确认用户意图指令编写技巧
指令应该具体可执行。避免模糊描述如"做得好",使用明确指令如"回复不超过 3 段话"。
Tools(工具策略)
定义 Agent 可使用的工具及使用方式:
markdown
## Tools
- web_search: allow # 自动执行
- send_email: ask # 需用户确认
- delete_file: deny # 禁止使用
- code_exec: allow # 自动执行
### Tool Usage Guidelines
- 查询信息时优先使用 knowledge_search
- 仅在知识库无结果时使用 web_search
- 发送消息前必须向用户确认内容Constraints(约束条件)
定义 Agent 的行为红线:
markdown
## Constraints
- Never expose API keys, tokens, or credentials
- Never execute commands that modify system files
- Always respond in the same language as the user
- Do not generate content that violates platform policies
- Maximum response length: 2000 characters约束的重要性
约束条件是 Agent 安全运行的关键防线。LLM 会将这些约束作为强指令遵循,但不能保证 100% 遵守。建议配合工具策略做硬性限制。
高级定制
条件指令
markdown
## Agent Instructions
### When channel is wechat
- 使用轻松的对话风格
- 回复长度不超过 500 字
- 适当使用表情符号
### When channel is email
- 使用正式的商务风格
- 包含问候语和落款
- 回复可以更加详细多语言支持
markdown
## Agent Instructions
- Detect the user's language and respond in the same language
- For Chinese users, use Simplified Chinese (简体中文)
- Technical terms should be in English with Chinese explanation on first use多 Agent 协作指令
markdown
## Agent Instructions
- 编程问题转交给 coding-agent
- 写作任务转交给 writing-agent
- 你只处理日常对话和任务分发
## Sub-agents
- coding-agent: 处理代码相关任务
- writing-agent: 处理写作相关任务文件加载行为
| 行为 | 说明 |
|---|---|
| 加载时机 | 每次 Agent 运行时 |
| 注入位置 | 系统提示词的指令部分 |
| 子 Agent | 继承主 Agent 的 AGENTS.md |
| 热更新 | 修改后下次会话生效 |
| 缺省行为 | 无 AGENTS.md 时使用内置默认指令 |
与 SOUL.md 的关系
AGENTS.md 定义 Agent 做什么(行为),SOUL.md 定义 Agent 是什么(人格)。两者互补,共同构成 Agent 的完整身份。
