MCPcopy Create free account
hub / github.com/scriptscat/scriptcat / createSubAgentTool

Function createSubAgentTool

src/app/service/agent/core/tools/sub_agent.ts:56–81  ·  view source on GitHub ↗
(params: {
  runSubAgent: (options: SubAgentRunOptions) => Promise<SubAgentRunResult>;
})

Source from the content-addressed store, hash-verified

54};
55
56export 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}

Callers 2

sub_agent.test.tsFile · 0.90

Calls 2

requireStringFunction · 0.90
runSubAgentMethod · 0.80

Tested by

no test coverage detected