# EdgeClaw **Repository Path**: chx-root/EdgeClaw ## Basic Information - **Project Name**: EdgeClaw - **Description**: No description available - **Primary Language**: Unknown - **License**: MIT - **Default Branch**: main - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2026-03-19 - **Last Updated**: 2026-03-19 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README
端云协同的AI智能体
EdgeClaw:让敏感数据绝不上云,让便宜模型承担 80% 请求
【中文 | English】
--- **最新动态** 🔥 - **[2026.03.13]** 🎉 EdgeClaw 新增成本感知协同:自动判断任务复杂度,为云端匹配最经济的模型 - **[2026.02.12]** 🎉 EdgeClaw 正式开源,端云协同 AI 智能体 --- ## 💡 关于 EdgeClaw EdgeClaw 是一个**端云协同的 AI 智能体**,由 [THUNLP(清华大学)](https://nlp.csai.tsinghua.edu.cn)、[中国人民大学](http://ai.ruc.edu.cn/)、[AI9Stars](https://github.com/AI9Stars)、[面壁智能(ModelBest)](https://modelbest.cn/en) 和 [OpenBMB](https://www.openbmb.cn/home) 联合开发,构建于 [OpenClaw](https://github.com/openclaw/openclaw) 之上。 当下 AI Agent 架构中,端侧长期被忽视——所有数据与任务一股脑涌向云端,隐私泄露与算力浪费由此而生。EdgeClaw 重新激活端侧的价值,构建可自定义的三级安全体系(S1 直通 / S2 脱敏 / S3 本地),通过端侧双引擎(规则检测 ~0ms + 本地 LLM 语义检测 ~1-2s)实时判别每条请求的敏感度与复杂度,再经统一可组合管线,将其转发至隐私安全与性价比最合适的处理路径。配合端云协同的智能转发能力,开发者无需修改业务逻辑,即可在 EdgeClaw 中实现“公开数据上云、敏感数据脱敏、私密数据落地”的无感端云协同隐私保护与性价比节省。
| **🤝 端云各有分工** 端侧负责感知数据属性(敏感度、复杂度),云端负责推理和生成。端侧补云端的盲区(敏感数据不上云),云端补端侧的短板(做不了的复杂任务交给云)。 | **🔒 三级安全协同模式** 安全数据(S1)——直接上云;敏感数据(S2)——端侧脱敏后转发云端推理;私密数据(S3)——端侧独立处理,云端仅维持上下文连贯。 |
| **💰 性价比感知协同** 本地 LLM 语义判断任务复杂度,简单任务转发到便宜模型,只在复杂任务上用贵模型。典型工作流下 60–80% 的请求被转发到低价模型,大幅削减云端 token 开支。 | **🚀 即插即用,一行不改** EdgeClaw 通过 Hook 机制自动拦截和转发,无需修改任何业务逻辑代码,可无缝替换 OpenClaw。 |
∀ x, Detect(x) = S₃ ⟹ x ∉ Cloud(x)
**定理 2(脱敏完整性)**:对任意 S2 级数据 _x_,其云侧可见形式不包含原始隐私实体值:∀ x, Detect(x) = S₂ ⟹ ∀ (ti, vi) ∈ Extract(x), vi ∉ Cloud(x)
--- ## 💰 功能二:性价比感知协同 ### 为什么需要性价比感知协同? 在典型的 AI 编程助手工作流中,大部分请求是查文件、看代码、简单问答——用最贵的模型处理这些任务纯属浪费。性价比感知协同用本地小模型做 LLM-as-Judge,把请求按复杂度分级转发到不同价位的云侧模型。 | 复杂度 | 任务示例 | 默认目标模型 | | ------------- | -------------------------------- | ------------------- | | **SIMPLE** | 查询、翻译、格式化、打招呼 | `gpt-4o-mini` | | **MEDIUM** | 代码生成、单文件编辑、邮件撰写 | `gpt-4o` | | **COMPLEX** | 系统设计、多文件重构、跨文档分析 | `claude-sonnet-4.6` | | **REASONING** | 数学证明、形式逻辑、实验设计 | `o4-mini` | ### 为什么用 LLM-as-Judge 而不用关键词规则? | 方案 | 优点 | 缺点 | | ---------------- | ------------------------ | --------------------------- | | 关键词规则 | 快 | 不理解语义,误判率高 | | **LLM-as-Judge** | **理解语义,多语言通用** | 多一次本地模型调用(~1-2s) | Judge 跑在本地小模型上(如 MiniCPM-4.1 / Qwen3.5),延迟约 1-2 秒。 ### 智能缓存 Prompt 哈希缓存(SHA-256,TTL 5 分钟),相同请求不重复 Judge,进一步降低延迟开销。 ### 省多少? 以典型编程助手工作流为例,、性价比感知路由可将 **60–80% 的请求** 转发到更便宜的模型。 --- ## 🚀 可组合路由管线 安全协同和性价比感知协同运行在**同一管线**中,通过权重和两阶段短路策略协同工作: ``` User Message │ ▼ RouterPipeline.run() │ ├── Phase 1: 快速路由器 (weight ≥ 50) 并行执行 │ └── security router → 三级灵敏度检测 │ ├── 短路判断: 若 Phase 1 发现敏感数据 → 跳过 Phase 2 │ └── Phase 2: 慢速路由器 (weight < 50) 按需执行 └── cost-aware router → LLM Judge 任务复杂度分类 ``` **设计哲学**:安全优先——安全路由器高权重先跑,有敏感数据就直接短路处理,不浪费时间再判断复杂度。只有安全通过(S1)后,才启动性价比感知协同优化成本。 ### 端到端管线形式化 ``` ⎧ θ_cloud(m) if a = passthrough m ─[c_msg]→ Detect(m) → l ─[c_route]→ R(l) → a → ⎨ θ_cloud(De(m)) if a = desensitize ⎩ θ_local(m) if a = redirect ─[c_persist]→ W(m, l) ─[c_end]→ Sync ``` ### 10 个 Hook 覆盖完整生命周期 | Hook | 触发时机 | 核心职责 | | ---------------------- | ------------- | --------------------------- | | `before_model_resolve` | 模型选择前 | 运行管线 → 路由决策 | | `before_prompt_build` | Prompt 构建前 | 注入 Guard Prompt / S2 标记 | | `before_tool_call` | 工具调用前 | 文件访问守卫 + 子代理守卫 | | `after_tool_call` | 工具调用后 | 工具结果检测 | | `tool_result_persist` | 结果持久化 | 双轨会话写入 | | `before_message_write` | 消息写入前 | S3→占位符, S2→脱敏版 | | `session_end` | 会话结束 | 记忆同步 | | `message_sending` | 出站消息 | 检测并脱敏/取消 | | `before_agent_start` | 子代理启动前 | 任务内容守卫 | | `message_received` | 收到消息 | 观察性日志 | --- ## 📦 安装 我们提供两种安装方式:源码安装(推荐)和本地 LLM 环境配置。 ### 方式一:源码安装 ```bash git clone https://github.com/openbmb/edgeclaw.git cd edgeclaw pnpm install pnpm build pnpm ui:build pnpm openclaw onboard --install-daemon ``` ### 方式二:本地 LLM 环境 EdgeClaw 需要一个本地推理后端用于隐私检测和 Guard Agent。推荐 Ollama: ```bash # macOS brew install ollama # Linux curl -fsSL https://ollama.ai/install.sh | sh # 拉取推荐模型 ollama pull openbmb/minicpm4.1 # 启动服务 ollama serve ``` 也支持 vLLM、LMStudio、SGLang、TGI 等所有 OpenAI 兼容 API。详见 `config.example.json` 中的各后端配置示例。 ### 验证安装 ```bash pnpm openclaw gateway run ``` 如果看到 GuardClaw 插件加载日志,说明安装成功。 --- ## 🚀 快速开始 ### 1. 启用 GuardClaw 插件 在 `openclaw.json` 中添加: ```json { "plugins": { "entries": { "GuardClaw": { "enabled": true, "config": { "privacy": { "enabled": true, "localModel": { "enabled": true, "provider": "ollama", "model": "openbmb/minicpm4.1", "endpoint": "http://localhost:11434" }, "guardAgent": { "id": "guard", "workspace": "~/.openclaw/workspace-guard", "model": "ollama/openbmb/minicpm4.1" } } } } } } } ``` ### 2. 配置 Guard Agent 在 `openclaw.json` 的 `agents` 中注册 Guard Agent: ```json { "agents": { "list": [ { "id": "main", "workspace": "~/.openclaw/workspace-main", "subagents": { "allowAgents": ["guard"] } }, { "id": "guard", "workspace": "~/.openclaw/workspace-guard", "model": "ollama/openbmb/minicpm4.1" } ] } } ``` ### 3. 启动 ```bash pnpm openclaw gateway run ``` EdgeClaw 自动拦截和转发,无需修改任何业务逻辑。 ### 4.(可选)启用 性价比感知路由 在 `privacy.routers` 中开启: ```json { "privacy": { "routers": { "token-saver": { "enabled": true, "weight": 30, "options": { "tiers": { "SIMPLE": { "provider": "openai", "model": "gpt-4o-mini" }, "MEDIUM": { "provider": "openai", "model": "gpt-4o" }, "COMPLEX": { "provider": "anthropic", "model": "claude-sonnet-4.6" }, "REASONING": { "provider": "openai", "model": "o4-mini" } } } } } } } ``` --- ## 🎬 Demo --- ## 🔧 自定义配置 ### 检测规则自定义 ```json { "privacy": { "rules": { "keywords": { "S2": ["password", "api_key", "token"], "S3": ["ssh", "id_rsa", "private_key", ".pem"] }, "patterns": { "S2": ["(?:mysql|postgres|mongodb)://[^\\s]+"], "S3": ["-----BEGIN (?:RSA |EC )?PRIVATE KEY-----"] }, "tools": { "S2": { "tools": ["exec", "shell"], "paths": ["~/secrets"] }, "S3": { "tools": ["sudo"], "paths": ["~/.ssh", "~/.aws"] } } } } } ``` ### 检测器组合 ```json { "privacy": { "checkpoints": { "onUserMessage": ["ruleDetector", "localModelDetector"], "onToolCallProposed": ["ruleDetector"], "onToolCallExecuted": ["ruleDetector"] } } } ``` ### 自定义路由器 EdgeClaw 协同管线完全可扩展,实现 `GuardClawRouter` 接口即可注入自定义协同逻辑: ```typescript const myRouter: GuardClawRouter = { id: "content-filter", async detect(context, pluginConfig): Promise