乐于分享
好东西不私藏

OpenClaw 多 Agent 配置实战指南

OpenClaw 多 Agent 配置实战指南

基于 OpenClaw 2026.3.23-2 版本,亲测可用。

📋 配置前准备

环境要求

  • OpenClaw 版本
    : 2026.3.23-2 或更高
  • Node.js
    : v18+
  • 模型 Provider
    : DashScope(阿里云)已配置

检查当前配置

  1. # 查看版本
  2. openclaw --version
  3. # 查看当前配置
  4. cat ~/.openclaw/openclaw.json | jq .agents
  5. # 检查服务状态
  6. openclaw gateway status

🎯 为什么要配置多 Agent

单 Agent 的局限:

  • 一个模型干所有活,效率低
  • 专业任务不够专业(比如写代码不如专用模型)
  • 无法并行处理复杂任务

多 Agent 的优势:

  • 专人专事(代码交给 coder,写作交给 creative)
  • 并行协作(复杂任务分给多个 agent)
  • 成本优化(简单任务用便宜模型)

📦 第一步:备份原配置

重要!先备份,防止配错了回不去。

  1. cp ~/.openclaw/openclaw.json ~/.openclaw/openclaw.json.backup.$(date +%Y%m%d)

🔧 第二步:编辑配置文件

打开配置文件:

  1. vim ~/.openclaw/openclaw.json

找到 agents部分,替换成下面的配置。


📝 第三步:多 Agent 配置(完整版)

  1. {
  2. "agents":{
  3. "defaults":{
  4. "model":{
  5. "primary":"dashscope/qwen3.5-plus"
  6. },
  7. "imageModel":{
  8. "primary":"dashscope/qwen3-vl-plus"
  9. },
  10. "models":{
  11. "dashscope/qwen3.5-plus":{"alias":"assistant"},
  12. "dashscope-us/qwen3-max-2025-09-23":{"alias":"max"},
  13. "dashscope/glm-4.7":{"alias":"glm"},
  14. "dashscope/glm-5":{"alias":"long-text"},
  15. "dashscope/qwen3-coder-next":{"alias":"coder-fast"},
  16. "dashscope/qwen3-coder-plus":{"alias":"coder"},
  17. "dashscope/qwen3-vl-flash":{"alias":"vision-fast"},
  18. "dashscope/qwen3-vl-plus":{"alias":"vision"},
  19. "dashscope/MiniMax-M2.5":{"alias":"reasoning"},
  20. "dashscope/kimi-k2.5":{"alias":"creative"},
  21. "dashscope/wan2.6-t2i":{"alias":"image-gen"}
  22. },
  23. "workspace":"/home/admin/.openclaw/workspace",
  24. "compaction":{"mode":"safeguard"}
  25. },
  26. "list":[
  27. {
  28. "id":"main",
  29. "name":"通用助手",
  30. "model":{"primary":"dashscope/qwen3.5-plus"},
  31. "subagents":{"thinking":"off"}
  32. },
  33. {
  34. "id":"coder",
  35. "name":"代码专家",
  36. "model":{"primary":"dashscope/qwen3-coder-plus"},
  37. "subagents":{"thinking":"on"}
  38. },
  39. {
  40. "id":"coder-fast",
  41. "name":"快速代码助手",
  42. "model":{"primary":"dashscope/qwen3-coder-next"},
  43. "subagents":{"thinking":"off"}
  44. },
  45. {
  46. "id":"vision",
  47. "name":"视觉分析专家",
  48. "model":{"primary":"dashscope/qwen3-vl-plus"},
  49. "subagents":{"thinking":"off"}
  50. },
  51. {
  52. "id":"long-context",
  53. "name":"长文本专家",
  54. "model":{"primary":"dashscope/glm-5"},
  55. "subagents":{"thinking":"off"}
  56. },
  57. {
  58. "id":"creative",
  59. "name":"创意写作专家",
  60. "model":{"primary":"dashscope/kimi-k2.5"},
  61. "subagents":{"thinking":"off"}
  62. },
  63. {
  64. "id":"reasoning",
  65. "name":"逻辑推理专家",
  66. "model":{"primary":"dashscope/MiniMax-M2.5"},
  67. "subagents":{"thinking":"on"}
  68. },
  69. {
  70. "id":"data-analyst",
  71. "name":"数据分析专家",
  72. "model":{"primary":"dashscope/qwen3.5-plus"},
  73. "subagents":{"thinking":"on"}
  74. },
  75. {
  76. "id":"investment-advisor",
  77. "name":"投资分析顾问",
  78. "model":{"primary":"dashscope/qwen3.5-plus"},
  79. "subagents":{"thinking":"on"}
  80. },
  81. {
  82. "id":"research-assistant",
  83. "name":"研究助理",
  84. "model":{"primary":"dashscope/glm-4.7"},
  85. "subagents":{"thinking":"off"}
  86. },
  87. {
  88. "id":"image-gen",
  89. "name":"图像生成专家",
  90. "model":{"primary":"dashscope/wan2.6-t2i"},
  91. "subagents":{"thinking":"off"}
  92. }
  93. ]
  94. }
  95. }

