use subagent tool meta instead of calling the func
This commit is contained in:
parent
66fe98fe7d
commit
eb77a589b4
7 changed files with 57 additions and 40 deletions
|
|
@ -389,6 +389,8 @@ export const services = {
|
|||
gitAiIntegration: gitAiIntegrationService,
|
||||
} as const;
|
||||
|
||||
export type ServicesType = typeof services;
|
||||
|
||||
// Export the service container for advanced usage
|
||||
export { serviceContainer };
|
||||
|
||||
|
|
|
|||
|
|
@ -1,12 +1,9 @@
|
|||
import type { ChatHistoryItem } from "core";
|
||||
|
||||
import {
|
||||
ModelServiceState,
|
||||
SERVICE_NAMES,
|
||||
serviceContainer,
|
||||
services,
|
||||
} from "../services/index.js";
|
||||
import { ToolPermissionServiceState } from "../services/ToolPermissionService.js";
|
||||
import type { ServicesType } from "../services/index.js";
|
||||
import type { ServiceContainer } from "../services/ServiceContainer.js";
|
||||
import type { ToolPermissionServiceState } from "../services/ToolPermissionService.js";
|
||||
import { ModelServiceState, SERVICE_NAMES } from "../services/types.js";
|
||||
import { streamChatResponse } from "../stream/streamChatResponse.js";
|
||||
import { escapeEvents } from "../util/cli.js";
|
||||
import { logger } from "../util/logger.js";
|
||||
|
|
@ -20,6 +17,8 @@ export interface SubAgentExecutionOptions {
|
|||
parentSessionId: string;
|
||||
abortController: AbortController;
|
||||
onOutputUpdate?: (output: string) => void;
|
||||
services: ServicesType;
|
||||
serviceContainer: ServiceContainer;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -61,13 +60,20 @@ async function buildAgentSystemMessage(
|
|||
export async function executeSubAgent(
|
||||
options: SubAgentExecutionOptions,
|
||||
): Promise<SubAgentResult> {
|
||||
const {
|
||||
agent: subAgent,
|
||||
prompt,
|
||||
abortController,
|
||||
onOutputUpdate,
|
||||
services,
|
||||
serviceContainer,
|
||||
} = options;
|
||||
|
||||
const mainAgentPermissionsState =
|
||||
await serviceContainer.get<ToolPermissionServiceState>(
|
||||
SERVICE_NAMES.TOOL_PERMISSIONS,
|
||||
);
|
||||
|
||||
const { agent: subAgent, prompt, abortController, onOutputUpdate } = options;
|
||||
|
||||
try {
|
||||
logger.debug("Starting subagent execution", {
|
||||
agent: subAgent.model?.name,
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import { ModelServiceState } from "../services/index.js";
|
||||
import { ModelService } from "../services/ModelService.js";
|
||||
import type { ModelServiceState } from "../services/types.js";
|
||||
|
||||
/**
|
||||
* Get an agent by name
|
||||
|
|
|
|||
|
|
@ -7,13 +7,14 @@ import { readFileTool } from "./readFile.js";
|
|||
import { reportFailureTool } from "./reportFailure.js";
|
||||
import { runTerminalCommandTool } from "./runTerminalCommand.js";
|
||||
import { searchCodeTool } from "./searchCode.js";
|
||||
import { subagentTool } from "./subagent.js";
|
||||
import { SUBAGENT_TOOL_META } from "./subagent.js";
|
||||
import type { Tool } from "./types.js";
|
||||
import { uploadArtifactTool } from "./uploadArtifact.js";
|
||||
import { writeChecklistTool } from "./writeChecklist.js";
|
||||
import { writeFileTool } from "./writeFile.js";
|
||||
|
||||
// putting in here for circular import issue
|
||||
export const ALL_BUILT_IN_TOOLS = [
|
||||
export const ALL_BUILT_IN_TOOLS: Tool[] = [
|
||||
readFileTool,
|
||||
editTool,
|
||||
multiEditTool,
|
||||
|
|
@ -23,7 +24,7 @@ export const ALL_BUILT_IN_TOOLS = [
|
|||
runTerminalCommandTool,
|
||||
fetchTool,
|
||||
writeChecklistTool,
|
||||
subagentTool(),
|
||||
SUBAGENT_TOOL_META,
|
||||
exitTool,
|
||||
reportFailureTool,
|
||||
uploadArtifactTool,
|
||||
|
|
|
|||
|
|
@ -127,6 +127,8 @@ export async function getAllAvailableTools(
|
|||
tools.push(
|
||||
subagentTool({
|
||||
modelServiceState: modelState,
|
||||
services,
|
||||
serviceContainer,
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
import { executeSubAgent } from "../subagent/executor.js";
|
||||
import {
|
||||
generateSubagentToolDescription,
|
||||
getSubagent,
|
||||
|
|
@ -5,17 +6,14 @@ import {
|
|||
} from "../subagent/get-agents.js";
|
||||
import { logger } from "../util/logger.js";
|
||||
|
||||
import { GetTool } from "./types.js";
|
||||
import { GetTool, Tool } from "./types.js";
|
||||
|
||||
export const subagentTool: GetTool = (params) => ({
|
||||
export const SUBAGENT_TOOL_META: Tool = {
|
||||
name: "Subagent",
|
||||
displayName: "Subagent",
|
||||
description: params
|
||||
? generateSubagentToolDescription(params.modelServiceState)
|
||||
: "Use a subagent to handle a specialized task.",
|
||||
description: "Use a subagent to handle a specialized task.",
|
||||
readonly: false,
|
||||
isBuiltIn: true,
|
||||
|
||||
parameters: {
|
||||
type: "object",
|
||||
required: ["description", "prompt", "subagent_name"],
|
||||
|
|
@ -28,6 +26,24 @@ export const subagentTool: GetTool = (params) => ({
|
|||
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: GetTool = (params) => ({
|
||||
...SUBAGENT_TOOL_META,
|
||||
|
||||
description: generateSubagentToolDescription(params.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: ${
|
||||
|
|
@ -38,18 +54,6 @@ export const subagentTool: GetTool = (params) => ({
|
|||
},
|
||||
|
||||
preprocess: async (args: any) => {
|
||||
if (!params) {
|
||||
return {
|
||||
args,
|
||||
preview: [
|
||||
{
|
||||
type: "text",
|
||||
content: "Subagent not found",
|
||||
},
|
||||
],
|
||||
};
|
||||
}
|
||||
|
||||
const { description, subagent_name } = args;
|
||||
|
||||
const agent = getSubagent(params.modelServiceState, subagent_name);
|
||||
|
|
@ -73,8 +77,6 @@ export const subagentTool: GetTool = (params) => ({
|
|||
},
|
||||
|
||||
run: async (args: any, context?: { toolCallId: string }) => {
|
||||
if (!params) return "";
|
||||
|
||||
const { prompt, subagent_name } = args;
|
||||
|
||||
logger.debug("subagent args", { args, context });
|
||||
|
|
@ -85,10 +87,8 @@ export const subagentTool: GetTool = (params) => ({
|
|||
throw new Error(`Unknown agent type: ${subagent_name}`);
|
||||
}
|
||||
|
||||
const { executeSubAgent } = await import("../subagent/executor.js");
|
||||
const { services } = await import("../services/index.js");
|
||||
|
||||
const parentSessionId = services.chatHistory.getSessionId();
|
||||
const chatHistoryService = params.services.chatHistory;
|
||||
const parentSessionId = chatHistoryService.getSessionId();
|
||||
if (!parentSessionId) {
|
||||
throw new Error("No active session found");
|
||||
}
|
||||
|
|
@ -99,10 +99,12 @@ export const subagentTool: GetTool = (params) => ({
|
|||
prompt,
|
||||
parentSessionId,
|
||||
abortController: new AbortController(),
|
||||
services: params.services,
|
||||
serviceContainer: params.serviceContainer,
|
||||
onOutputUpdate: context?.toolCallId
|
||||
? (output: string) => {
|
||||
try {
|
||||
services.chatHistory.addToolResult(
|
||||
chatHistoryService.addToolResult(
|
||||
context.toolCallId,
|
||||
output,
|
||||
"calling",
|
||||
|
|
|
|||
|
|
@ -1,6 +1,8 @@
|
|||
import type { ToolPolicy } from "@continuedev/terminal-security";
|
||||
|
||||
import { ModelServiceState } from "src/services/types.js";
|
||||
import type { ServicesType } from "src/services/index.js";
|
||||
import type { ServiceContainer } from "src/services/ServiceContainer.js";
|
||||
import type { ModelServiceState } from "src/services/types.js";
|
||||
|
||||
// JSON Schema compatible parameter definition
|
||||
export interface ParameterSchema {
|
||||
|
|
@ -49,8 +51,10 @@ export interface Tool {
|
|||
) => ToolPolicy;
|
||||
}
|
||||
|
||||
export type GetTool = (params?: {
|
||||
export type GetTool = (params: {
|
||||
modelServiceState: ModelServiceState;
|
||||
services: ServicesType;
|
||||
serviceContainer: ServiceContainer;
|
||||
}) => Tool;
|
||||
|
||||
export interface ToolCall {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue