From e6c04e91760bed451360f5186df1330bca2a5636 Mon Sep 17 00:00:00 2001 From: uinstinct <61635505+uinstinct@users.noreply.github.com> Date: Wed, 25 Feb 2026 11:50:53 +0530 Subject: [PATCH 1/8] remove unnecessary lint --- extensions/cli/src/subagent/executor.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/extensions/cli/src/subagent/executor.ts b/extensions/cli/src/subagent/executor.ts index 1580e7f7f9d..bb0982f0038 100644 --- a/extensions/cli/src/subagent/executor.ts +++ b/extensions/cli/src/subagent/executor.ts @@ -54,7 +54,6 @@ async function buildAgentSystemMessage( /** * Execute a subagent in a child session */ -// eslint-disable-next-line complexity export async function executeSubAgent( options: SubAgentExecutionOptions, ): Promise { From ce5cf78419e9dda17cf559c8db7b9b2cae102434 Mon Sep 17 00:00:00 2001 From: uinstinct <61635505+uinstinct@users.noreply.github.com> Date: Wed, 25 Feb 2026 18:57:27 +0530 Subject: [PATCH 2/8] add tool result in chat history for subagent when chathistoryservice is disabled in subagent, manually update the last tool state with output and status --- extensions/cli/src/stream/handleToolCalls.ts | 32 ++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/extensions/cli/src/stream/handleToolCalls.ts b/extensions/cli/src/stream/handleToolCalls.ts index bc5d99176e0..f4f477da8bf 100644 --- a/extensions/cli/src/stream/handleToolCalls.ts +++ b/extensions/cli/src/stream/handleToolCalls.ts @@ -147,13 +147,41 @@ export async function handleToolCalls( // Execute the valid preprocessed tool calls // Note: executeStreamedToolCalls adds tool results to toolCallStates via - // services.chatHistory.addToolResult() internally - const { hasRejection } = await executeStreamedToolCalls( + // services.chatHistory.addToolResult() internally when service is available + const { hasRejection, chatHistoryEntries } = await executeStreamedToolCalls( preprocessedCalls, callbacks, isHeadless, ); + // When ChatHistoryService is disabled in subagent execution, + // manually update the local chatHistory array with tool results + if (!useService && chatHistoryEntries.length > 0) { + const lastAssistantIndex = chatHistory.findLastIndex( + (item) => item.message.role === "assistant" && item.toolCallStates, + ); + if ( + lastAssistantIndex >= 0 && + chatHistory[lastAssistantIndex].toolCallStates + ) { + for (const entry of chatHistoryEntries) { + const toolState = chatHistory[lastAssistantIndex].toolCallStates!.find( + (ts) => ts.toolCallId === entry.tool_call_id, + ); + if (toolState) { + toolState.status = entry.status; + toolState.output = [ + { + content: String(entry.content) || "", + name: "Tool Result", + description: "Tool execution result", + }, + ]; + } + } + } + } + if (isHeadless && hasRejection) { logger.debug( "Tool call rejected in headless mode - returning current content", From 4125fb22e339fee401dd99f8a395790de0fd0a97 Mon Sep 17 00:00:00 2001 From: uinstinct <61635505+uinstinct@users.noreply.github.com> Date: Wed, 25 Feb 2026 18:58:57 +0530 Subject: [PATCH 3/8] prevent nested subagent execution --- extensions/cli/src/subagent/executor.ts | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/extensions/cli/src/subagent/executor.ts b/extensions/cli/src/subagent/executor.ts index bb0982f0038..2b6ebd794fc 100644 --- a/extensions/cli/src/subagent/executor.ts +++ b/extensions/cli/src/subagent/executor.ts @@ -8,6 +8,8 @@ import { streamChatResponse } from "../stream/streamChatResponse.js"; import { escapeEvents } from "../util/cli.js"; import { logger } from "../util/logger.js"; +let isInsideSubagent = false; + /** * Options for executing a subagent */ @@ -57,6 +59,14 @@ async function buildAgentSystemMessage( export async function executeSubAgent( options: SubAgentExecutionOptions, ): Promise { + if (isInsideSubagent) { + return { + success: false, + response: "", + error: "Nested subagent invocation is not allowed", + }; + } + const { agent: subAgent, prompt, abortController, onOutputUpdate } = options; const mainAgentPermissionsState = @@ -64,6 +74,8 @@ export async function executeSubAgent( SERVICE_NAMES.TOOL_PERMISSIONS, ); + isInsideSubagent = true; + try { logger.debug("Starting subagent execution", { agent: subAgent.model?.name, @@ -167,6 +179,8 @@ export async function executeSubAgent( ? lastMessage.message.content : ""; + logger.debug("debug1 subagent chathistory", { chatHistory }); + logger.debug("Subagent execution completed", { agent: model?.name, responseLength: response.length, @@ -208,5 +222,7 @@ export async function executeSubAgent( response: "", error: error.message, }; + } finally { + isInsideSubagent = false; } } From bbcf04e687dfc0279ab41d3ab93e638355f59a41 Mon Sep 17 00:00:00 2001 From: uinstinct <61635505+uinstinct@users.noreply.github.com> Date: Wed, 25 Feb 2026 19:19:07 +0530 Subject: [PATCH 4/8] add builtin subagents explorer and code reviewer --- .../cli/src/subagent/builtInSubagents.ts | 90 +++++++++++++++++++ extensions/cli/src/subagent/executor.ts | 2 - extensions/cli/src/subagent/get-agents.ts | 44 ++++++--- 3 files changed, 123 insertions(+), 13 deletions(-) create mode 100644 extensions/cli/src/subagent/builtInSubagents.ts diff --git a/extensions/cli/src/subagent/builtInSubagents.ts b/extensions/cli/src/subagent/builtInSubagents.ts new file mode 100644 index 00000000000..0c60d5f5ad6 --- /dev/null +++ b/extensions/cli/src/subagent/builtInSubagents.ts @@ -0,0 +1,90 @@ +import type { ModelConfig } from "@continuedev/config-yaml"; + +import { logger } from "src/util/logger.js"; + +export interface BuiltInSubagent { + name: string; + systemPrompt: string; + model: string; +} + +export const NAVIGATOR_SUBAGENT: BuiltInSubagent = { + name: "navigator", + model: "claude-haiku-4-5", + systemPrompt: `You are a Codebase Navigator subagent specialized in exploring, searching, and mapping large codebases. + +When to use: + + Use this subagent whenever you need to explore or find or understand a codebase or a folder. + +When navigating a codebase, you will: + +1. **Locate Relevant Code**: Use file and code search tools to find the most relevant files, modules, functions, and types. Prefer a small, high-signal set of locations over exhaustive listings. + +2. **Trace Behavior and Dependencies**: Follow call chains, imports, and data flow to understand how the relevant pieces interact, including upstream/downstream dependencies and important side effects. + +3. **Map the Codebase for Others**: Build a concise mental map: which components are core, which are helpers, where entry points live, and how configuration or environment affects behavior. + +Your output should be concise and actionable, starting with a brief summary of what you found and listing the key files/paths, functions, symbols, and important relationships or flows between them in plain language. If you cannot find something, describe what you searched for, where you looked, and suggest next places or strategies to investigate.`, +}; + +export const CODE_REVIEWER_SUBAGENT: BuiltInSubagent = { + name: "code-reviewer", + model: "claude-sonnet-4-6", + systemPrompt: `You are a Senior Code Reviewer with expertise in software architecture, design patterns, and best practices. Your role is to review completed project steps against original plans and ensure code quality standards are met. + +When to use: + + Use this subagent whenever you are requested to review code, or after a feature or refactor is implemented and you want a structured review against the original plan and code quality standards. + +When reviewing completed work, you will: + +1. **Plan Alignment Analysis**: Compare implementation against original plans, identify justified vs problematic deviations, and verify all planned functionality is complete + +2. **Code Quality Assessment**: Review adherence to patterns, error handling, type safety, naming conventions, test coverage, and potential security or performance issues + +3. **Architecture and Design Review**: Ensure proper architectural patterns, separation of concerns, loose coupling, system integration, and scalability considerations + +4. **Documentation and Standards**: Verify appropriate comments, function documentation, file headers, and adherence to project-specific coding standards + +5. **Issue Identification and Recommendations**: Categorize issues as Critical/Important/Suggestions with specific examples, actionable recommendations, and code examples when helpful + +Your output should be structured, actionable, and focused on helping maintain high code quality while ensuring project goals are met. Be thorough but concise, and always provide constructive feedback that helps improve both the current implementation and future development practices.`, +}; + +export const BUILT_IN_SUBAGENTS: BuiltInSubagent[] = [ + NAVIGATOR_SUBAGENT, + CODE_REVIEWER_SUBAGENT, +]; + +export function createBuiltInSubagentModel( + subagent: BuiltInSubagent, + baseModel: ModelConfig, +): ModelConfig { + return { + ...baseModel, + name: subagent.name, + model: subagent.model, + roles: ["subagent"], + chatOptions: { + ...baseModel.chatOptions, + baseSystemMessage: subagent.systemPrompt, + }, + }; +} + +export function isLocalAnthropicModel(model: ModelConfig | null): boolean { + if (!model) { + return false; + } + + const isAnthropic = model.provider === "anthropic"; + const hasDirectApiKey = + typeof model.apiKey === "string" && model.apiKey.length > 0; + + logger.debug("subagent_enabled_for_anthropic", { + enabled: isAnthropic && hasDirectApiKey, + }); + + return isAnthropic && hasDirectApiKey; +} diff --git a/extensions/cli/src/subagent/executor.ts b/extensions/cli/src/subagent/executor.ts index 2b6ebd794fc..3790250bb7e 100644 --- a/extensions/cli/src/subagent/executor.ts +++ b/extensions/cli/src/subagent/executor.ts @@ -179,8 +179,6 @@ export async function executeSubAgent( ? lastMessage.message.content : ""; - logger.debug("debug1 subagent chathistory", { chatHistory }); - logger.debug("Subagent execution completed", { agent: model?.name, responseLength: response.length, diff --git a/extensions/cli/src/subagent/get-agents.ts b/extensions/cli/src/subagent/get-agents.ts index 9abdc2d3adc..872f551036a 100644 --- a/extensions/cli/src/subagent/get-agents.ts +++ b/extensions/cli/src/subagent/get-agents.ts @@ -1,24 +1,48 @@ +import { createLlmApi } from "../config.js"; import { ModelService } from "../services/ModelService.js"; import type { ModelServiceState } from "../services/types.js"; -/** - * Get an agent by name - */ +import { + BUILT_IN_SUBAGENTS, + createBuiltInSubagentModel, + isLocalAnthropicModel, +} from "./builtInSubagents.js"; + +function getAllSubagentModels(modelState: ModelServiceState) { + const configSubagents = ModelService.getSubagentModels(modelState); + + if (!isLocalAnthropicModel(modelState.model)) { + return configSubagents; + } + + const builtInSubagents = BUILT_IN_SUBAGENTS.map((subagent) => { + const subagentModel = createBuiltInSubagentModel( + subagent, + modelState.model!, + ); + return { + llmApi: createLlmApi(subagentModel, modelState.authConfig), + model: subagentModel, + assistant: modelState.assistant, + authConfig: modelState.authConfig, + }; + }); + + return [...configSubagents, ...builtInSubagents]; +} + export function getSubagent(modelState: ModelServiceState, name: string) { return ( - ModelService.getSubagentModels(modelState).find( + getAllSubagentModels(modelState).find( (model) => model.model.name === name, ) ?? null ); } -/** - * Generate dynamic tool description listing available agents - */ export function generateSubagentToolDescription( modelState: ModelServiceState, ): string { - const agentList = ModelService.getSubagentModels(modelState) + const agentList = getAllSubagentModels(modelState) .map( (subagentModel) => ` - ${subagentModel.model.name}: ${subagentModel.model.chatOptions?.baseSystemMessage}`, @@ -34,7 +58,5 @@ ${agentList} } export function getAgentNames(modelState: ModelServiceState): string[] { - return ModelService.getSubagentModels(modelState).map( - (model) => model.model.name, - ); + return getAllSubagentModels(modelState).map((model) => model.model.name); } From d5676dbe7d889136abd838fb20760a45e89d31d0 Mon Sep 17 00:00:00 2001 From: uinstinct <61635505+uinstinct@users.noreply.github.com> Date: Wed, 25 Feb 2026 19:22:56 +0530 Subject: [PATCH 5/8] refine subagent tool description --- extensions/cli/src/subagent/get-agents.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/extensions/cli/src/subagent/get-agents.ts b/extensions/cli/src/subagent/get-agents.ts index 872f551036a..563ac9820ee 100644 --- a/extensions/cli/src/subagent/get-agents.ts +++ b/extensions/cli/src/subagent/get-agents.ts @@ -49,8 +49,11 @@ export function generateSubagentToolDescription( ) .join("\n"); - // todo: refine this prompt later - return `Launch a specialized subagent to handle a specific task. + return `Launch an autonomous specialized subagent to handle a specific task. + +You have the independence to make decisions within you scope. You should focus on the specific task given by the main agent. + +Remember: You are part of a larger system. Your specialized focus helps the main agent handle multiple concerns efficiently. Here are the available subagents: ${agentList} From e19a8b1ffe84ef7ad3986848d282fcf46cdb570b Mon Sep 17 00:00:00 2001 From: uinstinct <61635505+uinstinct@users.noreply.github.com> Date: Wed, 25 Feb 2026 19:26:25 +0530 Subject: [PATCH 6/8] put subagent tool out of beta --- extensions/cli/src/index.ts | 4 ---- extensions/cli/src/services/index.ts | 8 +------- extensions/cli/src/tools/index.tsx | 9 ++------- extensions/cli/src/tools/toolsConfig.ts | 9 --------- 4 files changed, 3 insertions(+), 27 deletions(-) diff --git a/extensions/cli/src/index.ts b/extensions/cli/src/index.ts index a3a718e3efd..f251a427ee9 100644 --- a/extensions/cli/src/index.ts +++ b/extensions/cli/src/index.ts @@ -200,10 +200,6 @@ addCommonOptions(program) ) .option("--resume", "Resume from last session") .option("--fork ", "Fork from an existing session ID") - .option( - "--beta-subagent-tool", - "Enable beta Subagent tool for invoking subagents", - ) .action(async (prompt, options) => { // Telemetry: record command invocation await posthogService.capture("cliCommand", { command: "cn" }); diff --git a/extensions/cli/src/services/index.ts b/extensions/cli/src/services/index.ts index c1807e55c0e..9be4c98e498 100644 --- a/extensions/cli/src/services/index.ts +++ b/extensions/cli/src/services/index.ts @@ -1,9 +1,6 @@ import { loadAuthConfig } from "../auth/workos.js"; import { initializeWithOnboarding } from "../onboarding.js"; -import { - setBetaSubagentToolEnabled, - setBetaUploadArtifactToolEnabled, -} from "../tools/toolsConfig.js"; +import { setBetaUploadArtifactToolEnabled } from "../tools/toolsConfig.js"; import { logger } from "../util/logger.js"; import { AgentFileService } from "./AgentFileService.js"; @@ -66,9 +63,6 @@ export async function initializeServices(initOptions: ServiceInitOptions = {}) { if (commandOptions.betaUploadArtifactTool) { setBetaUploadArtifactToolEnabled(true); } - if (commandOptions.betaSubagentTool) { - setBetaSubagentToolEnabled(true); - } // Handle onboarding for TUI mode (headless: false) unless explicitly skipped if (!initOptions.headless && !initOptions.skipOnboarding) { const authConfig = loadAuthConfig(); diff --git a/extensions/cli/src/tools/index.tsx b/extensions/cli/src/tools/index.tsx index eb10d870d62..127038d93c1 100644 --- a/extensions/cli/src/tools/index.tsx +++ b/extensions/cli/src/tools/index.tsx @@ -31,10 +31,7 @@ import { runTerminalCommandTool } from "./runTerminalCommand.js"; import { checkIfRipgrepIsInstalled, searchCodeTool } from "./searchCode.js"; import { skillsTool } from "./skills.js"; import { subagentTool } from "./subagent.js"; -import { - isBetaSubagentToolEnabled, - isBetaUploadArtifactToolEnabled, -} from "./toolsConfig.js"; +import { isBetaUploadArtifactToolEnabled } from "./toolsConfig.js"; import { type Tool, type ToolCall, @@ -127,9 +124,7 @@ export async function getAllAvailableTools( tools.push(exitTool); } - if (isBetaSubagentToolEnabled()) { - tools.push(await subagentTool()); - } + tools.push(await subagentTool()); tools.push(await skillsTool()); diff --git a/extensions/cli/src/tools/toolsConfig.ts b/extensions/cli/src/tools/toolsConfig.ts index e9a2e02330b..b1703a545bc 100644 --- a/extensions/cli/src/tools/toolsConfig.ts +++ b/extensions/cli/src/tools/toolsConfig.ts @@ -4,7 +4,6 @@ */ let betaUploadArtifactToolEnabled = false; -let betaSubagentToolEnabled = false; export function setBetaUploadArtifactToolEnabled(enabled: boolean): void { betaUploadArtifactToolEnabled = enabled; @@ -13,11 +12,3 @@ export function setBetaUploadArtifactToolEnabled(enabled: boolean): void { export function isBetaUploadArtifactToolEnabled(): boolean { return betaUploadArtifactToolEnabled; } - -export function setBetaSubagentToolEnabled(enabled: boolean): void { - betaSubagentToolEnabled = enabled; -} - -export function isBetaSubagentToolEnabled(): boolean { - return betaSubagentToolEnabled; -} From c1166405417d894a3699ce96016d1a3a3341d607 Mon Sep 17 00:00:00 2001 From: uinstinct <61635505+uinstinct@users.noreply.github.com> Date: Mon, 2 Mar 2026 18:17:31 +0530 Subject: [PATCH 7/8] rename to getAgents --- extensions/cli/src/subagent/{get-agents.ts => getAgents.ts} | 0 extensions/cli/src/tools/subagent.test.ts | 2 +- extensions/cli/src/tools/subagent.ts | 2 +- 3 files changed, 2 insertions(+), 2 deletions(-) rename extensions/cli/src/subagent/{get-agents.ts => getAgents.ts} (100%) diff --git a/extensions/cli/src/subagent/get-agents.ts b/extensions/cli/src/subagent/getAgents.ts similarity index 100% rename from extensions/cli/src/subagent/get-agents.ts rename to extensions/cli/src/subagent/getAgents.ts diff --git a/extensions/cli/src/tools/subagent.test.ts b/extensions/cli/src/tools/subagent.test.ts index 3af2ff4bfe8..9aae2066372 100644 --- a/extensions/cli/src/tools/subagent.test.ts +++ b/extensions/cli/src/tools/subagent.test.ts @@ -3,7 +3,7 @@ import { beforeEach, describe, expect, it, vi } from "vitest"; import { services } from "../services/index.js"; import { serviceContainer } from "../services/ServiceContainer.js"; import { executeSubAgent } from "../subagent/executor.js"; -import { getAgentNames, getSubagent } from "../subagent/get-agents.js"; +import { getAgentNames, getSubagent } from "../subagent/getAgents.js"; import { subagentTool } from "./subagent.js"; diff --git a/extensions/cli/src/tools/subagent.ts b/extensions/cli/src/tools/subagent.ts index 43d2d29eb4f..86645b5062e 100644 --- a/extensions/cli/src/tools/subagent.ts +++ b/extensions/cli/src/tools/subagent.ts @@ -6,7 +6,7 @@ import { generateSubagentToolDescription, getSubagent, getAgentNames as getSubagentNames, -} from "../subagent/get-agents.js"; +} from "../subagent/getAgents.js"; import { SUBAGENT_TOOL_META } from "../subagent/index.js"; import { logger } from "../util/logger.js"; From af13df6f0f0d6ea7c8c7ca771564aa85520f81a1 Mon Sep 17 00:00:00 2001 From: uinstinct <61635505+uinstinct@users.noreply.github.com> Date: Mon, 2 Mar 2026 18:45:56 +0530 Subject: [PATCH 8/8] change code review to generalist subagent --- .../cli/src/subagent/builtInSubagents.ts | 24 ++++++++----------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/extensions/cli/src/subagent/builtInSubagents.ts b/extensions/cli/src/subagent/builtInSubagents.ts index 0c60d5f5ad6..2880c7e4222 100644 --- a/extensions/cli/src/subagent/builtInSubagents.ts +++ b/extensions/cli/src/subagent/builtInSubagents.ts @@ -28,33 +28,29 @@ When navigating a codebase, you will: Your output should be concise and actionable, starting with a brief summary of what you found and listing the key files/paths, functions, symbols, and important relationships or flows between them in plain language. If you cannot find something, describe what you searched for, where you looked, and suggest next places or strategies to investigate.`, }; -export const CODE_REVIEWER_SUBAGENT: BuiltInSubagent = { - name: "code-reviewer", +export const GENERALIST_SUBAGENT: BuiltInSubagent = { + name: "general-tasker", model: "claude-sonnet-4-6", - systemPrompt: `You are a Senior Code Reviewer with expertise in software architecture, design patterns, and best practices. Your role is to review completed project steps against original plans and ensure code quality standards are met. + systemPrompt: `You are a Generalist subagent capable of handling any development task delegated to you. When to use: - Use this subagent whenever you are requested to review code, or after a feature or refactor is implemented and you want a structured review against the original plan and code quality standards. + Use this subagent for any task that doesn't require a specialized subagent, including but not limited to: implementing features, fixing bugs, refactoring, code review, documentation, research, debugging, and analysis. -When reviewing completed work, you will: +When handling a task, you will: -1. **Plan Alignment Analysis**: Compare implementation against original plans, identify justified vs problematic deviations, and verify all planned functionality is complete +1. **Interpret the Request**: Understand what is being asked, whether it's exploration, implementation, review, analysis, or something else entirely. Adapt your approach based on the nature of the task. -2. **Code Quality Assessment**: Review adherence to patterns, error handling, type safety, naming conventions, test coverage, and potential security or performance issues +2. **Gather Context**: Use available tools to explore the codebase, read relevant files, and understand the surrounding architecture before taking action or forming conclusions. -3. **Architecture and Design Review**: Ensure proper architectural patterns, separation of concerns, loose coupling, system integration, and scalability considerations +3. **Communicate Results**: Provide clear, actionable output tailored to the task. Summarize what you did or discovered, highlight key insights or changes, and note any open questions or recommended next steps. -4. **Documentation and Standards**: Verify appropriate comments, function documentation, file headers, and adherence to project-specific coding standards - -5. **Issue Identification and Recommendations**: Categorize issues as Critical/Important/Suggestions with specific examples, actionable recommendations, and code examples when helpful - -Your output should be structured, actionable, and focused on helping maintain high code quality while ensuring project goals are met. Be thorough but concise, and always provide constructive feedback that helps improve both the current implementation and future development practices.`, +You are flexible and resourceful. If a task is ambiguous, make reasonable assumptions and state them. If you encounter blockers, describe what you attempted and suggest alternatives.`, }; export const BUILT_IN_SUBAGENTS: BuiltInSubagent[] = [ NAVIGATOR_SUBAGENT, - CODE_REVIEWER_SUBAGENT, + GENERALIST_SUBAGENT, ]; export function createBuiltInSubagentModel(