⚙️ 配置说明

模型选择逻辑

Agent
模型
为什么选它
main
qwen3.5-plus
综合能力最强,适合协调
coder
qwen3-coder-plus
专门优化代码生成
coder-fast
qwen3-coder-next
响应快,适合简单任务
vision
qwen3-vl-plus
视觉识别能力强
long-context
glm-5
超长上下文支持
creative
kimi-k2.5
创意写作优秀
reasoning
MiniMax-M2.5
逻辑推理能力强
data-analyst
qwen3.5-plus
数据分析够用
investment-advisor
qwen3.5-plus
投资分析综合能力强
research-assistant
glm-4.7
信息检索准确
image-gen
wan2.6-t2i
图像生成专用

Thinking 模式

  • thinking: on
    - 启用推理模式,适合复杂任务(coder、reasoning、data-analyst、investment-advisor)
  • thinking: off
    - 快速响应,适合简单任务(main、vision、creative 等)

🚀 第四步:验证配置

检查语法

  1. # 验证 JSON 语法
  2. cat ~/.openclaw/openclaw.json | jq .

如果输出正常 JSON,说明语法没问题。

重启服务

  1. openclaw gateway restart

检查状态

  1. openclaw gateway status

看到 Runtime: running就说明成功了。


💡 第五步:使用多 Agent

方式 1:对话中直接调用

在消息前加 /agent-id

  1. /coder 帮我写一个Python爬虫
  2. /vision 分析这张图片
  3. /creative 写一篇关于 AI 的文章
  4. /investment-advisor 分析贵州茅台股票
  5. /coder-fast 写个HelloWorld函数

方式 2:使用 sessions_spawn

  1. // 创建代码专家 agent
  2. sessions_spawn({
  3.   task:"帮我写一个 Web 爬虫",
  4.   agentId:"coder",
  5.   runtime:"subagent",
  6.   mode:"run"
  7. })
  8. // 创建投资顾问 agent
  9. sessions_spawn({
  10.   task:"分析宁德时代股票",
  11.   agentId:"investment-advisor",
  12.   runtime:"subagent",
  13.   mode:"run"
  14. })

方式 3:自动协作(高级)

复杂任务会自动协调多个 agent:

  1. 用户:帮我做一个股票分析系统
  2. 自动协调流程:
  3. 1. investment-advisor 提供分析逻辑
  4. 2. coder 编写代码实现
  5. 3. data-analyst 设计数据可视化
  6. 4.汇总完整系统

📊 实际使用案例

案例 1:写代码 + 写文档

  1. 任务:帮我写一个股票数据爬虫,并写使用说明
  2. 分配:
  3. - coder 编写爬虫代码
  4. - creative 撰写使用文档
  5. - main 汇总整理

