加入我们的 Telegram 社群 (clawdbotCN) 学习分享和了解更多 →
核心概念
多代理路由

多代理路由

Clawdbot 支持运行多个独立的 AI 代理,每个代理都有自己的工作空间、会话和配置。

什么是代理?

代理 (Agent) 是一个完全隔离的 AI 人格,拥有:

  • 独立的工作空间 (文件、个性规则)
  • 独立的状态目录 (agentDir)
  • 独立的会话存储
  • 独立的认证配置

核心概念

代理隔离

每个代理读取自己的配置:

~/.clawdbot/agents/<agentId>/
├── sessions/           # 会话存储
├── auth-profiles.json  # 认证配置
└── workspace/          # 工作空间

重要: 凭据不会在代理之间自动共享。

路由机制

消息通过 绑定规则 (bindings) 确定路由到哪个代理:

  1. 对等 ID (最具体)
  2. 群组/团队 ID
  3. 账号 ID
  4. 渠道级匹配
  5. 默认代理回退

配置多代理

添加代理

使用向导添加新代理:

clawdbot agents add work

配置文件

{
  agents: {
    // 默认代理
    default: {
      workspace: "~/clawd",
      sandbox: "host"
    },
 
    // 工作代理
    work: {
      workspace: "~/clawd-work",
      sandbox: "docker",
      tools: {
        restricted: ["browser", "shell"]
      }
    },
 
    // 个人代理
    personal: {
      workspace: "~/clawd-personal",
      sandbox: "host"
    }
  }
}

绑定规则

配置哪些渠道/账号映射到哪个代理:

{
  bindings: [
    // Telegram 消息路由到工作代理
    {
      match: { channel: "telegram" },
      agent: "work"
    },
 
    // 特定 WhatsApp 号码路由到个人代理
    {
      match: {
        channel: "whatsapp",
        peer: "+15551234567"
      },
      agent: "personal"
    },
 
    // Discord 特定服务器
    {
      match: {
        channel: "discord",
        guild: "123456789"
      },
      agent: "work"
    }
  ]
}

代理设置

工作空间

每个代理可以有独立的工作空间:

{
  agents: {
    work: {
      workspace: "~/work-projects",
      // 只允许访问工作目录
      workspacePolicy: "strict"
    }
  }
}

沙箱模式

控制代理的隔离级别:

{
  agents: {
    untrusted: {
      sandbox: "docker",
      // Docker 沙箱配置
      sandboxConfig: {
        image: "clawdbot/sandbox:latest",
        memory: "2g",
        cpus: 2
      }
    }
  }
}

工具限制

限制代理可以使用的工具:

{
  agents: {
    limited: {
      tools: {
        // 禁用某些工具
        disabled: ["shell", "browser"],
        // 或只允许某些工具
        allowed: ["search", "calculator"]
      }
    }
  }
}

命令参考

# 列出所有代理
clawdbot agents list
 
# 添加新代理
clawdbot agents add <name>
 
# 删除代理
clawdbot agents remove <name>
 
# 切换默认代理
clawdbot agents default <name>

使用场景

工作/个人分离

{
  bindings: [
    { match: { channel: "slack" }, agent: "work" },
    { match: { channel: "whatsapp" }, agent: "personal" }
  ]
}

多语言支持

{
  agents: {
    chinese: {
      personality: "用中文回复"
    },
    english: {
      personality: "Reply in English"
    }
  }
}

安全分级

{
  agents: {
    admin: {
      sandbox: "host",
      tools: { allowed: ["*"] }
    },
    public: {
      sandbox: "docker",
      tools: { disabled: ["shell", "browser"] }
    }
  }
}

下一步