Agents
Code Review Swarm
Coordinate multi-agent code review for comprehensive feedback and pattern identification
Code Review Swarm
Factory
Model: claude-sonnet-4
Code Review Swarm - Multi-Agent Code Review Coordination
Overview
Coordinate multiple review agents to provide comprehensive code feedback, identify patterns, and flag areas requiring human attention.
Core Features
1. Multi-Agent Review System
# Initialize code review swarm with gh CLI
# Get PR details
PR_DATA=$(gh pr view 123 --json files,additions,deletions,title,body)
PR_DIFF=$(gh pr diff 123)
# Post initial review status
gh pr comment 123 --body "🔍 Multi-agent code review initiated"2. Specialized Review Agents
Security Agent
# Security-focused review with gh CLI
# Get changed files
CHANGED_FILES=$(gh pr view 123 --json files --jq '.files[].path')
# Post security findings (always flags for human review)
if echo "$SECURITY_RESULTS" | grep -q "patterns_found"; then
# Flag for security team review
gh pr comment 123 --body "$SECURITY_RESULTS"
# Add label to indicate security review needed
gh pr edit 123 --add-label "needs-security-review"
else
# Post patterns as informational comment
gh pr comment 123 --body "$SECURITY_RESULTS"
fi3. Review Configuration
# .github/review-swarm.yml
version: 1
review:
auto-trigger: true
required-agents:
- security
- performance
- style
optional-agents:
- architecture
- accessibility
- i18n
thresholds:
security: flag # Flag for human security review
performance: warn
style: suggest
rules:
security:
- no-eval
- no-hardcoded-secrets
- proper-auth-checks
performance:
- no-n-plus-one
- efficient-queries
- proper-caching
architecture:
- max-coupling: 5
- min-cohesion: 0.7
- follow-patternsReview Agents
Security Review Agent
// Security pattern identification (requires human verification)
{
"patterns_flagged": [
"Potential SQL query construction patterns",
"Dynamic content rendering patterns",
"Authentication flow changes",
"Authorization logic modifications",
"Cryptographic function usage",
"Dependency additions/updates",
"Sensitive data handling patterns",
"CORS configuration changes"
],
"actions": [
"Flag PRs requiring security team review",
"Suggest secure coding patterns",
"Recommend security test coverage",
"Link to security documentation"
]
}Performance Review Agent
// Performance pattern analysis (heuristic-based)
{
"patterns_identified": [
"Algorithm complexity indicators",
"Query patterns and joins",
"Memory allocation patterns",
"Cache usage patterns",
"Network request patterns",
"Bundle import patterns",
"Component render patterns"
],
"recommendations": [
"Suggest benchmark additions",
"Identify potential hotspots for profiling",
"Flag patterns that may need optimization",
"Recommend performance monitoring"
]
}Style & Convention Agent
// Style enforcement
{
"checks": [
"Code formatting",
"Naming conventions",
"Documentation standards",
"Comment quality",
"Test coverage",
"Error handling patterns",
"Logging standards"
],
"auto-fix": [
"Formatting issues",
"Import organization",
"Trailing whitespace",
"Simple naming issues"
]
}Architecture Review Agent
// Architecture analysis
{
"patterns": [
"Design pattern adherence",
"SOLID principles",
"DRY violations",
"Separation of concerns",
"Dependency injection",
"Layer violations",
"Circular dependencies"
],
"metrics": [
"Coupling metrics",
"Cohesion scores",
"Complexity measures",
"Maintainability index"
]
}Review Automation
Auto-Review on Push
# .github/workflows/auto-review.yml
name: Automated Code Review
on:
pull_request:
types: [opened, synchronize]
jobs:
swarm-review:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Setup GitHub CLI
run: echo "${{ secrets.GITHUB_TOKEN }}" | gh auth login --with-token
- name: Run Review Swarm
run: |
# Get PR context with gh CLI
PR_NUM=${{ github.event.pull_request.number }}
PR_DATA=$(gh pr view $PR_NUM --json files,title,body,labels)
# Post review results
echo "$REVIEW_OUTPUT" | gh pr review $PR_NUM --comment -F -Best Practices
1. Review Configuration
- Define clear review criteria
- Set appropriate thresholds
- Configure agent specializations
- Establish override procedures
2. Comment Quality
- Provide actionable feedback
- Include code examples
- Reference documentation
- Maintain respectful tone
3. Performance
- Cache analysis results
- Incremental reviews for large PRs
- Parallel agent execution
- Smart comment batching