案例 2:投资分析报告

  1. 任务:写一篇新能源板块投资分析报告
  2. 分配:
  3. - research-assistant 收集行业数据
  4. - investment-advisor 分析投资逻辑
  5. - creative 优化文章表达
  6. - main 汇总整理

案例 3:图片 + 数据分析

  1. 任务:分析这张财务报表图片
  2. 分配:
  3. - vision 识别图片内容
  4. - data-analyst 分析财务数据
  5. - main 汇总建议

⚠️ 常见问题

问题 1:配置后服务启动失败

原因:JSON 语法错误

解决

  1. # 验证语法
  2. cat ~/.openclaw/openclaw.json | jq .
  3. # 恢复备份
  4. cp ~/.openclaw/openclaw.json.backup.*~/.openclaw/openclaw.json

问题 2:Agent 调用失败

原因:模型未开通或 API Key 问题

解决

  1. # 检查模型配置
  2. cat ~/.openclaw/openclaw.json | grep -5"models"
  3. # 测试模型
  4. openclaw models test qwen3.5-plus

问题 3:Thinking 模式不生效

原因:某些模型不支持 thinking

解决

  • qwen3-coder-plus 支持 thinking
  • qwen3-coder-next 不支持 thinking(设为 off)
  • 检查模型文档确认支持情况

🎯 优化建议

根据使用频率调整

如果你经常写代码:

  1. {
  2. "id":"coder",
  3. "model":{"primary":"dashscope/qwen3-coder-plus"},
  4. "subagents":{"thinking":"on"}
  5. }

如果你经常分析图片:

  1. {
  2. "id":"vision",
  3. "model":{"primary":"dashscope/qwen3-vl-plus"},
  4. "subagents":{"thinking":"off"}
  5. }

成本优化

便宜模型组合:

  • 简单任务 → glm-4.7(便宜)
  • 代码任务 → qwen3-coder-next(快速)
  • 复杂任务 → qwen3.5-plus(均衡)

📖 进阶配置

自定义 Agent

添加你自己的专用 agent:

  1. {
  2. "id":"my-custom-agent",
  3. "name":"我的专用助手",
  4. "model":{"primary":"dashscope/qwen3.5-plus"},
  5. "subagents":{"thinking":"off"}
  6. }

调整默认模型

  1. {
  2. "defaults":{
  3. "model":{
  4. "primary":"dashscope/glm-4.7"//改成默认用 glm
  5. }
  6. }
  7. }

📞 故障排查

查看日志

  1. # 查看网关日志
  2. openclaw gateway logs
  3. # 查看实时日志
  4. tail -/tmp/openclaw/openclaw-*.log

检查 Agent 列表

  1. # 列出所有 agent
  2. openclaw agents list

测试特定 Agent

  1. # 测试 coder agent
  2. openclaw agents test coder "写个 Hello World"

✅ 配置完成检查清单

  • 备份原配置
  • 编辑 openclaw.json
  • 验证 JSON 语法(jq .)
  • 重启服务(openclaw gateway restart)
  • 检查服务状态(openclaw gateway status)
  • 测试调用 agent(/coder 测试)
  • 确认日志无错误

📚 相关资源

  • OpenClaw 官方文档
    : https://docs.openclaw.ai
  • 模型配置指南
    : ~/.openclaw/workspace/docs/
  • 配置备份
    : ~/.openclaw/openclaw.json.backup.*

🎉 总结

配置多 Agent 就 5 步:

  1. 备份
    - 防止配错
  2. 编辑
    - 添加 agent 配置
  3. 验证
    - 检查 JSON 语法
  4. 重启
    - 应用配置
  5. 测试
    - 调用 agent 确认

配置完成后,你就可以:

  • 用 /coder写代码
  • 用 /creative写文章
  • 用 /vision分析图片
  • 用 /investment-advisor分析股票

专人专事,效率翻倍!


配置时间: 2026-03-27OpenClaw 版本: 2026.3.23-2配置状态: ✅ 亲测可用


互动:

你配置了哪些 Agent?有什么使用心得?

欢迎交流~