const BUILTIN_AGENTS = {
'context-gatherer': {
description: '分析代码库,识别相关文件',
systemPrompt: CONTEXT_GATHERER_PROMPT,
tools: ['readCode', 'fileSearch', 'grepSearch'],
mode: 'sync',
},
'custom-agent-creator': {
description: '创建自定义 Agent',
systemPrompt: AGENT_CREATOR_PROMPT,
tools: ['fsWrite', 'readFile'],
mode: 'sync',
},
'general-task-execution': {
description: '通用任务执行',
systemPrompt: GENERAL_PROMPT,
tools: '*',
mode: 'sync',
},
};// .kiro/agents/code-reviewer.json
{
"name": "code-reviewer",
"description": "Review code for best practices",
"systemPrompt": "You are an expert code reviewer...",
"tools": ["readCode", "getDiagnostics", "grepSearch"],
"mode": "sync"
}const result = await invokeSubAgent({
name: 'context-gatherer',
prompt: 'Find authentication related files',
});
// result 包含 Agent 的完整输出
console.log(result.output);const agentId = await invokeSubAgent({
name: 'general-task-execution',
prompt: 'Run all tests',
mode: 'async',
});
// 继续其他工作
// ...
// 稍后检查结果
const result = await getAgentResult(agentId);// 主 Agent: 修复 bug
// 子 Agent: 分析相关代码
const files = await invokeSubAgent({
name: 'context-gatherer',
prompt: '找出与登录功能相关的所有文件',
});
// 主 Agent 继续处理这些文件
for (const file of files) {
await analyzeAndFix(file);
}// 同时运行多个 Agent
const [tests, lint, build] = await Promise.all([
invokeSubAgent({ name: 'test-runner', prompt: 'Run tests' }),
invokeSubAgent({ name: 'linter', prompt: 'Run linter' }),
invokeSubAgent({ name: 'builder', prompt: 'Build project' }),
]);// 使用专门的 Agent
const review = await invokeSubAgent({
name: 'code-reviewer',
prompt: 'Review this PR for security issues',
contextFiles: [{ path: 'src/auth.ts' }],
});