delegate-task
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseDelegate Task Skill
任务委派Skill
Delegate subtasks to specialized AI agents, enabling multi-agent collaboration. Each sub-agent can have different configurations, tools, and expertise.
将子任务委派给专业AI Agent,实现多Agent协作。每个子Agent可拥有不同的配置、工具和专业能力。
When to Use
适用场景
✅ USE this skill when:
- Complex multi-step workflows
- Specialized expertise needed (code review, research, summarization)
- Parallel task execution
- Separation of concerns
❌ DON'T use this skill when:
- Simple single-step tasks
- Tasks requiring deep context from parent
- Tight-loop iterations
✅ 以下场景适用本Skill:
- 复杂的多步骤工作流
- 需要专业能力(代码审查、调研、总结)
- 并行任务执行
- 关注点分离
❌ 以下场景不适用本Skill:
- 简单的单步骤任务
- 需要父级深度上下文的任务
- 紧密循环迭代任务
Architecture
架构
┌─────────────────┐
│ Parent Agent │
│ (Orchestrator) │
└────────┬────────┘
│ Delegations
▼
┌─────────────────────────────────────────────┐
│ ┌──────────┐ ┌──────────┐ ┌──────────┐ │
│ │ Research │ │ Code │ │ Review │ │
│ │ Agent │ │ Agent │ │ Agent │ │
│ └──────────┘ └──────────┘ └──────────┘ │
└─────────────────────────────────────────────┘┌─────────────────┐
│ Parent Agent │
│ (Orchestrator) │
└────────┬────────┘
│ Delegations
▼
┌─────────────────────────────────────────────┐
│ ┌──────────┐ ┌──────────┐ ┌──────────┐ │
│ │ Research │ │ Code │ │ Review │ │
│ │ Agent │ │ Agent │ │ Agent │ │
│ └──────────┘ └──────────┘ └──────────┘ │
└─────────────────────────────────────────────┘Agent Configurations
Agent配置
Define sub-agents in your configuration:
json
{
"delegations": {
"research": {
"model": "claude-sonnet-4-5-20250929",
"tools": ["brave-search", "web-fetch", "summarize"],
"systemPrompt": "You are a research specialist..."
},
"coder": {
"model": "claude-sonnet-4-5-20250929",
"tools": ["vscode", "git-structured", "content-search"],
"systemPrompt": "You are an expert software engineer..."
},
"reviewer": {
"model": "claude-3-5-sonnet",
"tools": ["vscode", "content-search"],
"systemPrompt": "You are a code reviewer focusing on quality..."
}
}
}在配置中定义子Agent:
json
{
"delegations": {
"research": {
"model": "claude-sonnet-4-5-20250929",
"tools": ["brave-search", "web-fetch", "summarize"],
"systemPrompt": "You are a research specialist..."
},
"coder": {
"model": "claude-sonnet-4-5-20250929",
"tools": ["vscode", "git-structured", "content-search"],
"systemPrompt": "You are an expert software engineer..."
},
"reviewer": {
"model": "claude-3-5-sonnet",
"tools": ["vscode", "content-search"],
"systemPrompt": "You are a code reviewer focusing on quality..."
}
}
}Usage
使用方法
JavaScript API
JavaScript API
javascript
const { delegate } = require('/job/.pi/skills/delegate-task/delegate.js');
// Simple delegation
const result = await delegate('research', {
task: 'Find the latest developments in AI agents',
context: 'Focus on multi-agent systems'
});
console.log(result.response);
console.log(result.metadata);
// Delegation with custom config
const codeResult = await delegate('coder', {
task: 'Implement a REST API endpoint',
context: 'Use Express.js, add validation',
timeout: 300000 // 5 minutes
});
// Parallel delegations
const [research, analysis] = await Promise.all([
delegate('research', { task: 'Research topic X' }),
delegate('analysis', { task: 'Analyze data Y' })
]);javascript
const { delegate } = require('/job/.pi/skills/delegate-task/delegate.js');
// 简单委派
const result = await delegate('research', {
task: 'Find the latest developments in AI agents',
context: 'Focus on multi-agent systems'
});
console.log(result.response);
console.log(result.metadata);
// 自定义配置委派
const codeResult = await delegate('coder', {
task: 'Implement a REST API endpoint',
context: 'Use Express.js, add validation',
timeout: 300000 // 5分钟
});
// 并行委派
const [research, analysis] = await Promise.all([
delegate('research', { task: 'Research topic X' }),
delegate('analysis', { task: 'Analyze data Y' })
]);Bash
Bash
bash
node /job/.pi/skills/delegate-task/delegate.js \
--agent research \
--task "Find AI agent frameworks" \
--context "Compare features and pricing"bash
node /job/.pi/skills/delegate-task/delegate.js \
--agent research \
--task "Find AI agent frameworks" \
--context "Compare features and pricing"API
API
javascript
delegate(agentName, options)Options:
- - Task description (required)
task - - Additional context
context - - Timeout in ms (default: 300000)
timeout - - Max response tokens
maxTokens - - Override agent model
model - - Enable streaming (default: false)
stream
Returns:
javascript
{
success: true,
agent: "research",
response: "I found 3 main frameworks...",
metadata: {
model: "claude-sonnet-4-5-20250929",
tokensUsed: 1542,
duration: 12300,
citations: ["https://..."]
},
conversationId: "conv_abc123"
}javascript
delegate(agentName, options)参数选项:
- - 任务描述(必填)
task - - 额外上下文
context - - 超时时间(毫秒,默认:300000)
timeout - - 最大响应令牌数
maxTokens - - 覆盖Agent模型
model - - 启用流式响应(默认:false)
stream
返回结果:
javascript
{
success: true,
agent: "research",
response: "I found 3 main frameworks...",
metadata: {
model: "claude-sonnet-4-5-20250929",
tokensUsed: 1542,
duration: 12300,
citations: ["https://..."]
},
conversationId: "conv_abc123"
}Delegation Chain
委派链
Supports nested delegation (up to 5 levels):
javascript
// Parent delegates to researcher
const research = await delegate('research', {
task: 'Compare CI/CD solutions'
});
// Researcher can further delegate
const analysis = await delegate('analysis', {
task: 'Analyze cost differences',
parentTask: research.response
});支持嵌套委派(最多5层):
javascript
// 父级委派给调研Agent
const research = await delegate('research', {
task: 'Compare CI/CD solutions'
});
// 调研Agent可进一步委派
const analysis = await delegate('analysis', {
task: 'Analyze cost differences',
parentTask: research.response
});Multi-Agent Workflow Example
多Agent工作流示例
javascript
async function buildFeature(featureName) {
// 1. Research existing implementations
const research = await delegate('research', {
task: `Research how ${featureName} is implemented elsewhere`,
context: 'Look at open source projects'
});
// 2. Plan architecture
const plan = await delegate('architect', {
task: 'Design the architecture',
context: research.response
});
// 3. Implement code
const code = await delegate('coder', {
task: 'Implement the feature',
context: `${research.response}\n\nArchitecture: ${plan.response}`
});
// 4. Review code
const review = await delegate('reviewer', {
task: 'Review the implementation',
context: code.response
});
return { research, plan, code, review };
}javascript
async function buildFeature(featureName) {
// 1. 调研现有实现方案
const research = await delegate('research', {
task: `Research how ${featureName} is implemented elsewhere`,
context: 'Look at open source projects'
});
// 2. 规划架构
const plan = await delegate('architect', {
task: 'Design the architecture',
context: research.response
});
// 3. 实现代码
const code = await delegate('coder', {
task: 'Implement the feature',
context: `${research.response}\n\nArchitecture: ${plan.response}`
});
// 4. 审查代码
const review = await delegate('reviewer', {
task: 'Review the implementation',
context: code.response
});
return { research, plan, code, review };
}Error Handling
错误处理
javascript
try {
const result = await delegate('coder', {
task: 'Write a function'
});
console.log(result.response);
} catch (error) {
if (error.code === 'AGENT_NOT_FOUND') {
console.error('Unknown agent');
} else if (error.code === 'TIMEOUT') {
console.error('Agent took too long');
} else if (error.code === 'DEPTH_EXCEEDED') {
console.error('Delegation chain too deep');
}
}javascript
try {
const result = await delegate('coder', {
task: 'Write a function'
});
console.log(result.response);
} catch (error) {
if (error.code === 'AGENT_NOT_FOUND') {
console.error('Unknown agent');
} else if (error.code === 'TIMEOUT') {
console.error('Agent took too long');
} else if (error.code === 'DEPTH_EXCEEDED') {
console.error('Delegation chain too deep');
}
}Best Practices
最佳实践
- Clear task descriptions - Be specific about what you want
- Provide context - Include relevant background
- Set timeouts - Prevent infinite loops
- Chain thoughtfully - Don't over-nest
- Handle errors - Graceful degradation
- 明确任务描述 - 清晰说明需求
- 提供上下文 - 包含相关背景信息
- 设置超时 - 避免无限循环
- 合理链式委派 - 不要过度嵌套
- 处理错误 - 优雅降级
Agent-to-Agent Communication
Agent间通信
javascript
// Pass data between agents
const context = JSON.stringify({
originalTask: task,
researchFindings: research.data,
constraints: ['Must use TypeScript', 'No external deps']
});
await delegate('coder', {
task: 'Implement based on research',
context
});javascript
// 在Agent间传递数据
const context = JSON.stringify({
originalTask: task,
researchFindings: research.data,
constraints: ['Must use TypeScript', 'No external deps']
});
await delegate('coder', {
task: 'Implement based on research',
context
});