ClawWork - AI 外包工作者
约 1181 字大约 4 分钟
2026-03-07
AI 外包工作者,采用动态有向无环图(DAG)架构,将任务拆分为 Planner、Coder、Reviewer 多个节点协同完成。
核心特性
DAG 工作流
- 动态有向无环图架构
- 任务自动拆分
- 节点并行执行
- 依赖关系管理
多角色协同
- Planner: 任务规划
- Coder: 代码实现
- Reviewer: 代码审查
- Tester: 测试验证
- 每个角色可使用不同模型
目标导向
- 完整交付成果
- 质量保证机制
- 自动化测试
- 文档生成
灵活配置
- 自定义工作流
- 节点策略配置
- 模型选择
- 重试机制
快速开始
安装
# 克隆仓库
git clone https://github.com/HKUDS/ClawWork.git
cd ClawWork
# 安装依赖
pip install -r requirements.txt
# 配置环境变量
cp .env.example .env
# 编辑 .env 文件配置
创建 workflow.yaml:
workflow:
name: "web-app-development"
# 定义节点
nodes:
- id: planner
type: planner
model: claude-3-5-sonnet-20241022
prompt_template: "planning.txt"
- id: architect
type: architect
model: claude-3-5-sonnet-20241022
depends_on: [planner]
- id: frontend_coder
type: coder
model: claude-3-5-sonnet-20241022
depends_on: [architect]
context: "frontend"
- id: backend_coder
type: coder
model: claude-3-5-sonnet-20241022
depends_on: [architect]
context: "backend"
- id: reviewer
type: reviewer
model: claude-3-5-sonnet-20241022
depends_on: [frontend_coder, backend_coder]
- id: tester
type: tester
model: claude-3-5-sonnet-20241022
depends_on: [reviewer]
# 交付物
deliverables:
- type: code
path: "./output/src"
- type: documentation
path: "./output/docs"
- type: tests
path: "./output/tests"
# 质量标准
quality:
min_test_coverage: 80
max_complexity: 10
code_style: "pep8"运行
# 执行工作流
python clawwork.py --workflow workflow.yaml --task "开发一个待办事项 Web 应用"
# 查看进度
python clawwork.py --status
# 查看结果
ls output/技术架构
DAG 架构
┌─────────────────────────────────────────┐
│ ClawWork Engine │
│ │
│ ┌───────────────────────────────────┐ │
│ │ DAG Scheduler │ │
│ │ - Topological Sort │ │
│ │ - Parallel Execution │ │
│ │ - Dependency Resolution │ │
│ └───────────────────────────────────┘ │
│ ↓ │
│ ┌───────────────────────────────────┐ │
│ │ Node Executor │ │
│ │ - LLM Invocation │ │
│ │ - Context Management │ │
│ │ - Result Validation │ │
│ └───────────────────────────────────┘ │
│ ↓ │
│ ┌───────────────────────────────────┐ │
│ │ Deliverable Manager │ │
│ │ - Code Generation │ │
│ │ - Documentation │ │
│ │ - Quality Check │ │
│ └───────────────────────────────────┘ │
└─────────────────────────────────────────┘工作流示例
┌─────────┐
│ Planner │
└────┬────┘
│
↓
┌─────────┐
│Architect│
└────┬────┘
│
┌────┴────┐
↓ ↓
┌─────────┐ ┌─────────┐
│Frontend │ │Backend │
│ Coder │ │ Coder │
└────┬────┘ └────┬────┘
└────┬──────┘
↓
┌─────────┐
│Reviewer │
└────┬────┘
↓
┌─────────┐
│ Tester │
└─────────┘核心技术栈
- 语言: Python 3.9+
- DAG 引擎: NetworkX
- 异步: asyncio
- LLM: 多模型支持
使用示例
基本使用
from clawwork import ClawWork, Workflow
# 创建工作流
workflow = Workflow.from_yaml("workflow.yaml")
# 初始化 ClawWork
cw = ClawWork(workflow)
# 执行任务
result = cw.execute(
task="开发一个博客系统",
requirements=[
"用户注册登录",
"文章发布编辑",
"评论功能",
"响应式设计"
]
)
# 获取交付物
print(f"代码路径: {result.code_path}")
print(f"文档路径: {result.docs_path}")
print(f"测试覆盖率: {result.test_coverage}%")自定义节点
from clawwork import Node
class CustomNode(Node):
def __init__(self, config):
super().__init__(config)
async def execute(self, context):
# 自定义逻辑
prompt = self.build_prompt(context)
result = await self.llm.generate(prompt)
# 验证结果
if not self.validate(result):
raise ValueError("结果不符合要求")
return result
def validate(self, result):
# 自定义验证逻辑
return True
# 注册自定义节点
workflow.register_node_type("custom", CustomNode)并行执行
# 配置并行节点
workflow = Workflow()
workflow.add_node("task1", parallel_group="group_a")
workflow.add_node("task2", parallel_group="group_a")
workflow.add_node("task3", parallel_group="group_a")
# 这三个任务会并行执行
result = cw.execute("任务描述")高级功能
增量开发
# 基于已有代码继续开发
result = cw.execute(
task="添加用户权限管理功能",
base_code="./existing_project",
incremental=True
)质量检查
quality:
# 代码质量
code_style: "pep8"
max_complexity: 10
max_line_length: 100
# 测试要求
min_test_coverage: 80
required_tests:
- unit
- integration
# 文档要求
docstring_coverage: 90
readme_required: true
api_docs_required: true重试机制
nodes:
- id: coder
type: coder
retry:
max_attempts: 3
backoff: exponential
on_failure: "reviewer" # 失败后交给 reviewer成本优化
nodes:
# 规划使用强模型
- id: planner
model: claude-3-5-sonnet-20241022
# 编码使用中等模型
- id: coder
model: claude-3-haiku-20240307
# 审查使用强模型
- id: reviewer
model: claude-3-5-sonnet-20241022性能指标
| 指标 | 数值 |
|---|---|
| 小型项目交付时间 | 10-30 分钟 |
| 中型项目交付时间 | 1-3 小时 |
| 代码质量评分 | 85+ |
| 测试覆盖率 | 80%+ |
| 文档完整度 | 90%+ |
适用场景
推荐使用
- 承接外包代码开发
- 长链条独立项目交付
- 需要完整交付成果的任务
- 多人协作模拟
- 快速原型开发
- 代码重构项目
不推荐使用
- 简单的单文件脚本
- 需要人工创意的设计工作
- 实时交互场景
- 探索性编程
项目模板
ClawWork 提供多种项目模板:
Web 应用模板
clawwork create --template web-app --name my-app
# 包含:前端、后端、数据库、部署配置API 服务模板
clawwork create --template api-service --name my-api
# 包含:RESTful API、文档、测试、Docker数据分析模板
clawwork create --template data-analysis --name my-analysis
# 包含:数据处理、可视化、报告生成相关链接
- GitHub: HKUDS/ClawWork
- 文档: 使用文档
- 示例项目: Examples
- 问题反馈: Issues
贡献
欢迎贡献代码、报告问题或提出建议!
# 克隆仓库
git clone https://github.com/HKUDS/ClawWork.git
# 安装开发依赖
cd ClawWork
pip install -r requirements-dev.txt
# 运行测试
pytest tests/
# 运行示例
python examples/web_app_example.py许可证
MIT License - 详见 LICENSE