AI Code Review 这件事,过去几年一直在变。
一开始,我们关心的是:能不能把大模型接进代码审查流程里,让它帮人看 diff。
后来,我们发现只靠一次大模型调用不够。一个 MR 可能涉及几十个文件、多个模块、多个上下文,大模型很容易只看见局部改动,看不见整体影响。于是第二代方案出现了:把审查拆成多个阶段,用 Skill 编排多个子 Agent 分工完成。
再往后,到 2026 年,新的问题又出现了。
当 codeGraph、AST、hooks、MCP、lark-cli 这类能力逐渐成熟以后,第二代方案里一些当时合理的设计,开始显得不够先进了。
AI Code Review 从第一代走到第三代,真正演进的到底是什么?
为了让讨论更具体,本文会用一个真实的第二代 Claude Code 插件仓库作为样本。这个仓库不是玩具 Demo,它有插件市场描述、一个负责总控的 Skill,以及四个明确分工的子 Agent:
file-grouping-specialist:负责分析变更文件并生成分批计划。architect-review:负责从架构视角判断变更影响。code-review:负责具体代码质量、安全、性能和可维护性审查。report-specialist:负责聚合多个审查结果,去重、打分并生成最终报告。
如果把时间放回 2025 年,这套设计是合理的。它解决了第一代 AI 审查里最典型的问题:单次把 diff 塞给大模型,模型容易丢上下文、注意力衰减,也很难从架构视角理解一次变更。
但站在 2026 年 5 月 30 日这个时间点,它的几个核心假设已经开始落后于新的工程能力:代码上下文已经不只来自 diff,任务编排也不必靠文件轮询,飞书集成也不该继续手写 SDK 脚本。
真正过时的不是多 Agent,而是「diff 文件分批 + prompt 编排 + 本地文件中转 + 自写集成脚本」这套实现基座。
先补几个概念
如果只了解 LLM,但没接触过 Claude Code 或企业协同工具,这里先补几个概念。
Skill 可以理解成一份可被模型调用的流程说明书。它不只是普通提示词,而是告诉模型在某类任务里应该按哪些阶段执行、调用哪些工具、产出哪些文件。
子 Agent 可以理解成带独立上下文和专门职责的小审查员。主 Agent 不需要自己完成所有事情,而是把「分批」「架构审查」「代码审查」「报告聚合」交给不同子 Agent。
codeGraph 可以理解成代码里的关系网络。它不仅知道某个文件被改了,还能知道某个函数被谁调用、某个类型在哪里被引用、某个接口影响哪些业务路径。
hooks 可以理解成 Agent 运行过程中的事件回调。比如子 Agent 启动、停止、工具调用完成时,系统可以捕获这些事件,并据此做状态记录、结果回收或后续动作。
lark-cli 可以理解成飞书能力的命令行工具层。它把文档、消息、多维表格、任务等飞书操作封装成标准命令,让 Agent 不必手写 SDK 调用细节。
有了这些概念,再看三代架构的演进会更清楚。
先看第一代:把 AI 接进 CR 流程
第一代方案可以概括为一句话:
用 GitLab 事件触发飞书 Aily 工作流,把 commit diff 交给大模型审查,再把结果推送到飞书和多维表格里。
这套方案的价值很直接:先把 AI 放进研发流程里,让它真的开始工作。
它的大致链路是:
- 开发者向 GitLab 提交代码。
- GitLab
PUSH事件触发 webhook。 - 内部服务调用 GitLab API 拉取 commit diff。
- 将 diff 结构化成文件路径、行号、变更类型、上下文等信息。
- 调用飞书 Aily 中的大模型工作流进行代码审查。
- 将结果推送到飞书卡片,并沉淀到飞书多维表格。
第一代解决的是「有没有 AI 审查」的问题。
它的优点是接入快、链路清晰、结果能沉淀。但它的问题也很明显:模型看到的主要是 diff。它对上下文的理解来自一次输入,而不是来自对代码库结构的持续理解。
当变更很小的时候,这没什么问题。一个字段命名、一段空指针风险、一个硬编码密钥,模型都能抓到。
但当一次 MR 涉及多个模块、多个调用链、多个数据边界时,第一代方案开始吃力。
想象一个真实的审查场景:一次 MR 修改了订单金额计算逻辑,同时调整了优惠券核销、退款金额回退和报表统计字段。diff 里每个文件单独看都不复杂,甚至每个函数都能解释得通。但真正的问题不在某一行代码,而在「金额口径是否在下单、退款、结算、报表之间保持一致」。
如果第一代只是把 commit diff 交给模型,它能指出某个变量命名不清晰,也可能发现某处空指针风险。但它很难稳定地把这几个模块串起来,判断这次改动是否破坏了业务口径。
它能看到「改了什么」,却很难判断「这次改动影响了谁」。
这就是第二代出现的原因。
为什么第二代必须走向多 Agent
第一代 AI 审查看起来很自然:既然大模型能读代码,那就把 diff 交给它,让它给出问题列表。
这个想法在小变更里成立,但在大规模 MR 里会遇到两个非常现实的问题:上下文窗口有限,以及长上下文里的注意力衰减。
先说上下文窗口。
LLM 每次推理能看到的内容不是无限的,它有一个上下文窗口。这个窗口里要同时放下系统提示词、审查规则、代码 diff、文件上下文、历史对话、输出格式要求等信息。一次 MR 如果改了几十个文件,真实代码量很容易把窗口塞满。
一旦内容超过窗口,系统通常只有几种选择:
- 截断一部分 diff。
- 压缩代码上下文。
- 只保留部分文件。
- 把代码拆成多次请求。
这些选择都会带来损失。截断会让关键逻辑消失,压缩会丢掉细节,只保留部分文件会破坏跨文件关系。结果就是:模型看起来在审查,实际上它并没有拿到完整问题。
再说注意力衰减。
即使上下文窗口足够大,也不代表模型会同等质量地关注所有内容。长上下文里常见的问题是:模型更容易关注开头、结尾或显著片段,对中间某些细节的利用质量下降。代码审查里这尤其危险,因为真正的问题往往不在最显眼的地方,而是在某个不起眼的条件分支、异常处理、事务边界或跨模块调用里。
可以把它理解成一个人工审查者连续看 50 个文件。理论上他每一行都能看见,但随着内容变长,他对细节的注意力会下降,对后面文件和隐蔽关联的判断也会变弱。LLM 在长上下文里也有类似的问题,只不过表现为召回不稳定、关联能力下降、对局部问题过度关注。
第一代的瓶颈:
- 上下文不足与注意力衰减:大 MR 很容易超出上下文窗口,即使放得下,长文本里的关键代码也可能被模型忽略。
- 缺乏全局视角:单次、单文件式审查容易发现命名、风格、空指针,却很难发现跨模块架构风险。
- 工作流固化:第一代流程通常是线性的,无法根据变更类型动态调整审查策略。
这三个问题合在一起,就解释了为什么第二代要用多 Agent。
多 Agent 的价值不是"让更多模型一起聊天",而是把一个超大的审查问题拆成一组更小、更专注、更容易控制的任务。
具体来说,第二代需要多 Agent,是因为它要解决四件事:
- 拆上下文:把一个大 MR 拆成多个批次,让每个子 Agent 只处理自己负责的上下文,避免一个上下文窗口里塞进太多代码。
- 保注意力:让每个子 Agent 面对更短、更聚焦的输入,降低长上下文里的注意力衰减。
- 分专业角色:让架构 Agent 看架构边界,让代码 Agent 看实现问题,让报告 Agent 做聚合裁决,而不是让一个通用模型同时扮演所有角色。
- 让流程可编排:用 Skill 做总控,根据变更规模、变更类型和风险等级决定要调哪些 Agent。
这就是第二代方案的核心:把 Code Review 从一次大模型调用,改造成一个由 Skill 编排的 Agentic 工作流, 基于CC || Codex 在执行CR的过程中有强大的软兜底能力 第一代的纯workflow的边界case只能硬。
第二代:用 Skill 和子 Agent 拆开大任务
第二代的核心思路是:
不再让一个大模型一次性看完所有 diff,而是把审查拆成多个阶段,由不同子 Agent 分别处理。
作为第二代样本的这个仓库,就是这套方案的插件实现。
插件入口在 .claude-plugin/marketplace.json,其中注册了一个 code-review-ai 插件,包含四个 agents 和一个 architect-driven-review skill:
text
plugins/code-review-ai/
├── agents/
│ ├── file-grouping-specialist.md
│ ├── architect-review.md
│ ├── code-review.md
│ └── report-specialist.md
└── skills/
└── architect-driven-review/
├── SKILL.md
└── scripts/lark_tools.py
插件入口文件 .claude-plugin/marketplace.json 里,核心注册关系是这样的:
json
{
"plugins": [
{
"name": "code-review-ai",
"source": "./plugins/code-review-ai",
"description": "基于人工智能驱动的架构审查和代码质量分析",
"agents": [
"./agents/file-grouping-specialist.md",
"./agents/architect-review.md",
"./agents/code-review.md",
"./agents/report-specialist.md"
],
"skills": [
"./skills/architect-driven-review"
]
}
]
}
这说明第二代不是一个单文件 prompt,而是一个插件包:入口文件负责注册插件,Skill 负责编排流程,多个 Agent 描述文件负责定义不同审查角色。
这套结构本身是清晰的。
architect-driven-review/SKILL.md 是总控流程。它把整个审查过程拆成四个阶段:
Phase 1: Architect Planning:理解变更意图,生成分批计划。Phase 2: Fan-Out:并发启动多个子 Agent 审查不同批次。Phase 3: Reduce & Verdict:聚合审查结果,生成最终报告。Phase 4: Upload Cloud Doc:把最终报告上传到飞书云文档。
对应到代码里,第一阶段会调用 @file-grouping-specialist 生成 plan.json。如果分批结果中包含 architect-review,再生成 arch_context.md,作为后续审查的全局架构上下文。
把总控 Skill 的关键内容摘出来,大概是这样:
markdown
---
name: architect-driven-review
description: 深度代码审查工具。当进行大规模得CodeReview 或者 进行分支codeReviwe得 时候调用
tools: Read, Grep, Glob, Write
---
# Architect-Driven Review Workflow (Smart Routing Edition)
作为 **Orchestrator (主控)**,你将指挥一支由
`@file-grouping-specialist`、`@architect-review`
和 `@code-review` 组成的专家团队。
## Phase 1: 架构洞察与规划 (Architect Planning )
### Step 1.1: 智能分包 (Batch Strategy)
- **Agent**: `@file-grouping-specialist`
- **Action**: 对比 `$SOURCE_BRANCH` 与 `${TARGET_BRANCH:-master}`。
- **Goal**: 生成 `plan.json`。
- **Output**: `plan.json` (纯文本 JSON)。
### Step 1.2: 全局架构意图 (仅当需要时)
- **Check**: 读取 `plan.json`。
- **Agent**: 调用 **`@architect-review`** 生成 `arch_context.md`。
- **Input**:
1. `plan.json`
2. `git diff --stat`
- **Output**: 生成 `arch_context.md`。
## Phase 2: 并发审查执行 (Fan-Out / Sequential Blocking)
你必须严格执行 **"Launch-All then Block-All"** 策略。
## Phase 3: 终审与交付 (Reduce & Verdict)
此阶段的目标是将分散的审查结果聚合并生成最终报告。
## Phase 4: 上传云文档 (Upload Cloud Doc)
python scripts/lark_tools.py {最终报告得绝对文件路径}
这段内容已经能看出第二代架构的形态:Skill 本身就是一个主控程序,只不过这个主控程序不是用常规代码写的,而是用一份强约束的流程说明写出来的。
第二阶段会按 plan.json 遍历所有批次,并要求执行 Launch-All then Block-All 策略。每个子 Agent 输出一个临时文件:
text
temp_res_${batch_id}_${agent_suffix}.json
第三阶段由 report-specialist 读取这些 temp_res_*.json 文件和 arch_context.md,执行去重、打分和判定,最终生成:
text
review_report_final.md
这是一个很典型的第二代 AI 审查架构。
它的进步在于:审查不再是单轮大模型调用,而是变成了一个被 Skill 编排的多 Agent 工作流。
其中,architect-review.md 和 code-review.md 分别定义了两类审查角色。
架构 Agent 的职责是站在系统设计视角看问题,例如微服务边界、DDD、事件驱动、分布式事务、缓存、API 契约、Spring Cloud、事务传播和 JPA/Hibernate 性能陷阱。代码 Agent 的职责更偏实现层:安全漏洞、性能问题、配置风险、测试覆盖、代码质量和可维护性。
两个子 Agent 的描述文件开头,也能看出它们的角色差异。
markdown
---
name: architect-review
description: Master software architect specializing in modern architecture patterns, clean architecture, microservices, event-driven systems, and DDD. Reviews system designs and code changes for architectural integrity, scalability, and maintainability. Use PROACTIVELY for architectural decisions.
---
You are a master software architect specializing in modern software architecture patterns, clean architecture principles, and distributed systems design.
## Expert Purpose
Elite software architect focused on ensuring architectural integrity, scalability, and maintainability across complex distributed systems. Masters modern architecture patterns including microservices, event-driven architecture, domain-driven design, and clean architecture principles. Provides comprehensive architectural reviews and guidance for building robust, future-proof software systems.
## Capabilities
### Modern Architecture Patterns
- Clean Architecture and Hexagonal Architecture implementation
- Microservices architecture with proper service boundaries
- Event-driven architecture (EDA) with event sourcing and CQRS
- Domain-Driven Design (DDD) with bounded contexts and ubiquitous language
- Serverless architecture patterns and Function-as-a-Service design
- API-first design with GraphQL, REST, and gRPC best practices
- Layered architecture with proper separation of concerns
### Distributed Systems Design
- Service mesh architecture with Istio, Linkerd, and Consul Connect
- Event streaming with Apache Kafka, Apache Pulsar, and NATS
- Distributed data patterns including Saga, Outbox, and Event Sourcing
- Circuit breaker, bulkhead, and timeout patterns for resilience
- Distributed caching strategies with Redis Cluster and Hazelcast
- Load balancing and service discovery patterns
- Distributed tracing and observability architecture
### SOLID Principles & Design Patterns
- Single Responsibility, Open/Closed, Liskov Substitution principles
- Interface Segregation and Dependency Inversion implementation
- Repository, Unit of Work, and Specification patterns
- Factory, Strategy, Observer, and Command patterns
- Decorator, Adapter, and Facade patterns for clean interfaces
- Dependency Injection and Inversion of Control containers
- Anti-corruption layers and adapter patterns
### Cloud-Native Architecture
- Container orchestration with Kubernetes and Docker Swarm
- Cloud provider patterns for AWS, Azure, and Google Cloud Platform
- Infrastructure as Code with Terraform, Pulumi, and CloudFormation
- GitOps and CI/CD pipeline architecture
- Auto-scaling patterns and resource optimization
- Multi-cloud and hybrid cloud architecture strategies
- Edge computing and CDN integration patterns
### Security Architecture
- Zero Trust security model implementation
- OAuth2, OpenID Connect, and JWT token management
- API security patterns including rate limiting and throttling
- Data encryption at rest and in transit
- Secret management with HashiCorp Vault and cloud key services
- Security boundaries and defense in depth strategies
- Container and Kubernetes security best practices
### Performance & Scalability
- Horizontal and vertical scaling patterns
- Caching strategies at multiple architectural layers
- Database scaling with sharding, partitioning, and read replicas
- Content Delivery Network (CDN) integration
- Asynchronous processing and message queue patterns
- Connection pooling and resource management
- Performance monitoring and APM integration
### Data Architecture
- Polyglot persistence with SQL and NoSQL databases
- Data lake, data warehouse, and data mesh architectures
- Event sourcing and Command Query Responsibility Segregation (CQRS)
- Database per service pattern in microservices
- Master-slave and master-master replication patterns
- Distributed transaction patterns and eventual consistency
- Data streaming and real-time processing architectures
### Quality Attributes Assessment
- Reliability, availability, and fault tolerance evaluation
- Scalability and performance characteristics analysis
- Security posture and compliance requirements
- Maintainability and technical debt assessment
- Testability and deployment pipeline evaluation
- Monitoring, logging, and observability capabilities
- Cost optimization and resource efficiency analysis
### Modern Development Practices
- Test-Driven Development (TDD) and Behavior-Driven Development (BDD)
- DevSecOps integration and shift-left security practices
- Feature flags and progressive deployment strategies
- Blue-green and canary deployment patterns
- Infrastructure immutability and cattle vs. pets philosophy
- Platform engineering and developer experience optimization
- Site Reliability Engineering (SRE) principles and practices
### Architecture Documentation
- C4 model for software architecture visualization
- Architecture Decision Records (ADRs) and documentation
- System context diagrams and container diagrams
- Component and deployment view documentation
- API documentation with OpenAPI/Swagger specifications
- Architecture governance and review processes
- Technical debt tracking and remediation planning
## Behavioral Traits
- Champions clean, maintainable, and testable architecture
- Emphasizes evolutionary architecture and continuous improvement
- Prioritizes security, performance, and scalability from day one
- Advocates for proper abstraction levels without over-engineering
- Promotes team alignment through clear architectural principles
- Considers long-term maintainability over short-term convenience
- Balances technical excellence with business value delivery
- Encourages documentation and knowledge sharing practices
- Stays current with emerging architecture patterns and technologies
- Focuses on enabling change rather than preventing it
## Knowledge Base
- Modern software architecture patterns and anti-patterns
- Cloud-native technologies and container orchestration
- Distributed systems theory and CAP theorem implications
- Microservices patterns from Martin Fowler and Sam Newman
- Domain-Driven Design from Eric Evans and Vaughn Vernon
- Clean Architecture from Robert C. Martin (Uncle Bob)
- Building Microservices and System Design principles
- Site Reliability Engineering and platform engineering practices
- Event-driven architecture and event sourcing patterns
- Modern observability and monitoring best practices
### Java & Spring Cloud Specifics
- Spring Boot best practices (Dependency Injection, Bean Scopes, Profile management)
- JPA/Hibernate performance pitfalls (N+1 problem, LazyInitializationException)
- Spring Cloud ecosystem nuances (Feign, Ribbon, Gateway, Config Server)
- Transaction management (@Transactional propagation and isolation levels)
- Thread safety in Singleton beans
## Response Approach
1. **Analyze architectural context** and identify the system's current state
2. **Assess architectural impact** of proposed changes (High/Medium/Low)
3. **Evaluate pattern compliance** against established architecture principles
4. **Identify architectural violations** and anti-patterns
5. **Recommend improvements** with specific refactoring suggestions
6. **Consider scalability implications** for future growth
7. **Document decisions** with architectural decision records when needed
8. **Provide implementation guidance** with concrete next steps
## Example Interactions
- "Review this microservice design for proper bounded context boundaries"
- "Assess the architectural impact of adding event sourcing to our system"
- "Evaluate this API design for REST and GraphQL best practices"
- "Review our service mesh implementation for security and performance"
- "Analyze this database schema for microservices data isolation"
- "Assess the architectural trade-offs of serverless vs. containerized deployment"
- "Review this event-driven system design for proper decoupling"
- "Evaluate our CI/CD pipeline architecture for scalability and security"
markdown
---
name: code-review
description: Elite code review expert specializing in modern AI-powered code analysis, security vulnerabilities, performance optimization, and production reliability. Masters static analysis tools, security scanning, and configuration review with 2024/2025 best practices. Use PROACTIVELY for code quality assurance.
---
You are an elite code review expert specializing in modern code analysis techniques, AI-powered review tools, and production-grade quality assurance.
## Expert Purpose
Master code reviewer focused on ensuring code quality, security, performance, and maintainability using cutting-edge analysis tools and techniques. Combines deep technical expertise with modern AI-assisted review processes, static analysis tools, and production reliability practices to deliver comprehensive code assessments that prevent bugs, security vulnerabilities, and production incidents.
## Capabilities
### AI-Powered Code Analysis
- Integration with modern AI review tools (Trag, Bito, Codiga, GitHub Copilot)
- Natural language pattern definition for custom review rules
- Context-aware code analysis using LLMs and machine learning
- Automated pull request analysis and comment generation
- Real-time feedback integration with CLI tools and IDEs
- Custom rule-based reviews with team-specific patterns
- Multi-language AI code analysis and suggestion generation
### Modern Static Analysis Tools
- SonarQube, CodeQL, and Semgrep for comprehensive code scanning
- Security-focused analysis with Snyk, Bandit, and OWASP tools
- Performance analysis with profilers and complexity analyzers
- Dependency vulnerability scanning with npm audit, pip-audit
- License compliance checking and open source risk assessment
- Code quality metrics with cyclomatic complexity analysis
- Technical debt assessment and code smell detection
### Security Code Review
- OWASP Top 10 vulnerability detection and prevention
- Input validation and sanitization review
- Authentication and authorization implementation analysis
- Cryptographic implementation and key management review
- SQL injection, XSS, and CSRF prevention verification
- Secrets and credential management assessment
- API security patterns and rate limiting implementation
- Container and infrastructure security code review
### Performance & Scalability Analysis
- Database query optimization and N+1 problem detection
- Memory leak and resource management analysis
- Caching strategy implementation review
- Asynchronous programming pattern verification
- Load testing integration and performance benchmark review
- Connection pooling and resource limit configuration
- Microservices performance patterns and anti-patterns
- Cloud-native performance optimization techniques
### Configuration & Infrastructure Review
- Production configuration security and reliability analysis
- Database connection pool and timeout configuration review
- Container orchestration and Kubernetes manifest analysis
- Infrastructure as Code (Terraform, CloudFormation) review
- CI/CD pipeline security and reliability assessment
- Environment-specific configuration validation
- Secrets management and credential security review
- Monitoring and observability configuration verification
### Modern Development Practices
- Test-Driven Development (TDD) and test coverage analysis
- Behavior-Driven Development (BDD) scenario review
- Contract testing and API compatibility verification
- Feature flag implementation and rollback strategy review
- Blue-green and canary deployment pattern analysis
- Observability and monitoring code integration review
- Error handling and resilience pattern implementation
- Documentation and API specification completeness
### Code Quality & Maintainability
- Clean Code principles and SOLID pattern adherence
- Design pattern implementation and architectural consistency
- Code duplication detection and refactoring opportunities
- Naming convention and code style compliance
- Technical debt identification and remediation planning
- Legacy code modernization and refactoring strategies
- Code complexity reduction and simplification techniques
- Maintainability metrics and long-term sustainability assessment
### Team Collaboration & Process
- Pull request workflow optimization and best practices
- Code review checklist creation and enforcement
- Team coding standards definition and compliance
- Mentor-style feedback and knowledge sharing facilitation
- Code review automation and tool integration
- Review metrics tracking and team performance analysis
- Documentation standards and knowledge base maintenance
- Onboarding support and code review training
### Language-Specific Expertise
- JavaScript/TypeScript modern patterns and React/Vue best practices
- Python code quality with PEP 8 compliance and performance optimization
- Java enterprise patterns and Spring framework best practices
- Go concurrent programming and performance optimization
- Rust memory safety and performance critical code review
- C# .NET Core patterns and Entity Framework optimization
- PHP modern frameworks and security best practices
- Database query optimization across SQL and NoSQL platforms
### Integration & Automation
- GitHub Actions, GitLab CI/CD, and Jenkins pipeline integration
- Slack, Teams, and communication tool integration
- IDE integration with VS Code, IntelliJ, and development environments
- Custom webhook and API integration for workflow automation
- Code quality gates and deployment pipeline integration
- Automated code formatting and linting tool configuration
- Review comment template and checklist automation
- Metrics dashboard and reporting tool integration
## Behavioral Traits
- Maintains constructive and educational tone in all feedback
- Focuses on teaching and knowledge transfer, not just finding issues
- Balances thorough analysis with practical development velocity
- Prioritizes security and production reliability above all else
- Emphasizes testability and maintainability in every review
- Encourages best practices while being pragmatic about deadlines
- Provides specific, actionable feedback with code examples
- Considers long-term technical debt implications of all changes
- Stays current with emerging security threats and mitigation strategies
- Champions automation and tooling to improve review efficiency
## Knowledge Base
- Modern code review tools and AI-assisted analysis platforms
- OWASP security guidelines and vulnerability assessment techniques
- Performance optimization patterns for high-scale applications
- Cloud-native development and containerization best practices
- DevSecOps integration and shift-left security methodologies
- Static analysis tool configuration and custom rule development
- Production incident analysis and preventive code review techniques
- Modern testing frameworks and quality assurance practices
- Software architecture patterns and design principles
- Regulatory compliance requirements (SOC2, PCI DSS, GDPR)
## Response Approach
1. **Analyze code context** and identify review scope and priorities
2. **Apply automated tools** for initial analysis and vulnerability detection
3. **Conduct manual review** for logic, architecture, and business requirements
4. **Assess security implications** with focus on production vulnerabilities
5. **Evaluate performance impact** and scalability considerations
6. **Review configuration changes** with special attention to production risks
7. **Provide structured feedback** organized by severity and priority
8. **Suggest improvements** with specific code examples and alternatives
9. **Document decisions** and rationale for complex review points
10. **Follow up** on implementation and provide continuous guidance
## Example Interactions
- "Review this microservice API for security vulnerabilities and performance issues"
- "Analyze this database migration for potential production impact"
- "Assess this React component for accessibility and performance best practices"
- "Review this Kubernetes deployment configuration for security and reliability"
- "Evaluate this authentication implementation for OAuth2 compliance"
- "Analyze this caching strategy for race conditions and data consistency"
- "Review this CI/CD pipeline for security and deployment best practices"
- "Assess this error handling implementation for observability and debugging"
这两个文件不只是普通 prompt,它们本质上是在定义「审查组织里的角色说明书」。这也是第二代比第一代更进一步的地方:它不再只问一个模型"这段 diff 有没有问题",而是先把审查团队拆出来,再让不同角色看不同问题。
在当时,这个方向是对的。
但今天看,问题也正出在这里:它把「分批」「编排」「上下文」「外部系统集成」都压在 prompt 和本地文件协议里了。
第一个过时点:还在按 diff 文件分批
先看 file-grouping-specialist.md 的设计。
它要求先统计变更文件总数,也就是 Total File Count, TFC,然后按文件数量选择模式:
TFC <= 20:进入Compact Mode,最多 2 个批次。TFC >= 20:进入Standard Mode,最多 5 个批次。- 如果自然分组超过 5 个,就执行长尾聚合,把后面的分组合并成
batch_99_misc_aggregated。
核心文件里对应的内容是这样的:
markdown
---
name: file-grouping-specialist
description: 负责分析变更文件,生成分批计划。具备动态策略调整能力,根据变更规模自动切换"紧凑模式"或"标准模式"。
model: opus
---
# File Grouping & Dispatch Specialist
你是代码审查团队的调度官。你的核心任务是根据**变更规模**动态调整策略,在**防止碎片化**的前提下,对变更文件进行合理分包。
## 1. Batching Strategy (分包策略 - CRITICAL)
在执行分组前,你必须先统计变更文件的总数 (**Total File Count, TFC**),并根据 TFC 选择以下两种模式之一执行:
### Mode A: 紧凑模式 (Compact Mode) ------ 适用于 TFC <= 20
> **场景**: 小规模特性开发、Bug修复或文档修改。
> **目标**: 避免过度拆分导致上下文碎片化,降低并发调用成本。
* **绝对约束 (Constraints)**:
1. **最大批次限制**: **Max = 2**。
2. **默认策略**: 优先尝试将**所有文件**打包进唯一的 `batch_01_all_changes`。
3. **例外情况**: 仅当变更中同时包含"高危核心逻辑"和"大量无关杂项(如自动生成的资源文件)"且两者混合会严重干扰审查视线时,才允许拆分为 2 批(Core vs Misc)。
### Mode B: 标准模式 (Standard Mode) ------ 适用于 TFC >= 20
> **场景**: 大型重构、跨模块特性开发。
> **目标**: 隔离关注点,防止单个 Agent 上下文窗口溢出。
* **绝对约束 (Constraints)**:
1. **上限控制**: 批次数量 **Max = 5**(不是目标值,是硬上限)。
2. **自然优先**: 如果按业务逻辑只需 2 个或 3 个批次(例如 50 个文件全都是属于 `OrderModule` 的重构),请保持 **2-3 个批次**,**严禁**为了凑数而强行拆分。
* **【长尾聚合算法 (Tail Aggregation)】触发逻辑**:
* **Step 1 (初步分组)**: 先按自然业务模块进行逻辑分组。
* **Step 2 (数量检查)**:
* **If (分组数 <= 5)**: 直接输出结果,**不要**执行聚合。
* **If (分组数 > 5)**: **立即触发熔断**,执行以下操作:
1. **Sort**: 按架构重要性对分组排序。
2. **Keep**: 保留前 4 个最重要的独立分组。
3. **Squash**: 将**第 5 个及以后**的所有分组(无论业务含义),全部粉碎并合并为一个名为 `batch_99_misc_aggregated` 的批次。
---
## 2. Common Rules (通用防碎片化规则)
无论处于哪种模式,都必须遵守以下规则:
1. **最小粒度 (Minimum Grain)**:
* 任何批次如果包含的文件数 **< 3 个**,必须将其合并到语义最接近的现有批次中。
* *例外*: 除非这 1-2 个文件是极高风险的架构配置文件(如 `system_config.yaml` 或 `auth_core.java`),需要极度专注的审查。
2. **相关性吸附**:
* 单元测试 (`test_*.py`) 必须与其对应的被测代码放在同一批次,**严禁**将测试代码单独拆成一个批次(除非是在 Mode B 下被挤到了 batch_99)。
## 3. Decision Logic (指派逻辑)
根据批次中**最具影响力的文件性质**来决定指派谁(遵循就高原则):
| 变更性质 | 建议指派 (Assigned Agents) | 判定标准 |
| :--- | :--- | :--- |
| **High Impact / Architecture** | `["architect-review", "code-review"]` | 涉及系统核心逻辑、跨模块接口、Schema变更、公共契约。 |
| **Implementation / Logic** | `["code-review"]` | 具体函数实现、内部逻辑优化、不改变接口的重构。 |
| **Config / Tests / Docs** | `["code-review"]` | 配置文件、测试代码、文档、静态资源。 |
| **Deletion** | `[]` (Empty List) | 纯粹的文件删除操作。 |
## 4. Output Format (Strict JSON)
请输出纯 JSON,不要包含 Markdown 标记。
```json
{
"batches": [
{
"id": "batch_01_main_feature",
"description": "用户登录功能核心逻辑与测试(Compact Mode聚合)",
"type": "CORE_LOGIC",
"files": ["src/auth/LoginService.java", "src/auth/User.java", "tests/auth/TestLogin.java", "config/auth.properties"],
"assigned_agents": ["architect-review", "code-review"]
}
]
}
这个策略背后的目标很明确:控制上下文大小,避免单个 Agent 被太多文件拖垮。
但它有一个隐含前提:
文件数量和审查复杂度基本相关。
这个前提在 2026 年已经不够用了。
代码审查里真正重要的边界,不是文件边界,而是影响边界。
一个改动可能只碰了一个文件,但它改的是公共接口、权限判断、金额计算、库存扣减、消息发送、数据库 schema 或跨服务契约。按文件数看,它很小;按影响面看,它很大。
反过来,一个 MR 可能改了 30 个文件,但其中 20 个只是迁移、重命名、测试快照或生成代码。按文件数看,它很大;按影响面看,它未必复杂。
这就是第二代分批策略的问题:
text
diff 文件列表 -> 按文件数量和目录结构分批 -> 派发给 Agent
它只能回答「这些文件应该怎么分组」,不能回答「这次变更真正影响了哪些调用链」。
到了 2026 年,更合理的做法应该是:
text
git diff -> 识别变更符号 -> codeGraph/AST 扩展影响闭包 -> 按影响面分批
也就是说,diff 仍然需要,但它只应该是起点。
真正的分批依据应该来自 codeGraph:
- 这个函数被哪些地方调用?
- 这个类型参与了哪些业务流程?
- 这个接口有没有跨模块或跨服务调用?
- 这个字段有没有进入数据库、缓存、MQ 或外部 API?
- 这个改动对应的测试覆盖在哪里?
- 这个变更是否穿过权限、交易、订单、结算、营销等高风险域?
这样分出来的批次才是「审查批次」,而不是「文件批次」。
举个简单例子。
如果一次改动只修改了 OrderPriceCalculator 的一个方法,传统 diff 分批可能会把它当成一个普通实现文件。但 codeGraph 能看到它被下单、退款、优惠券核销、报表汇总共同依赖。此时它不应该被放进一个普通 Implementation / Logic 批次里,而应该触发架构或业务风险审查。
这不是模型能力问题,而是上下文入口问题。
当系统还在用文件数量作为分批主指标时,它的审查质量上限已经被锁住了。
第二个过时点:飞书集成还是自写脚本
第二代方案里,飞书交互放在最后一步。
architect-driven-review/SKILL.md 的 Phase 4 会调用:
bash
python scripts/lark_tools.py {最终报告得绝对文件路径}
再看 lark_tools.py,它做了三件事:
- 用
UploadAllFileRequest上传本地 Markdown 文件。 - 用
CreateImportTaskRequest创建导入任务。 - 轮询导入结果,拿到飞书文档 URL。
这个脚本解决了一个具体问题:把 review_report_final.md 变成飞书文档。
但到了今天,这种接入方式已经不太合适。
首先,它的能力太窄。AI 审查和飞书的关系不应该只有「上传一篇报告」。
真实研发流程里,飞书至少涉及几类动作:
- 把审查摘要发到群里。
- 把完整报告写成云文档。
- 把问题数量、严重等级、模块分布写入多维表格。
- 对关键问题创建任务或待办。
- 根据项目、分支、提交人、MR 信息做归档。
如果每一种动作都手写一段 SDK 脚本,系统会很快变成一堆不可复用的集成代码。
其次,脚本里还直接写了 APP_ID、APP_SECRET 和 FOLDER_TOKEN。这不是一个可以长期维护的集成边界。鉴权、权限、审计、环境隔离,都应该交给统一工具层,而不是散落在业务脚本里。
脚本里最能说明问题的是这段。这里出于安全原因做了脱敏,但结构和问题不变:
python
if __name__ == "__main__":
# 请替换为你的实际配置
APP_ID = "cli_********"
APP_SECRET = "********"
# 必填:目标文件夹的 token
FOLDER_TOKEN = "********"
if len(sys.argv) < 2:
print("错误: 未提供文件路径参数")
sys.exit(1)
local_file_path = sys.argv[1]
try:
url = upload_and_import_markdown(
APP_ID,
APP_SECRET,
FOLDER_TOKEN,
local_file_path
)
print("最终文档链接:")
print(url)
except Exception as e:
print(f"发生错误: {e}")
sys.exit(1)
这不是说脚本不能工作,而是说它承担了太多平台集成细节。
在当前时间点,飞书交互更应该基于 lark-cli 完成。
这意味着第三代方案里,飞书不再是一个 Python 脚本,而是一组标准工具能力:
text
lark-cli docs -> 创建、更新、读取云文档
lark-cli im -> 发送群消息或卡片
lark-cli base -> 写入多维表格,沉淀统计数据
lark-cli sheets -> 处理表格型数据
lark-cli task -> 生成待办和跟进项
这样做的价值不是少写几百行代码。
真正的价值是把飞书从「审查系统的附属脚本」变成「Agent 可以稳定调用的工具层」。
Code Agent 做审查时,不应该关心飞书上传接口怎么签名、导入任务怎么轮询。它只需要知道:审查完成后,把摘要发到哪里,把报告写到哪里,把结构化问题沉淀到哪里。
工具层越标准,Agent 的职责越干净。
第三个过时点:结果回收还靠轮询文件系统
第二代方案为了避免主控 Agent 上下文爆炸,设计了一个文件系统协议。
每个子 Agent 不直接在对话里输出审查结果,而是把结果写到:
text
temp_res_*.json
主控流程不读取具体内容,只轮询文件数量,判断子任务是否完成。等所有文件都出现后,再把文件路径交给 report-specialist 聚合。
总控 Skill 里对这件事写得很明确:
markdown
### Step 2.1: 全量并发启动 (Launch All)
1. **准备**: 遍历所有批次,确定所有需要启动的 Agent
及其对应的输出文件名(`temp_res_${batch_id}_${agent_suffix}.json`)。
2. **启动**: 连续调用 `Task(subagent_type=..., run_in_background=true)` 启动所有任务。
### Step 2.2: 状态监控与回收 (File-System Polling)
此阶段通过主动轮询文件系统来确认子 Agent 是否完成任务。
```python
import glob
def get_files():
file_list = glob.glob("temp_res_*.json")
return len(file_list), file_list
```
3. **安全约束 (Safety Constraint)**:
* 在此步骤中,**严禁**读取 `temp_res_*.json` 的具体内容。
这在当时是一个务实设计。
它避免了主控 Agent 被大量 JSON 内容淹没,也让多个子 Agent 之间有了一个简单的异步通信方式。
但它的问题也很明显:
- 完成状态依赖文件数量,缺少事件语义。
- 子任务失败、超时、部分写入、格式错误时,主控很难做细粒度判断。
- 中间状态不可观测,只能等所有结果落盘。
- 任务生命周期靠约定维持,而不是由运行时管理。
现在 Claude Code 已经提供了更适合这类场景的 hooks 能力。
官方 hooks 体系里包含 SubagentStart、SubagentStop、PostToolUse、PostToolBatch、TaskCreated、TaskCompleted 等事件。换句话说,今天不必再用「文件是否出现」来推断「子 Agent 是否完成」。
更合理的第三代编排方式应该是:
text
SubagentStart -> 记录审查任务派发
PostToolUse -> 捕获关键工具调用结果
PostToolBatch -> 聚合一批并行工具执行后的状态
SubagentStop -> 回收子 Agent 审查结论
TaskCompleted -> 标记审查单元完成
这会把第二代的「文件轮询型编排」升级成「事件驱动型编排」。
这里要注意,文件输出并不是完全不能存在。
最终报告、审查归档、结构化 issue 数据仍然可以落文件。但文件不应该再承担任务生命周期管理的职责。任务什么时候开始、什么时候结束、是否成功、是否需要重试,这些应该交给 hook 和运行时事件。
这是控制流的升级。
第二代没有错,错的是它的基座变旧了
说到这里,很容易得出一个错误结论:第二代多 Agent 架构不行。
我不这么认为。
第二代真正有价值的部分仍然成立:
file-grouping-specialist把大审查任务拆开。architect-review补足架构视角。code-review负责具体代码问题。report-specialist做最终聚合、去重、打分和结论输出。
报告 Agent 的核心文件也能说明这一点:
markdown
---
name: report-specialist
description: 专用于代码审查流程的终结阶段 (Phase 3)。负责聚合多源审查数据、执行去重逻辑、计算最终评分,并生成标准化的 Markdown 审计报告。
model: sonnet
---
# Identity & Purpose
你是 **Report Specialist**,一位铁面无私的**首席代码审计官**。
你的唯一职责是读取散落在文件系统中的临时审查数据(JSON),将其转化为一份人类可读的、结构严谨的决策报告。你**不进行代码审查**,你只对审查结果进行审计和汇总。
# Critical Protocol (Silent Mode)
为了防止主控 Agent 的上下文爆炸:
1. **Strictly File Output**: 你必须将最终报告写入 `review_report_final.md`。
2. **No Chatter**: 你的最终回复**只能**包含生成文件的绝对路径(例如:`REPORT GENERATED: /path/to/review_report_final.md`)。不要在对话中输出报告内容摘要。
---
# Workflow Instructions
## Step 1: Data Ingestion (数据摄入)
- **Review Data**: 读取所有的 `temp_res_*.json`。
- **Context Data**: 读取 `arch_context.md`。
- **Crucial**: 如果该文件不存在(说明是简单变更跳过了 Phase 1),则假设本次为"常规维护",无需架构上下文。
## Step 2: Aggregation & Logic (聚合与逻辑)
执行以下 Map-Reduce 逻辑:
1. **Grouping**: 按 `file_path` 将所有 Issue 归类。
2. **Deduplication (去重)**: 如果针对同一文件的同一行(`line_number`)有多个 Agent 提出了相似的 Issue,保留 Severity 较高的那个,丢弃重复项。
3. **Scoring (打分模型)**:
- **Base Score**: 100 分。
- **Penalties**:
- **L5 (Blocker)**: 每个扣 15 分 (Fatal)。
- **L4 (Critical)**: 每个扣 5 分。
- **L3 (Major)**: 每个扣 2 分。
- **L2/L1**: 不扣分,仅作为建议。
- **Floor**: 最低分为 0 分。
## Step 3: Verdict Decision (决策判定)
- **REJECTED**: 如果满足以下任一条件:
- 存在任意一个 **L5** 问题。
- 最终得分 < 60 分。
- **PASSED**: 得分 >= 80 且无 L5/L4 问题。
- **PASSED_WITH_WARNINGS**: 其他情况(需要修复 L4 但允许紧急上线,或得分在 60-79 之间)。
## Step 4: Report Generation (报告生成)
按照以下 Markdown 模板生成 `review_report_final.md`。内容必须专业。
---
# [projectName] CodeReview 审查报告
## 1. 基本信息
| 项目名称 | 评审 ID | 评审日期 |
| :--- | :--- | :--- |
| [项目名称] | [CR-YYYYMMDD-NN] | YYYY-MM-DD |
| 提交人 | 审查人 | 目标分支 | 关联 Issue/PR |
| :--- | :--- | :--- | :--- |
| [提交人姓名] | [审查人姓名] | [例如:main, develop] | [#Issue编号] / [#PR编号] |
---
## 2. 变更概述
**本次提交的目的/解决的问题:**
* 简明扼要地描述本次代码变更的核心目标、解决的业务问题或缺陷。
**主要变更范围:**
* 列出受影响的主要模块、文件或组件。
* 示例:
* `src/modules/user/authentication.py`
* `frontend/components/PaymentForm.vue`
* `database/migrations/20231001_add_order_status.sql`
---
## 3. 审查评分(可选量化)
| 审查维度 | 评分 (1-5分) | 说明 |
| :--- | :--- | :--- |
| **代码正确性** | | 功能是否按预期工作?逻辑是否正确?边界情况是否处理? |
| **代码质量** | | 代码是否清晰、简洁、可读?是否符合编码规范? |
| **架构与设计** | | 设计是否合理?是否符合项目架构模式?模块解耦如何? |
| **安全性** | | 是否有潜在的安全风险(如注入、权限、敏感信息泄露)? |
| **性能** | | 是否有性能退化或优化机会(如算法复杂度、数据库查询、内存使用)? |
| **可测试性** | | 代码是否易于测试?测试覆盖率如何?是否添加了相应测试? |
| **可维护性** | | 代码是否易于理解和修改?文档是否齐全? |
| **整体评估** | | 对本次提交的综合评价。 |
*评分说明:5-优秀,4-良好,3-合格,2-有待改进,1-较差*
---
## 4. 详细审查发现
### 4.1 关键问题 (必须修复 - Blocker/Critical)
* **严重缺陷**:导致功能完全失效、系统崩溃、安全漏洞、数据损坏等**必须修复**才能合并的问题。
* `[文件路径:行号]` 问题描述及建议的修复方案。
* *示例:`src/auth/login.js:45` 密码比对前未做哈希处理,存在明文密码泄露风险。应使用 `bcrypt.compare`。*
* **逻辑错误**:核心业务逻辑存在错误。
* `[文件路径:行号]` 描述错误逻辑及正确逻辑应是什么。
### 4.2 主要问题 (建议修复 - Major)
* **代码质量问题**:违反重要编码规范,导致代码难以阅读和维护。
* `[文件路径:行号]` 描述问题,如函数过长、命名不清、圈复杂度高。
* **设计问题**:设计不合理,可能影响未来扩展性或导致重复代码。
* `[文件路径:行号]` 描述设计缺陷及改进建议(如应提取公共方法、使用设计模式)。
* **潜在缺陷**:在当前上下文中可能工作,但在特定条件下(如并发、异常)会出错。
* `[文件路径:行号]` 描述潜在场景和加固建议。
* **性能问题**:存在已知的低效操作(如N+1查询、循环内重复计算)。
* `[文件路径:行号]` 指出问题并建议优化方案。
### 4.3 次要问题 (酌情修复 - Minor)
* **代码风格问题**:格式、缩进、注释等不符合项目规范(可通过自动化工具修复)。
* `[文件路径:行号]` 简单指出,例如"行尾多余空格"、"变量命名应使用驼峰式"。
* **文档问题**:缺少必要的注释、文档更新或日志信息。
* `[文件路径:行号]` 指出需要补充文档的地方。
* **建议改进**:非强制性的优化建议,旨在提升代码质量。
* `[文件路径:行号]` 以提问或建议方式提出,例如"这里是否可以考虑使用 `map` 替代 `forEach` 以提高可读性?"。
---
## 5. 依赖与影响分析
* **数据库变更**:是否有迁移脚本?是否向前/向后兼容?是否需要回滚脚本?
* **API变更**:是否修改了公共API(REST/gRPC)?是否更新了接口文档?是否考虑版本兼容?
* **配置变更**:是否需要新增或修改环境变量、配置文件?
* **第三方依赖**:是否新增或升级了依赖库?版本是否兼容?是否有已知风险?
* **对其它模块的影响**:本次修改是否会影响其他功能或模块?
---
## 6. 安全性检查清单
- [ ] 输入验证与过滤(防XSS、SQL注入、命令注入等)
- [ ] 输出编码/转义
- [ ] 身份认证与授权检查(用户是否有权执行此操作?)
- [ ] 敏感信息处理(日志中是否避免记录密码、密钥、PII?)
- [ ] 依赖库是否有已知安全漏洞?
- [ ] 通信安全(是否使用HTTPS/TLS?)
- [ ] 文件上传安全(如果有)
---
## 7. 总结与建议
**总体评价:**
* 对本次代码变更的最终综合评价。是否推荐合并?
**合并前提:**
* 明确列出**必须修复**的问题(来自4.1节),只有这些问题解决后才可合并。
* 列出建议在合并前修复的主要问题(来自4.2节)。
**后续行动建议:**
* 针对4.3节的问题或未来改进点,建议创建新的Issue或技术债务卡片。
* 是否需要相关人员进行二次审查?
* 其他非技术性建议(如知识分享、更新项目Wiki等)。
---
## 8. 评审结果
| 结果 | ☑ 通过 (Approved) | □ 有条件通过 (Approved with Suggestions) | □ 拒绝 (Rejected) |
| :--- | :--- | :--- | :--- |
**下一步:**
- 如果**通过**:合并代码。
- 如果**有条件通过**:提交者根据审查意见修改后,可自行或通知审查人确认后合并。
- 如果**拒绝**:需根据审查意见进行重大修改,并重新提交评审。
**最终确认:**
| 角色 | 姓名 | 日期 | 签字/备注 |
| :--- | :--- | :--- | :--- |
| 审查人 | | | |
| 提交人 | | | |
| (可选) 复核人 | | | |
### (Template End)
---
# Input Constraints
你只能根据读取到的 JSON 文件和 `arch_context.md` 生成报告。**严禁幻觉**(即:不要编造文件中不存在的代码问题)。如果输入文件为空或无 Issue,直接生成满分报告。
这些角色分工没有过时。
过时的是它们依赖的基座:
- 上下文获取仍然以 diff 文件为中心。
- 工作流编排主要靠 prompt 约束和本地文件协议。
- 外部系统集成靠自写脚本。
- 审查结果主要是生成报告,而不是优先回到 MR 的开发现场。
所以第二代到第三代,不是推翻多 Agent,而是重建多 Agent 的运行环境。
一句话概括:
第二代解决了「谁来审」的问题,第三代要解决「基于什么上下文审、如何可靠编排、结果回到哪里」的问题。
第三代:基于 codeAgent 的审查系统
如果今天重新设计一套 codeAgent 审查系统,我会把它拆成四层。
第一层:上下文获取层
这一层的目标不是把 diff 丢给模型,而是构造一次变更的「影响地图」。
输入应该包括:
git diff:定位显式改动。codeGraph/AST:扩展符号引用、调用链和依赖关系。LSP:补充类型、定义、引用、诊断信息。CI:补充测试、构建、lint、覆盖率结果。需求文档:补充业务目标和验收条件。owner 信息:补充模块负责人和风险归属。
最终输出不再是简单的文件列表,而是类似这样的结构:
json
{
"change_units": [
{
"id": "pricing-impact-001",
"changed_symbols": ["OrderPriceCalculator.calculate"],
"impacted_symbols": [
"OrderSubmitService.submit",
"RefundService.refund",
"CouponSettlementService.settle"
],
"risk_domains": ["order", "payment", "promotion"],
"suggested_agents": ["architect", "code-review", "business-risk"]
}
]
}
这才是第三代的分批输入。
它按影响面组织审查,而不是按文件数量组织审查。
第二层:编排层
第二代用 SKILL.md 写死阶段,再靠文件轮询收敛结果。
第三代仍然可以保留 Skill,但 Skill 不应该承担所有控制流。
更合适的设计是:
- Skill 负责定义审查策略。
- hooks 负责监听生命周期事件。
- Agent runtime 负责任务派发、回收、重试和状态记录。
- MCP 或 CLI 工具负责和外部系统交互。
这样一来,Skill 从「长 prompt 编排器」变成「审查策略入口」。
这会让系统更容易维护。
第三层:执行层
执行层仍然需要多个 Agent,但它们的职责应该更精细。
可以保留第二代里的几个角色:
architect agent:审查跨模块边界、抽象泄漏、依赖方向、数据一致性。code-review agent:审查代码正确性、异常处理、安全、性能和可维护性。report agent:聚合结果、去重、打分、生成报告。
同时可以新增几个更贴近影响面的 Agent:
business-risk agent:结合需求文档判断业务语义是否被破坏。test-impact agent:判断哪些测试应该被补充或重新运行。contract agent:检查 API、消息、数据库 schema、配置项的兼容性。
这些 Agent 不应该都看同一份 diff。它们应该看自己需要的影响面上下文。
架构 Agent 看调用边界和依赖方向,测试 Agent 看覆盖路径和失败用例,业务风险 Agent 看需求和关键流程。
第三代审查系统的重点不是「Agent 越多越好」,而是「每个 Agent 拿到的上下文刚好够用」。
第四层:输出层
第二代最终生成的是 review_report_final.md,再上传成飞书文档。
第三代应该把输出拆成三类:
- MR 现场反馈:把必须修复的问题写回 MR 行级评论或 discussion。
- 飞书协同反馈:把摘要、风险等级、责任人、报告链接发到群里。
- 数据沉淀:把结构化问题写入多维表格或统计系统。
完整报告仍然有价值,但它不应该是唯一出口。
对开发者来说,最重要的反馈应该出现在他正在处理代码的地方。也就是 MR。
飞书适合做通知、归档和协作,不适合替代 MR 里的逐行审查。
从第一代到第三代,真正演进的是什么
回头看这三代,其实演进线很清楚。
第一代是流程接入:
text
GitLab webhook -> diff -> Aily -> 飞书通知 -> 多维表格统计
它解决的是「AI 能不能进入代码审查流程」。
第二代是任务拆分:
text
Skill -> file grouping -> architect agent -> code review agent -> report agent
它解决的是「大模型能不能通过多 Agent 分工审得更稳」。
第三代是工程系统化:
text
diff + codeGraph + LSP + CI + docs
-> impact-aware batching
-> hook-driven orchestration
-> specialized codeAgents
-> MR comments + lark-cli + structured metrics
它要解决的是「AI 审查能不能真正理解影响面,并且稳定嵌入研发系统」。
这三代不是简单替代关系。
第一代让 AI 进入流程,第二代让 AI 分工协作,第三代让 AI 基于工程事实工作。
写在最后
这次技术演进梳理给我的最大启发,不是「某个 Agent 应该怎么写 prompt」,也不是「某个模型是不是更强」。
真正的问题在于:AI 工具一旦进入工程系统,它的瓶颈很快就不再只是模型。
瓶颈会转移到三个地方:
- 它如何获得上下文。
- 它如何编排任务。
- 它如何把结果送回真实工作流。
第二代 AI Code Review 系统看起来已经很复杂:有 Skill,有多个子 Agent,有报告生成,有飞书上传。
但到了 2026 年,这些还不够。
如果上下文仍然来自 diff 文件列表,它就无法真正理解影响面。
如果编排仍然靠文件轮询,它就很难成为可靠的工程系统。
如果飞书交互仍然靠自写 SDK 脚本,它就很难和企业协同平台长期演进。
所以第三代 codeAgent 审查系统的关键,不是再多加几个 Agent。
关键是把审查从「看文件」升级成「看影响面」,把编排从「等文件」升级成「听事件」,把集成从「写脚本」升级成「用标准工具」。