Skip to content

About

Multi-agent code review system built with Claude. Parallel security, quality, and performance agents with orchestrator

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

1 Commit

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🤖 CodeReview Agent — 多 Agent 协作代码审查系统

基于 Claude claude-sonnet-4-20250514 构建的多 Agent 协作代码审查工具。三个专业 Sub-Agent 并行分析,Orchestrator 汇总决策并自动生成修复方案。


🧠 核心逻辑

用户提交代码
      │
      ▼
┌─────────────────────────────────────┐
│           Orchestrator              │
│  (协调调度 / 汇总结果 / 决策修复)    │
└──────────┬──────────────────────────┘
           │ 并行派发
     ┌─────┼─────┐
     ▼     ▼     ▼
┌────────┐ ┌────────┐ ┌─────────────┐
│Security│ │Quality │ │ Performance │
│ Agent  │ │ Agent  │ │    Agent    │
│安全扫描│ │质量分析│ │  性能检测   │
└────────┘ └────────┘ └─────────────┘
     │         │            │
     └─────────┴────────────┘
                 │
                 ▼
        最终报告 + 自动修复代码

解决的核心痛点:

  • 传统 Code Review 依赖人工,速度慢、覆盖不全
  • 单一 AI 模型难以同时兼顾安全/质量/性能三个维度
  • 多 Agent 专业分工 + Orchestrator 长链推理决策,显著提升审查深度和准确率

✨ 功能特性

Agent 职责 输出
SecurityAgent SQL注入、XSS、敏感信息泄露等漏洞扫描 安全评分 + 漏洞列表
QualityAgent 可读性、可维护性、代码规范检查 质量评分 + 改进建议
PerformanceAgent 时间复杂度、内存使用、算法效率分析 性能评分 + 优化方案
Orchestrator 汇总三方结论,长链推理生成最终报告 综合评分 + 修复代码

🚀 快速开始

安装依赖

pip install anthropic

设置 API Key

export ANTHROPIC_API_KEY="your-api-key-here"

运行 Demo

cd src
python agent.py

在代码中使用

from src.agent import review_code

code = """
def get_user(username, password):
    query = f"SELECT * FROM users WHERE name='{username}'"
    ...
"""

report = review_code(code=code, language="python", file_path="user_service.py")

print(f"综合评分: {report.overall_score}/100")
print(f"总结: {report.final_summary}")
if report.auto_fixed:
    print(f"修复版本:\n{report.fixed_code}")

📊 输出示例

══════════════════════════════════════════════════
  代码审查报告 - demo/user_service.py
══════════════════════════════════════════════════
  综合评分: 🔴 38/100

  🔒 SecurityAgent: 25/100 — 发现严重 SQL 注入漏洞
     ⚠ 使用 f-string 直接拼接 SQL,存在注入风险
     ⚠ 密码明文存储,未加密处理
  ✨ QualityAgent: 52/100 — 代码可读性较差
     ⚠ 函数职责不单一,建议拆分
     ⚠ 缺少类型注解和文档注释
  ⚡ PerformanceAgent: 38/100 — 存在 O(n²) 性能问题
     ⚠ process_list 双层循环,复杂度过高
     ⚠ 数据库连接未复用,频繁开销

  📋 总结: 该代码存在严重安全漏洞和性能缺陷,建议重写。

  🔧 已自动生成修复版本
══════════════════════════════════════════════════

🏗 项目结构

xiaomi-100t-agent/
├── src/
│   └── agent.py          # 多 Agent 核心逻辑
├── examples/
│   └── sample_code.py    # 示例测试代码
├── docs/
│   └── architecture.md   # 架构设计文档
├── README.md
└── requirements.txt

🔮 扩展方向

  • 支持 PR 批量文件扫描(接入 GitHub Actions)
  • 增加 TestAgent 自动生成单元测试
  • Web UI 界面
  • 支持更多语言(Java / Go / TypeScript)

📦 依赖

anthropic>=0.40.0

License

MIT

About

Multi-agent code review system built with Claude. Parallel security, quality, and performance agents with orchestrator

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages