(params: {
runSubAgent: (options: SubAgentRunOptions) => Promise<SubAgentRunResult>;
})
| 54 | }; |
| 55 | |
| 56 | export function createSubAgentTool(params: { |
| 57 | runSubAgent: (options: SubAgentRunOptions) => Promise<SubAgentRunResult>; |
| 58 | }): { |
| 59 | definition: ToolDefinition; |
| 60 | executor: ToolExecutor; |
| 61 | } { |
| 62 | const executor: ToolExecutor = { |
| 63 | execute: async (args: Record<string, unknown>) => { |
| 64 | const prompt = requireString(args, "prompt"); |
| 65 | const description = (args.description as string) || "Sub-agent task"; |
| 66 | const type = args.type as string | undefined; |
| 67 | const tabId = args.tab_id as number | undefined; |
| 68 | |
| 69 | const result = await params.runSubAgent({ prompt, description, type, tabId }); |
| 70 | |
| 71 | // 返回结构化结果,附带子代理执行详情用于持久化 |
| 72 | const content = `[agentId: ${result.agentId}]\n\n${result.result}`; |
| 73 | if (result.details) { |
| 74 | return { content, subAgentDetails: result.details }; |
| 75 | } |
| 76 | return content; |
| 77 | }, |
| 78 | }; |
| 79 | |
| 80 | return { definition: SUB_AGENT_DEFINITION, executor }; |
| 81 | } |
no test coverage detected