构建"问题收集→Git 定位→代码修复→测试→部署"全流程自动化 Bug 解决助理
5 个专业智能体各司其职,通过 OpenClaw 编排引擎实现高效协作,覆盖 Bug 修复全流程
20+ 个可复用 Skills,支持灵活组合,形成完整的技能图谱,满足各种修复场景
每个智能体具备完整的认知循环,能够感知环境、执行动作、反思结果并持续优化
所有代码修复和测试在隔离沙箱中执行,确保生产环境安全,支持快速回滚
每个操作都有完整日志和追踪,支持事后审计、问题回溯、责任认定
标准化的流程设计,支持快速复制到其他项目,降低部署成本
┌─────────────────────────────────────────────────────────────────────────────┐
│ 问题收集层 │
│ ┌──────────────┐ ┌──────────────┐ ┌──────────────┐ ┌──────────────┐ │
│ │ Web 控制台 │ │ Slack/钉钉 │ │ 邮件系统 │ │ 监控系统 │ │
│ │ │ │ │ │ │ │ │ │
│ │ - 手动提交 │ │ - Bot 命令 │ │ - 邮件监听 │ │ - Prometheus│ │
│ │ - 日志上传 │ │ - 消息捕获 │ │ - 附件解析 │ │ - ELK │ │
│ │ - 进度查询 │ │ - 线程讨论 │ │ - 自动分类 │ │ - APM │ │
│ └──────────────┘ └──────────────┘ └──────────────┘ └──────────────┘ │
│ │ │
│ ┌──────────────┐ ┌──────────────┐ │
│ │ API 接口 │ │ Git Hook │ │
│ │ │ │ │ │
│ │ - RESTful │ │ - CI 失败 │ │
│ │ - Webhook │ │ - 测试失败 │ │
│ └──────────────┘ └──────────────┘ │
└─────────────────────────────────────────────────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────────────────────────────┐
│ OpenClaw 智能体编排层 │
│ ┌───────────────────────────────────────────────────────────────────────┐ │
│ │ Coordinator Agent │ │
│ │ ┌─────────────────────────────────────────────────────────────────┐ │ │
│ │ │ 工作流引擎 & 状态管理 │ │ │
│ │ │ - 任务分发 - 进度追踪 - 决策引擎 - 异常处理 │ │ │
│ │ └─────────────────────────────────────────────────────────────────┘ │ │
│ └───────────────────────────────────────────────────────────────────────┘ │
│ │
│ ┌────────────┐ ┌────────────┐ ┌────────────┐ ┌────────────┐ ┌────────┐│
│ │ Collector │ │ Locator │ │ Fixer │ │ Tester │ │Deployer││
│ │ Agent │ │ Agent │ │ Agent │ │ Agent │ │ Agent ││
│ │ │ │ │ │ │ │ │ │ ││
│ │ - 问题接收 │ │ - Git 定位 │ │ - 代码修复 │ │ - 测试验证 │ │ - 部署 ││
│ │ - 分类排序 │ │ - 根因分析 │ │ - 方案生成 │ │ - 回归测试 │ │ - 发布 ││
│ │ - 工单创建 │ │ - 责任归属 │ │ - 分支管理 │ │ - 质量门禁 │ │ - 回滚 ││
│ └────────────┘ └────────────┘ └────────────┘ └────────────┘ └────────┘│
│ │
│ ┌───────────────────────────────────────────────────────────────────────┐ │
│ │ Skill Chain 引擎 │ │
│ │ 20+ Skills: git_blame, code_analyze, fix_generate, test_run... │ │
│ └───────────────────────────────────────────────────────────────────────┘ │
└─────────────────────────────────────────────────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────────────────────────────┐
│ 执行层 │
│ ┌──────────────┐ ┌──────────────┐ ┌──────────────┐ ┌──────────────┐ │
│ │ Git │ │ Docker │ │ Jenkins │ │ K8s │ │
│ │ │ │ │ │ │ │ │ │
│ │ - 代码仓库 │ │ - 沙箱环境 │ │ - CI/CD │ │ - 容器编排 │ │
│ │ - 分支管理 │ │ - 隔离执行 │ │ - 流水线 │ │ - 服务部署 │ │
│ │ - Code │ │ - 资源限制 │ │ - 质量门禁 │ │ - 灰度发布 │ │
│ │ Review │ │ - 自动清理 │ │ - 部署发布 │ │ - 监控告警 │ │
│ └──────────────┘ └──────────────┘ └──────────────┘ └──────────────┘ │
└─────────────────────────────────────────────────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────────────────────────────┐
│ 数据层 │
│ ┌──────────────┐ ┌──────────────┐ ┌──────────────┐ ┌──────────────┐ │
│ │ PostgreSQL │ │ Redis │ │ MinIO │ │ Elasticsearch│ │
│ │ │ │ │ │ │ │ │ │
│ │ - Bug 工单 │ │ - 缓存层 │ │ - 文件存储 │ │ - 日志检索 │ │
│ │ - 执行记录 │ │ - 会话存储 │ │ - 镜像存储 │ │ - 全文搜索 │ │
│ │ - 审计日志 │ │ - 分布式锁 │ │ - 备份归档 │ │ - 数据分析 │ │
│ └──────────────┘ └──────────────┘ └──────────────┘ └──────────────┘ │
└─────────────────────────────────────────────────────────────────────────────┘
每个智能体专注单一职责,通过明确定义的接口协作,降低耦合度,提高可维护性
每个智能体都具备"感知 - 执行 - 反思"能力,能够根据执行结果调整策略,持续优化
所有代码执行在 Docker 沙箱中进行,与生产环境完全隔离,确保系统安全
每个操作都有详细日志,支持全链路追踪,满足合规要求和责任追溯
问题收集智能体
问题定位智能体
代码修复智能体
测试验证智能体
部署发布智能体
class CollectorAgent(BaseAgent): """问题收集智能体 - 负责接收、分类、优先级排序 Bug 反馈""" def __init__(self, config): super().__init__( name="CollectorAgent", skills=[ ReceiveBugSkill(), ClassifyBugSkill(), PrioritizeBugSkill(), CreateTicketSkill() ] ) async def perceive(self, context): """感知:从多渠道收集 Bug 信息""" bug_reports = [] # 从各渠道收集 for channel in ["web", "slack", "email", "monitor"]: reports = await self.skills.receive_bug.execute(channel) bug_reports.extend(reports) return bug_reports async def execute(self, bug_reports): """执行:分类、优先级排序、创建工单""" tickets = [] for report in bug_reports: # 分类 category = await self.skills.classify.execute(report) # 优先级评估 priority = await self.skills.prioritize.execute( report, category ) # 创建工单 ticket = await self.skills.create_ticket.execute( report, category, priority ) tickets.append(ticket) return tickets async def reflect(self, tickets): """反思:评估收集效果,优化分类规则""" for ticket in tickets: if ticket.category_confidence < 0.7: # 低置信度,需要优化分类模型 await self.optimize_classifier(ticket) # 记录指标 await self.metrics.record("bug_collected", 1)
class LocatorAgent(BaseAgent): """问题定位智能体 - 负责 Git 定位、根因分析、责任归属""" def __init__(self, config): super().__init__( name="LocatorAgent", skills=[ GitBlameSkill(), AnalyzeLogSkill(), RootCauseSkill(), ImpactAnalysisSkill(), CodeOwnershipSkill() ] ) async def perceive(self, ticket): """感知:收集错误信息、日志、堆栈""" error_info = { "stack_trace": ticket.stack_trace, "error_logs": await self.search_logs(ticket), "recent_changes": await self.get_recent_commits(ticket), "affected_files": ticket.affected_files } return error_info async def execute(self, error_info): """执行:Git 定位、根因分析、责任归属""" # Git Blame 分析代码归属 ownership = await self.skills.code_ownership.execute( error_info.affected_files ) # 根因分析 root_cause = await self.skills.root_cause.execute( error_info.stack_trace, error_info.error_logs ) # 影响范围分析 impact = await self.skills.impact_analysis.execute( root_cause.affected_module ) return LocalizationResult( root_cause=root_cause, ownership=ownership, impact=impact, confidence=root_cause.confidence ) async def reflect(self, result): """反思:评估定位准确性,优化分析模型""" if result.confidence < 0.8: # 低置信度,标记需要人工介入 await self.flag_for_human_review(result) # 记录定位指标 await self.metrics.record("location_accuracy", result.confidence)
class FixerAgent(BaseAgent): """代码修复智能体 - 负责分析代码、生成修复方案、提交代码""" def __init__(self, config): super().__init__( name="FixerAgent", skills=[ CodeAnalyzeSkill(), FixGenerateSkill(), BranchCreateSkill(), CommitCodeSkill(), CreatePRSkill() ], llm_provider="claude-code" ) async def perceive(self, localization): """感知:获取定位结果、相关代码""" code_context = await self.get_code_context( localization.root_cause.file_path, localization.root_cause.line_number ) return { "root_cause": localization.root_cause, "code_context": code_context, "similar_bugs": await self.search_similar_bugs() } async def execute(self, context): """执行:生成修复方案、创建分支、提交代码""" # 使用 Claude Code 分析并生成修复方案 fix_plan = await self.skills.fix_generate.execute( context.root_cause, context.code_context, context.similar_bugs ) # 生成多个候选方案 candidates = await self.generate_multiple_fixes(fix_plan) # 选择最优方案 best_fix = await self.select_best_fix(candidates) # 创建修复分支 branch = await self.skills.branch_create.execute( ticket_id=context.root_cause.ticket_id ) # 提交修复代码 commit = await self.skills.commit_code.execute( branch=branch, fix=best_fix, message=f"fix: {context.root_cause.description}" ) return FixResult( fix=best_fix, branch=branch, commit=commit, candidates=candidates ) async def reflect(self, result): """反思:评估修复质量,优化生成模型""" # 记录修复方案质量 await self.metrics.record("fix_quality", result.fix.quality_score) # 如果质量低,收集反馈用于模型优化 if result.fix.quality_score < 0.7: await self.collect_feedback_for_training(result)
class BaseSkill(ABC): """Skill 基类 - 所有 Skills 的抽象""" def __init__(self, name, description): self.name = name self.description = description self.metrics = SkillMetrics() @abstractmethod async def execute(self, **kwargs): """执行 Skill""" pass async def validate(self, input_data): """验证输入""" pass async def log(self, action, result): """记录审计日志""" await AuditLogger.log( skill=self.name, action=action, result=result, timestamp=datetime.utcnow() ) class SkillChain: """Skill 链 - 组合多个 Skills 形成复杂能力""" def __init__(self, skills): self.skills = skills self.execution_graph = ExecutionGraph() async def execute(self, input_data): """按依赖图执行 Skills""" results = {} for skill in self.execution_graph.topological_sort(): # 获取依赖的输入 skill_input = self.get_dependencies(skill, results) # 执行 Skill result = await skill.execute(**skill_input) # 存储结果供后续 Skill 使用 results[skill.name] = result return results
| Skill 名称 | 所属 Agent | 功能描述 | 输入 | 输出 |
|---|---|---|---|---|
receive_bug |
Collector | 从多渠道接收 Bug 报告 | channel, data | BugReport |
classify |
Collector | 自动分类 Bug 类型 | BugReport | Category + Confidence |
prioritize |
Collector | 评估 Bug 优先级 | BugReport, Category | Priority (P0-P3) |
git_blame |
Locator | Git Blame 代码归属分析 | file_path, line_number | AuthorInfo |
analyze_log |
Locator | 日志分析与异常提取 | log_entries | ErrorPatterns |
root_cause |
Locator | 根因分析 | stack_trace, logs | RootCause + Confidence |
code_analyze |
Fixer | 代码理解与分析 | code_context | CodeAnalysis |
fix_generate |
Fixer | 生成修复方案 (Claude Code) | RootCause, CodeAnalysis | FixPlan[] |
branch_create |
Fixer | 创建 Git 修复分支 | ticket_id | BranchName |
commit_code |
Fixer | 提交修复代码 | branch, fix, message | CommitHash |
run_unit_test |
Tester | 执行单元测试 | test_files | TestResult |
regression_test |
Tester | 回归测试验证 | fix_commit | RegressionReport |
canary_deploy |
Deployer | 灰度发布 | image, percentage | DeploymentStatus |
rollback |
Deployer | 自动回滚 | deployment_id | RollbackStatus |
# 定义完整的 Bug 修复 Skill 链 bugfix_chain = SkillChain([ # 阶段 1: 问题收集 ReceiveBugSkill(), ClassifyBugSkill(), PrioritizeBugSkill(), CreateTicketSkill(), # 阶段 2: 问题定位 GitBlameSkill(), AnalyzeLogSkill(), RootCauseSkill(), ImpactAnalysisSkill(), # 阶段 3: 代码修复 CodeAnalyzeSkill(), FixGenerateSkill(), BranchCreateSkill(), CommitCodeSkill(), # 阶段 4: 测试验证 RunUnitTestSkill(), RunIntegrationSkill(), RegressionTestSkill(), CoverageCheckSkill(), # 阶段 5: 部署发布 CodeReviewSkill(), CanaryDeploySkill(), MonitorSkill(), RollbackSkill() ]) # 执行 Skill 链 result = await bugfix_chain.execute(initial_bug_report)
负责智能体:Collector Agent
核心 Skills:receive_bug → classify → prioritize → create_ticket
负责智能体:Locator Agent
核心 Skills:git_blame → analyze_log → root_cause → impact_analysis
负责智能体:Fixer Agent
核心 Skills:code_analyze → fix_generate → branch_create → commit_code
负责智能体:Tester Agent
核心 Skills:run_unit_test → run_integration → regression_test → coverage_check
负责智能体:Deployer Agent
核心 Skills:code_review → canary_deploy → monitor → rollback
┌─────────────────────────────────────────────────────────────────┐
│ 沙箱管理层 │
│ ┌───────────────────────────────────────────────────────────┐ │
│ │ SandboxOrchestrator │ │
│ │ - 沙箱创建 - 资源分配 - 生命周期管理 - 清理回收 │ │
│ └───────────────────────────────────────────────────────────┘ │
└─────────────────────────────────────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────────────────┐
│ 沙箱实例层 │
│ ┌──────────────┐ ┌──────────────┐ ┌──────────────┐ │
│ │ Sandbox #1 │ │ Sandbox #2 │ │ Sandbox #3 │ │
│ │ │ │ │ │ │ │
│ │ - 代码执行 │ │ - 测试运行 │ │ - 集成验证 │ │
│ │ - 隔离环境 │ │ - 隔离环境 │ │ - 隔离环境 │ │
│ │ - 资源限制 │ │ - 资源限制 │ │ - 资源限制 │ │
│ └──────────────┘ └──────────────┘ └──────────────┘ │
└─────────────────────────────────────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────────────────┐
│ 资源隔离层 │
│ ┌──────────────┐ ┌──────────────┐ ┌──────────────┐ │
│ │ CPU Limit │ │ Memory Limit │ │ Network │ │
│ │ 2 Core │ │ 4GB │ │ Isolated │ │
│ └──────────────┘ └──────────────┘ └──────────────┘ │
│ ┌──────────────┐ ┌──────────────┐ ┌──────────────┐ │
│ │ Filesystem │ │ Process │ │ Timeout │ │
│ │ Read-Only │ │ Isolation │ │ 30min │ │
│ └──────────────┘ └──────────────┘ └──────────────┘ │
└─────────────────────────────────────────────────────────────────┘
class SandboxExecutor: """沙箱执行器 - 在隔离环境中执行代码""" def __init__(self, config): self.docker_client = docker.from_env() self.config = config self.sandboxes = {} async def create_sandbox(self, sandbox_id, requirements): """创建沙箱环境""" container = self.docker_client.containers.run( image="python:3.11-slim", name=f"bugfix-sandbox-{sandbox_id}", command="sleep infinity", detach=True, # 资源限制 cpu_quota=200000, # 2 Core mem_limit="4g", # 网络隔离 network="none", # 文件系统隔离 volumes={ "/tmp/sandbox/{sandbox_id}": { "bind": "/workspace", "mode": "rw" } }, # 安全配置 security_opt=["no-new-privileges:true"], cap_drop=["ALL"], read_only=True, tmpfs={"/tmp": "rw,noexec,nosuid,size=1g"} ) self.sandboxes[sandbox_id] = container return container async def execute_code(self, sandbox_id, code, timeout=1800): """在沙箱中执行代码""" container = self.sandboxes[sandbox_id] # 写入代码 await self.write_to_container(container, "/workspace/main.py", code) # 执行代码 (带超时) result = container.exec_run( cmd="python /workspace/main.py", demux=True, workdir="/workspace" ) # 收集输出 output = { "stdout": result.output[0].decode(), "stderr": result.output[1].decode(), "exit_code": result.exit_code } return output async def cleanup_sandbox(self, sandbox_id): """清理沙箱""" container = self.sandboxes.get(sandbox_id) if container: container.stop() container.remove() del self.sandboxes[sandbox_id]
class AuditLog: """审计日志数据结构""" def __init__(self): self.trace_id = uuid.uuid4() # 全链路追踪 ID self.timestamp = datetime.utcnow() self.agent_name = None self.skill_name = None self.action = None self.input_data = None self.output_data = None self.execution_time = None self.status = None self.error_message = None self.operator = None # AI Agent 或 人类 self.decision_reason = None # 决策依据 def to_dict(self): return { "trace_id": str(self.trace_id), "timestamp": self.timestamp.isoformat(), "agent": self.agent_name, "skill": self.skill_name, "action": self.action, "input": self.input_data, "output": self.output_data, "execution_time_ms": self.execution_time, "status": self.status, "error": self.error_message, "operator": self.operator, "decision_reason": self.decision_reason } class AuditLogger: """审计日志记录器""" @staticmethod async def log(**kwargs): """记录审计日志""" log_entry = AuditLog(**kwargs) # 写入数据库 await db.audit_logs.insert_one(log_entry.to_dict()) # 写入 Elasticsearch (用于检索) await es.index( index="audit-logs", body=log_entry.to_dict() ) @staticmethod async def query_by_trace_id(trace_id): """按追踪 ID 查询完整链路""" logs = await db.audit_logs.find( {"trace_id": trace_id} ).sort("timestamp", 1) return [log async for log in logs] @staticmethod async def generate_audit_report(ticket_id): """生成审计报告""" logs = await db.audit_logs.find( {"ticket_id": ticket_id} ) report = { "ticket_id": ticket_id, "total_actions": await logs.count(), "timeline": [log async for log in logs], "agents_involved": await logs.distinct("agent"), "total_execution_time": await calculate_total_time(logs), "success_rate": await calculate_success_rate(logs) } return report
| 查询类型 | 查询语句 | 用途 |
|---|---|---|
| 全链路追踪 | GET /audit/trace/{trace_id} |
查看完整执行链路 |
| 按工单查询 | GET /audit/ticket/{ticket_id} |
查看某工单的所有操作 |
| 按 Agent 查询 | GET /audit/agent/{agent_name} |
查看某 Agent 的所有操作 |
| 错误查询 | GET /audit/errors?from=...&to=... |
查询特定时间段的错误 |
| 审计报告 | GET /audit/report/{ticket_id} |
生成完整审计报告 |
开发、测试、生产多套 K8s 集群统一管理,支持跨集群部署和灾备
内置 CI/CD 流水线,与 Jenkins 深度集成,支持自动化部署
集成 Prometheus + Grafana,实时监控集群和应用状态
一键部署 PostgreSQL、Redis、RabbitMQ 等依赖服务
| 组件 | CPU | 内存 | 存储 | 副本数 |
|---|---|---|---|---|
| OpenClaw 编排引擎 | 4 Core | 8 GB | 50 GB | 3 |
| 智能体服务 (每个) | 2 Core | 4 GB | 20 GB | 2-5 |
| PostgreSQL | 4 Core | 16 GB | 500 GB | 2 (主从) |
| Redis | 2 Core | 8 GB | 50 GB | 3 (集群) |
| RabbitMQ | 2 Core | 4 GB | 20 GB | 3 (集群) |
| 沙箱执行器 | 8 Core | 16 GB | 100 GB | 5-10 |