decouple allbuiltins and subagent tool meta
This commit is contained in:
parent
c2d928d483
commit
d55a13894f
5 changed files with 126 additions and 123 deletions
28
extensions/cli/src/subagent/index.ts
Normal file
28
extensions/cli/src/subagent/index.ts
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
import { Tool } from "../tools/types.js";
|
||||
|
||||
export const SUBAGENT_TOOL_META: Tool = {
|
||||
name: "Subagent",
|
||||
displayName: "Subagent",
|
||||
description: "Use a subagent to handle a specialized task.",
|
||||
readonly: false,
|
||||
isBuiltIn: true,
|
||||
parameters: {
|
||||
type: "object",
|
||||
required: ["description", "prompt", "subagent_name"],
|
||||
properties: {
|
||||
description: {
|
||||
type: "string",
|
||||
description: "A short description of the task",
|
||||
},
|
||||
prompt: {
|
||||
type: "string",
|
||||
description: "The task for the agent to perform",
|
||||
},
|
||||
subagent_name: {
|
||||
type: "string",
|
||||
description: "The type of specialized agent to use for this task.",
|
||||
},
|
||||
},
|
||||
},
|
||||
run: async () => "",
|
||||
};
|
||||
|
|
@ -1,3 +1,5 @@
|
|||
import { SUBAGENT_TOOL_META } from "../subagent/index.js";
|
||||
|
||||
import { editTool } from "./edit.js";
|
||||
import { exitTool } from "./exit.js";
|
||||
import { fetchTool } from "./fetch.js";
|
||||
|
|
@ -7,7 +9,6 @@ import { readFileTool } from "./readFile.js";
|
|||
import { reportFailureTool } from "./reportFailure.js";
|
||||
import { runTerminalCommandTool } from "./runTerminalCommand.js";
|
||||
import { searchCodeTool } from "./searchCode.js";
|
||||
import { SUBAGENT_TOOL_META } from "./subagent.js";
|
||||
import type { Tool } from "./types.js";
|
||||
import { uploadArtifactTool } from "./uploadArtifact.js";
|
||||
import { writeChecklistTool } from "./writeChecklist.js";
|
||||
|
|
|
|||
|
|
@ -124,11 +124,7 @@ export async function getAllAvailableTools(
|
|||
}
|
||||
|
||||
if (isBetaSubagentToolEnabled()) {
|
||||
tools.push(
|
||||
subagentTool({
|
||||
modelServiceState: modelState,
|
||||
}),
|
||||
);
|
||||
tools.push(await subagentTool());
|
||||
}
|
||||
|
||||
const mcpState = await serviceContainer.get<MCPServiceState>(
|
||||
|
|
|
|||
|
|
@ -1,133 +1,117 @@
|
|||
import { serviceContainer } from "../services/ServiceContainer.js";
|
||||
import { ModelServiceState, SERVICE_NAMES } from "../services/types.js";
|
||||
import {
|
||||
generateSubagentToolDescription,
|
||||
getSubagent,
|
||||
getAgentNames as getSubagentNames,
|
||||
} from "../subagent/get-agents.js";
|
||||
import { SUBAGENT_TOOL_META } from "../subagent/index.js";
|
||||
import { logger } from "../util/logger.js";
|
||||
|
||||
import { GetTool, Tool } from "./types.js";
|
||||
import { Tool } from "./types.js";
|
||||
|
||||
export const SUBAGENT_TOOL_META: Tool = {
|
||||
name: "Subagent",
|
||||
displayName: "Subagent",
|
||||
description: "Use a subagent to handle a specialized task.",
|
||||
readonly: false,
|
||||
isBuiltIn: true,
|
||||
parameters: {
|
||||
type: "object",
|
||||
required: ["description", "prompt", "subagent_name"],
|
||||
properties: {
|
||||
description: {
|
||||
type: "string",
|
||||
description: "A short description of the task",
|
||||
},
|
||||
prompt: {
|
||||
type: "string",
|
||||
description: "The task for the agent to perform",
|
||||
},
|
||||
subagent_name: {
|
||||
type: "string",
|
||||
description: "The type of specialized agent to use for this task.",
|
||||
},
|
||||
},
|
||||
},
|
||||
run: async () => "",
|
||||
};
|
||||
export const subagentTool = async (): Promise<Tool> => {
|
||||
const modelServiceState = await serviceContainer.get<ModelServiceState>(
|
||||
SERVICE_NAMES.MODEL,
|
||||
);
|
||||
|
||||
export const subagentTool: GetTool = (params) => ({
|
||||
...SUBAGENT_TOOL_META,
|
||||
return {
|
||||
...SUBAGENT_TOOL_META,
|
||||
|
||||
description: generateSubagentToolDescription(params.modelServiceState),
|
||||
description: generateSubagentToolDescription(modelServiceState),
|
||||
|
||||
parameters: {
|
||||
...SUBAGENT_TOOL_META.parameters,
|
||||
properties: {
|
||||
...SUBAGENT_TOOL_META.parameters.properties,
|
||||
subagent_name: {
|
||||
type: "string",
|
||||
description: `The type of specialized agent to use for this task. Available agents: ${
|
||||
params ? getSubagentNames(params.modelServiceState).join(", ") : ""
|
||||
}`,
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
preprocess: async (args: any) => {
|
||||
const { description, subagent_name } = args;
|
||||
|
||||
const agent = getSubagent(params.modelServiceState, subagent_name);
|
||||
if (!agent) {
|
||||
throw new Error(
|
||||
`Unknown agent type: ${subagent_name}. Available agents: ${getSubagentNames(
|
||||
params.modelServiceState,
|
||||
).join(", ")}`,
|
||||
);
|
||||
}
|
||||
|
||||
return {
|
||||
args,
|
||||
preview: [
|
||||
{
|
||||
type: "text",
|
||||
content: `Spawning ${agent.model.name} to: ${description}`,
|
||||
parameters: {
|
||||
...SUBAGENT_TOOL_META.parameters,
|
||||
properties: {
|
||||
...SUBAGENT_TOOL_META.parameters.properties,
|
||||
subagent_name: {
|
||||
type: "string",
|
||||
description: `The type of specialized agent to use for this task. Available agents: ${
|
||||
modelServiceState
|
||||
? getSubagentNames(modelServiceState).join(", ")
|
||||
: ""
|
||||
}`,
|
||||
},
|
||||
],
|
||||
};
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
run: async (args: any, context?: { toolCallId: string }) => {
|
||||
const { prompt, subagent_name } = args;
|
||||
preprocess: async (args: any) => {
|
||||
const { description, subagent_name } = args;
|
||||
|
||||
logger.debug("subagent args", { args, context });
|
||||
const agent = getSubagent(modelServiceState, subagent_name);
|
||||
if (!agent) {
|
||||
throw new Error(
|
||||
`Unknown agent type: ${subagent_name}. Available agents: ${getSubagentNames(
|
||||
modelServiceState,
|
||||
).join(", ")}`,
|
||||
);
|
||||
}
|
||||
|
||||
// get agent configuration
|
||||
const agent = getSubagent(params.modelServiceState, subagent_name);
|
||||
if (!agent) {
|
||||
throw new Error(`Unknown agent type: ${subagent_name}`);
|
||||
}
|
||||
return {
|
||||
args,
|
||||
preview: [
|
||||
{
|
||||
type: "text",
|
||||
content: `Spawning ${agent.model.name} to: ${description}`,
|
||||
},
|
||||
],
|
||||
};
|
||||
},
|
||||
|
||||
// Dynamically import to avoid circular dependency and passing repeated params
|
||||
const { executeSubAgent } = await import("../subagent/executor.js");
|
||||
const { services } = await import("../services/index.js");
|
||||
run: async (args: any, context?: { toolCallId: string }) => {
|
||||
const { prompt, subagent_name } = args;
|
||||
|
||||
const chatHistoryService = services.chatHistory;
|
||||
const parentSessionId = chatHistoryService.getSessionId();
|
||||
if (!parentSessionId) {
|
||||
throw new Error("No active session found");
|
||||
}
|
||||
logger.debug("subagent args", { args, context });
|
||||
|
||||
// Execute subagent with output streaming
|
||||
const result = await executeSubAgent({
|
||||
agent,
|
||||
prompt,
|
||||
parentSessionId,
|
||||
abortController: new AbortController(),
|
||||
onOutputUpdate: context?.toolCallId
|
||||
? (output: string) => {
|
||||
try {
|
||||
chatHistoryService.addToolResult(
|
||||
context.toolCallId,
|
||||
output,
|
||||
"calling",
|
||||
);
|
||||
} catch {
|
||||
// Ignore errors during streaming updates
|
||||
// get agent configuration
|
||||
const agent = getSubagent(modelServiceState, subagent_name);
|
||||
if (!agent) {
|
||||
throw new Error(`Unknown agent type: ${subagent_name}`);
|
||||
}
|
||||
|
||||
// Dynamically import to avoid circular dependency and passing repeated params
|
||||
const { executeSubAgent } = await import("../subagent/executor.js");
|
||||
const { services } = await import("../services/index.js");
|
||||
|
||||
const chatHistoryService = services.chatHistory;
|
||||
const parentSessionId = chatHistoryService.getSessionId();
|
||||
if (!parentSessionId) {
|
||||
throw new Error("No active session found");
|
||||
}
|
||||
|
||||
// Execute subagent with output streaming
|
||||
const result = await executeSubAgent({
|
||||
agent,
|
||||
prompt,
|
||||
parentSessionId,
|
||||
abortController: new AbortController(),
|
||||
onOutputUpdate: context?.toolCallId
|
||||
? (output: string) => {
|
||||
try {
|
||||
chatHistoryService.addToolResult(
|
||||
context.toolCallId,
|
||||
output,
|
||||
"calling",
|
||||
);
|
||||
} catch {
|
||||
// Ignore errors during streaming updates
|
||||
}
|
||||
}
|
||||
}
|
||||
: undefined,
|
||||
});
|
||||
: undefined,
|
||||
});
|
||||
|
||||
logger.debug("subagent result", { result });
|
||||
logger.debug("subagent result", { result });
|
||||
|
||||
const output = [
|
||||
result.response,
|
||||
"<task_metadata>",
|
||||
`status: ${result.success ? "completed" : "failed"}`,
|
||||
"</task_metadata>",
|
||||
]
|
||||
.filter(Boolean)
|
||||
.join("\n");
|
||||
const output = [
|
||||
result.response,
|
||||
"<task_metadata>",
|
||||
`status: ${result.success ? "completed" : "failed"}`,
|
||||
"</task_metadata>",
|
||||
]
|
||||
.filter(Boolean)
|
||||
.join("\n");
|
||||
|
||||
return output;
|
||||
},
|
||||
});
|
||||
return output;
|
||||
},
|
||||
};
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,7 +1,5 @@
|
|||
import type { ToolPolicy } from "@continuedev/terminal-security";
|
||||
|
||||
import type { ModelServiceState } from "src/services/types.js";
|
||||
|
||||
// JSON Schema compatible parameter definition
|
||||
export interface ParameterSchema {
|
||||
type: string;
|
||||
|
|
@ -49,10 +47,6 @@ export interface Tool {
|
|||
) => ToolPolicy;
|
||||
}
|
||||
|
||||
export type GetTool = (params: {
|
||||
modelServiceState: ModelServiceState;
|
||||
}) => Tool;
|
||||
|
||||
export interface ToolCall {
|
||||
id: string;
|
||||
name: string;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue