A sophisticated AI meta-agent that analyzes codebases and dynamically generates optimized sub-agents specialized for that specific project.
This implements the Agent Factory pattern with hierarchical orchestration:
- Analyze any codebase to understand its structure, languages, frameworks, and patterns
- Generate specialized sub-agents tailored to that project's specific tech stack
- Export ready-to-use agent definitions directly into the analyzed project
- Orchestrate these agents to perform complex multi-step tasks
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Meta-Agent Orchestrator β
β βββββββββββββββ βββββββββββββββ βββββββββββββββββββββββ β
β β Project β β Agent β β Task β β
β β Analyzer ββββ Factory ββββ Orchestrator β β
β βββββββββββββββ βββββββββββββββ βββββββββββββββββββββββ β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β
ββββββββββββββββββββΌβββββββββββββββββββ
βΌ βΌ βΌ
βββββββββββββββ βββββββββββββββ βββββββββββββββ
β Code β β Framework β β Security β
β Reviewer β β Specialist β β Auditor β
βββββββββββββββ βββββββββββββββ βββββββββββββββ
# Analyze any project - agents are auto-exported to the project folder
python test_analyzer.py /path/to/your/project
# Output: /path/to/your/project/yourproject_agents.py- Language Detection: Identifies all programming languages used
- Framework Detection: Recognizes 30+ frameworks (React, Next.js, Vue, Django, FastAPI, etc.)
- Architecture Patterns: Detects MVC, component-based, service layers, etc.
- Tooling Detection: Build tools, testing frameworks, CI/CD, Docker
Each generated agent is customized with:
- Project-specific context in its system prompt
- Appropriate tools for its role
- Optimal model tier (opus/sonnet/haiku)
- Framework and language expertise
Agents are automatically exported to the analyzed project's folder as a Python file ready for use with Claude Agent SDK.
| Agent | Purpose | Model | Priority |
|---|---|---|---|
code-reviewer |
Quality, security, best practices | sonnet | high |
framework-specialist |
Framework-specific expertise | sonnet | high |
test-writer |
Unit/integration tests | sonnet | medium |
security-auditor |
Vulnerability scanning | opus | high |
performance-optimizer |
Profiling, optimization | sonnet | medium |
documentation-writer |
README, API docs | haiku | low |
# Install Claude Code (optional, for full SDK features)
npm install -g @anthropic-ai/claude-code
# Set API key
export ANTHROPIC_API_KEY=your-key-here# Just run - no dependencies needed!
python test_analyzer.py /path/to/project# Python
pip install -r requirements.txt
# TypeScript
npm install# Analyze project and auto-export agents to project folder
python test_analyzer.py /path/to/project
# Custom output path
python test_analyzer.py /path/to/project -o /custom/path/agents.pyπ Analyzing: /path/to/my-nextjs-app
======================================================================
PROJECT ANALYSIS: my-nextjs-app
======================================================================
Path: /path/to/my-nextjs-app
Type: fullstack-web
Primary Language: TypeScript
Total Files: 156
Total Lines: 12,450
Languages:
TypeScript 89 files ββββββββββββββββββββ
JavaScript 23 files βββββββββββ
CSS 18 files βββββββββ
...
Frameworks: Next.js, React, Tailwind CSS, Prisma
Patterns: App Router, Component-Based, API Layer
Features:
Tests: β
CI/CD: β
Docker: β
Docs: β
======================================================================
GENERATED AGENTS (6)
======================================================================
π΄ code-reviewer
Expert TypeScript code reviewer for Next.js, React...
Model: sonnet | Tools: Read, Grep, Glob
...
======================================================================
EXPORT COMPLETE
======================================================================
π¦ File: /path/to/my-nextjs-app/my_nextjs_app_agents.py
π Agents: 6 specialized sub-agents generated
π― Optimized for: my-nextjs-app (fullstack-web)
# 1. Import the generated agents
from my_nextjs_app_agents import agents, PROJECT_PROFILE
# 2. Create options with agents
from claude_agent_sdk import query, ClaudeAgentOptions
options = ClaudeAgentOptions(
agents=agents,
allowed_tools=["Read", "Write", "Edit", "Bash", "Grep", "Glob", "Task"],
cwd="/path/to/my-nextjs-app",
permission_mode="acceptEdits"
)
# 3. Run queries - Claude auto-delegates to specialists
async for msg in query("Review auth code for security", options=options):
print(msg) # security-auditor handles this automatically
# 4. Or access individual agents
from my_nextjs_app_agents import code_reviewer, security_auditor# Python
python src/meta_agent.py work /path/to/project
# TypeScript
npx ts-node src/meta-agent.ts work /path/to/projectThe analyzer scans your codebase to detect:
{
"name": "my-nextjs-app",
"primary_language": "TypeScript",
"frameworks": ["Next.js", "React", "Tailwind CSS", "Prisma"],
"project_type": "fullstack-web",
"architecture_patterns": ["App Router", "Component-Based", "API Layer"],
"has_tests": True,
"has_ci": True,
"total_files": 156,
"total_lines": 12450
}Based on the profile, specialized agents are generated:
agents = {
"code-reviewer": AgentDefinition(
description="Expert TypeScript code reviewer for Next.js, React...",
prompt="""You are an expert TypeScript code reviewer.
Project type: fullstack-web
Frameworks: Next.js, React, Tailwind CSS, Prisma""",
tools=["Read", "Grep", "Glob"],
model="sonnet"
),
"security-auditor": AgentDefinition(
description="Security specialist for TypeScript/Next.js...",
prompt="""You are a security expert for TypeScript applications...""",
tools=["Read", "Grep", "Glob", "Bash"],
model="opus" # Strongest model for security
),
# ... more agents
}The meta-agent delegates to specialists:
User: "Add authentication with NextAuth"
Meta-Agent:
1. Identifies this needs framework-specialist
2. Delegates implementation to framework-specialist
3. Delegates security review to security-auditor
4. Delegates test creation to test-writer
5. Aggregates results
project-analyzer-agent/
βββ CLAUDE.md # Agent instructions for Claude Code
βββ README.md # This file
βββ package.json # Node.js config
βββ requirements.txt # Python dependencies
βββ test_analyzer.py # Standalone analyzer (no SDK required)
βββ src/
β βββ meta_agent.py # Python implementation (requires SDK)
β βββ meta-agent.ts # TypeScript implementation (requires SDK)
βββ tools/
βββ project_analyzer.py # MCP analysis tools
JavaScript/TypeScript:
- React, Next.js, Vue.js, Nuxt.js, Angular, Svelte
- Express.js, Fastify, Hono
- Tailwind CSS, Prisma, tRPC, GraphQL
Python:
- Django, Flask, FastAPI
- Streamlit, LangChain
- PyTorch, TensorFlow
- SQLAlchemy, Pydantic
| Type | Indicators |
|---|---|
fullstack-web |
Next.js, Nuxt.js |
frontend-spa |
React, Vue, Angular |
backend-api |
Express, FastAPI, Flask |
ml-ai |
PyTorch, TensorFlow |
monorepo |
nx.json, turbo.json, lerna.json |
- Component-Based (
src/components) - Pages Router (
src/pages) - App Router (
app/) - Service Layer (
src/services) - API Layer (
src/api) - MVC (
src/controllers,src/models) - Agent Architecture (
agents/)
Dynamic creation of agents based on runtime analysis, inspired by Microsoft's AI Agent Design Patterns.
Manager-worker pattern where the meta-agent decomposes tasks and delegates to specialized sub-agents, based on AgentOrchestra research.
Agents receive project-specific context in their prompts, following patterns from LLM Agent surveys.
# In test_analyzer.py or meta_agent.py
def generate_agents(profile: dict) -> dict:
agents = {}
# Add custom agent
if "graphql" in [f.lower() for f in profile.get("frameworks", [])]:
agents["graphql-specialist"] = {
"description": f"GraphQL expert for {profile['primary_language']}",
"tools": ["Read", "Edit", "Write", "Grep", "Glob"],
"model": "sonnet",
"priority": "high",
"prompt": f"You are a GraphQL expert..."
}
return agents# In test_analyzer.py
FRAMEWORK_PACKAGES["my-framework"] = "My Framework"
PYTHON_FRAMEWORKS["my-lib"] = "My Library"
ARCHITECTURE_PATTERNS["src/my-pattern"] = "My Pattern"| Model | Use Case | Cost |
|---|---|---|
| opus | Security audits, complex decisions | High |
| sonnet | Code review, implementation, testing | Medium |
| haiku | Documentation, simple tasks | Low |
MIT