Loading...
Loading...
Spawn specialized sub-agents with context handoff for complex multi-phase tasks. Enables expertise delegation within a session with automatic context merging and depth limiting to prevent infinite loops.
npx skill4agent add winsorllc/upgraded-carnival agent-delegate┌─────────────────────────────────────────┐
│ Parent Agent Session │
│ "Review this entire codebase" │
└──────────────┬──────────────────────────┘
│ delegate()
▼
┌──────────────────────┐
│ Delegate Context │
│ - Parent prompt │
│ - Relevant files │
│ - Parent's analysis │
│ - Depth counter │
└──────────┬───────────┘
│
┌──────────▼───────────┐
│ Sub-Agent Session │
│ "Check for security │
│ vulnerabilities" │
└──────────┬───────────┘
│
▼
┌──────────────────────┐
│ Structured Result │
│ { findings, files, │
│ severity, next } │
└──────────────────────┘# Delegate a subtask with default settings
node /job/.pi/skills/agent-delegate/delegate.js \
--task "Review for security vulnerabilities"
# Delegate with custom system prompt
node /job/.pi/skills/agent-delegate/delegate.js \
--task "Analyze performance bottlenecks" \
--system "You are a performance optimization expert" \
--model "claude-sonnet-4-5-20250929"
# Delegate with file context
node /job/.pi/skills/agent-delegate/delegate.js \
--task "Review this code" \
--files "./src/auth.ts ./src/api.ts"
# Parallel delegation (spawn multiple agents)
node /job/.pi/skills/agent-delegate/delegate.js \
--parallel \
--task-1 "Check for security issues" \
--task-2 "Check for performance issues" \
--task-3 "Check for code style"
# With parent context
node /job/.pi/skills/agent-delegate/delegate.js \
--task "Build on this analysis" \
--context "./parent_analysis.md"| Option | Description | Default |
|---|---|---|
| The task prompt for the delegate | Required |
| Custom system prompt for delegate | Inherited from parent |
| LLM model to use | |
| Space-separated file paths to include | None |
| Parent analysis/context file | None |
| Enable parallel delegation mode | false |
| Task N for parallel mode (1-5) | N/A |
| Current delegation depth (internal) | 0 |
| Maximum recursion depth | 3 |
| Output file for results | stdout |
| Verbose logging | false |
DELEGATE_DEPTH{
delegateTask: "Check for SQL injection vulnerabilities",
parentAnalysis: "Found 3 database queries in auth.ts...",
relevantFiles: [
{ path: "./src/auth.ts", content: "..." },
{ path: "./src/db.ts", content: "..." }
],
delegationDepth: 1,
maxDepth: 3,
parentSession: "job/abc123"
}{
"delegateTask": "Check for SQL injection vulnerabilities",
"delegationDepth": 1,
"status": "complete",
"findings": [
{
"file": "./src/auth.ts",
"line": 42,
"severity": "high",
"issue": "Potential SQL injection via unsanitized input",
"codeSnippet": "const query = `SELECT * FROM users WHERE id = ${userId}`;",
"recommendation": "Use parameterized queries"
}
],
"summary": "Found 2 high-severity SQL injection risks",
"filesAnalyzed": 5,
"nextSteps": [
"Review ./src/api.ts for similar patterns",
"Add input validation layer"
],
"allowFurtherDelegation": true
}# Parent: "Review this PR comprehensively"
# Delegate security review
node /job/.pi/skills/agent-delegate/delegate.js \
--task "Review for security vulnerabilities: SQL injection, XSS, auth bypass, CSRF" \
--system "You are a security engineer with 10 years experience. Focus on OWASP Top 10." \
--files "./src/auth.ts ./src/api.ts ./src/db.ts" \
--output security_review.json
# Delegate performance review
node /job/.pi/skills/agent-delegate/delegate.js \
--task "Review for performance issues: N+1 queries, memory leaks, inefficient algorithms" \
--system "You are a performance optimization expert. Identify bottlenecks and optimization opportunities." \
--files "./src/db.ts ./src/cache.ts" \
--output performance_review.json
# Merge results
node /job/.pi/skills/agent-delegate/merge.js \
--inputs security_review.json performance_review.json \
--output combined_review.md# Parallel research delegation
node /job/.pi/skills/agent-delegate/delegate.js \
--parallel \
--task-1 "Research market trends for AI agents in enterprise" \
--task-2 "Identify top 10 competitors and their key features" \
--task-3 "Summarize customer pain points from Reddit, Hacker News, Twitter" \
--system-1 "You are a market analyst" \
--system-2 "You are a competitive intelligence specialist" \
--system-3 "You are a user research expert" \
--output-1 market_trends.json \
--output-2 competitor_analysis.json \
--output-3 user_pain_points.json# Phase 1: Analysis
node /job/.pi/skills/agent-delegate/delegate.js \
--task "Analyze this bug report and identify root cause candidates" \
--context "./bug_report.md" \
--output analysis.json
# Phase 2: Solution Design (builds on Phase 1)
node /job/.pi/skills/agent-delegate/delegate.js \
--task "Design a fix for the identified root cause" \
--context "./analysis.json" \
--system "You are a senior engineer specializing in system design" \
--output solution.json
# Phase 3: Implementation Plan
node /job/.pi/skills/agent-delegate/delegate.js \
--task "Create a step-by-step implementation plan with code examples" \
--context "./solution.json" \
--system "You are a tech lead who writes clear implementation guides" \
--output implementation_plan.md# job.md
I need to review this pull request comprehensively.
## Step 1: Delegate Security Review
First, let me spawn a security specialist:
\`\`\`bash
node /job/.pi/skills/agent-delegate/delegate.js \
--task "Review PR #{{pr_number}} for security vulnerabilities" \
--system "You are a security engineer focused on OWASP Top 10" \
--files "./src/auth.ts ./src/api.ts"
\`\`\`
## Step 2: Delegate Performance Review
Now a performance specialist:
\`\`\`bash
node /job/.pi/skills/agent-delegate/delegate.js \
--task "Review PR #{{pr_number}} for performance issues" \
--system "You are a performance optimization expert"
\`\`\`
## Step 3: Synthesize Results
Now I'll merge the findings...--parallelnode /job/.pi/skills/agent-delegate/delegate.js \
--parallel \
--task-1 "Security review" \
--task-2 "Performance review" \
--task-3 "Style review" \
--system-1 "Security expert persona..." \
--system-2 "Performance expert persona..." \
--system-3 "Style expert persona..." \
--output-1 security.json \
--output-2 performance.json \
--output-3 style.json \
--synthesize "Combine all reviews into unified report"{
"error": "MAX_DEPTH_EXCEEDED",
"message": "Cannot delegate further: maximum depth (3) reached",
"currentDepth": 3,
"recommendation": "Complete this subtask directly without further delegation"
}{
"error": "DELEGATE_FAILED",
"message": "Sub-agent failed to complete task",
"task": "Check for SQL injection",
"reason": "LLM API error: rate limit exceeded",
"retryable": true
}Parent: "Comprehensive code review"
├─ Delegate 1: Security review (OWASP focus)
├─ Delegate 2: Performance review (bottleneck focus)
└─ Delegate 3: Style review (best practices focus)Parent: "Review code"
├─ Delegate 1: "Find bugs"
│ └─ Delegate 2: "Find security bugs" # Too similar!
└─ Delegate 3: "Find security issues" # Duplicate!# Run unit tests
node /job/.pi/skills/agent-delegate/tests/unit.test.js
# Run integration test
node /job/.pi/skills/agent-delegate/tests/integration.test.js
# Test depth limiting
node /job/.pi/skills/agent-delegate/tests/depth.test.js| File | Purpose |
|---|---|
| Main delegation executor |
| Merge multiple delegate results |
| Parallel delegation coordinator |
| Context packaging utilities |
| Unit and integration tests |
| This documentation |
| Variable | Description | Default |
|---|---|---|
| Current delegation depth | 0 |
| Maximum recursion depth | 3 |
| Max parallel delegates | 5 |
| API key for Claude | Required |