runSubagentTool.ts ×11

Frontier kind: Code frontier

unlabeled · c_0e130bd9922e

32 tests · 49656 LOC · 214 files · introduces 0 tests · 125 LOC · 2 files

Introduces — evidence that enters the hierarchy at this concept

Code
12 ranges125 lines · 2 files
Tests
0 tests

Contains — complete concept membership

All code (extent)
3739 ranges49656 lines · 214 files · Browse complete extent
All tests (intent)
32 testsBrowse complete intent

Neighbourhood graph

The orange circle is the focus. Violet and green circles are every ancestor and descendant, broader and narrower, at any distance; blue squares and pink diamonds are the introduced files and exact introduced tests of every visible concept, not only the focus's. Arrows point from broader to narrower concepts and bridge only concepts omitted from this view. Undirected links show source or test introduction. Concept and file size follows LOC; exact test nodes use test-count units.

Introduced files, introduced tests, and structurally relevant concept specialization

In the embedded map, ordinary wheel input scrolls the page; use the visible controls to zoom and drag to pan. Open the full-screen map for canvas navigation: wheel pans, Ctrl/Command plus wheel zooms, and arrow keys pan when this region is focused. On touch screens, open the full-screen map to pan or pinch. If JavaScript or WebGL is unavailable, use the native relationship evidence on this page.

Graph controls are ready.

Interactive rendering requires JavaScript and WebGL. Use the native relationship evidence on this page while the interactive map is unavailable.

Native relationship evidence

Every exact file and test below is linked only from the concept that introduces it.

Introduced tests

Every collected test enters the hierarchy at exactly one concept.

No tests are introduced at this concept. Its intent tests are introduced by other concepts.

Introduced code

Every collected source range enters the hierarchy at exactly one concept.

2 files ranked by introduced lines: 125 introduced LOC across 12 ranges. Expand a file to inspect source; the > gutter marks introduced lines.

src/vs/workbench/contrib/chat/common/tools/builtinTools/runSubagentTool.ts 114 introduced LOC · 11 ranges

Open complete file

1 > /*--------------------------------------------------------------------------------------------- runSubagentTool.ts
2 > * Copyright (c) Microsoft Corporation. All rights reserved.
3 > * Licensed under the MIT License. See License.txt in the project root for license information.
4 > *--------------------------------------------------------------------------------------------*/
5 >
6 > import { CancellationToken } from '../../../../../../base/common/cancellation.js';
7 > import { Codicon } from '../../../../../../base/common/codicons.js';
8 > import { Emitter, type Event } from '../../../../../../base/common/event.js';
9 > import { MarkdownString } from '../../../../../../base/common/htmlContent.js';
10 > import { IJSONSchema, IJSONSchemaMap } from '../../../../../../base/common/jsonSchema.js';
11 > import { Disposable, DisposableStore } from '../../../../../../base/common/lifecycle.js';
12 > import type { URI } from '../../../../../../base/common/uri.js';
13 > import { ThemeIcon } from '../../../../../../base/common/themables.js';
14 > import { generateUuid } from '../../../../../../base/common/uuid.js';
15 > import { localize } from '../../../../../../nls.js';
16 > import { IConfigurationService } from '../../../../../../platform/configuration/common/configuration.js';
17 > import { IInstantiationService } from '../../../../../../platform/instantiation/common/instantiation.js';
18 > import { ILogService } from '../../../../../../platform/log/common/log.js';
19 > import { IProductService } from '../../../../../../platform/product/common/productService.js';
20 > import { ChatRequestVariableSet } from '../../attachments/chatVariableEntries.js';
21 > import { isByokModel } from '../../chatSelectedModel.js';
22 > import { IChatProgress, IChatService } from '../../chatService/chatService.js';
23 > import { ChatAgentLocation, ChatConfiguration, ChatModeKind } from '../../constants.js';
24 > import { COPILOT_VENDOR_ID, ILanguageModelChatMetadata, ILanguageModelsService } from '../../languageModels.js';
25 > import type { ChatModel, IChatRequestModeInstructions } from '../../model/chatModel.js';
26 > import { getChatSessionType } from '../../model/chatUri.js';
27 > import { IChatAgentRequest, IChatAgentResult, IChatAgentService } from '../../participants/chatAgents.js';
28 > import { ComputeAutomaticInstructions } from '../../promptSyntax/computeAutomaticInstructions.js';
29 > import { ChatRequestHooks, mergeHooks } from '../../promptSyntax/hookSchema.js';
30 > import { HookType } from '../../promptSyntax/hookTypes.js';
31 > import { ICustomAgent, IPromptsService } from '../../promptSyntax/service/promptsService.js';
32 > import { isBuiltinAgent } from '../../promptSyntax/utils/promptsServiceUtils.js';
33 > import {
34 > CountTokensCallback,
35 > ILanguageModelToolsService,
36 > IPreparedToolInvocation,
37 > isToolSet,
38 > IToolData,
39 > IToolImpl,
40 > IToolInvocation,
41 > IToolInvocationPreparationContext,
42 > IToolResult,
43 > ToolDataSource,
44 > ToolProgress,
45 > VSCodeToolReference,
46 > } from '../languageModelToolsService.js';
47 > import { ManageTodoListToolToolId } from './manageTodoListTool.js';
48 > import { createToolSimpleTextResult } from './toolHelpers.js';
49 >
50 > const BaseModelDescription = `Launch a new agent to handle complex, multi-step tasks autonomously. This tool is good at researching complex questions, searching for code, and executing multi-step tasks. When you are searching for a keyword or file and are not confident that you will find the right match in the first few tries, use this agent to perform the search for you.
51 >
52 > - Agents do not run async or in the background, you will wait for the agent\'s result.
53 > - When the agent is done, it will return a single message back to you. The result returned by the agent is not visible to the user. To show the user the result, you should send a text message back to the user with a concise summary of the result.
54 > - Each agent invocation is stateless. You will not be able to send additional messages to the agent, nor will the agent be able to communicate with you outside of its final report. Therefore, your prompt should contain a highly detailed task description for the agent to perform autonomously and you should specify exactly what information the agent should return back to you in its final and only message to you.
55 > - The agent's outputs should generally be trusted
56 > - Clearly tell the agent whether you expect it to write code or just to do research (search, file reads, web fetches, etc.), since it is not aware of the user\'s intent
57 > - If the user asks for a certain agent, you MUST provide that EXACT agent name (case-sensitive) to invoke that specific agent.`;
58 >
59 > export interface IRunSubagentToolInputParams {
60 > prompt: string;
61 > description: string;
62 > agentName?: string;
63 > model?: string;
64 > }
65 >
66 > export const RUN_SUBAGENT_MAX_NESTING_DEPTH = 5;
67 >
68 > export class RunSubagentTool extends Disposable implements IToolImpl {
69 >
70 > static readonly Id = 'runSubagent';
71 >
72 > private readonly _onDidUpdateToolData = this._register(new Emitter<void>());
73 > readonly onDidUpdateToolData: Event<void> = this._onDidUpdateToolData.event;
74 >
75 > /** Hack to port data between prepare/invoke */
76 > private readonly _resolvedModels = new Map<string, { modeModelId: string | undefined; resolvedModelName: string | undefined }>();
77 >
78 > /** Tracks the current subagent nesting depth per session to detect and limit recursion. */
79 > private readonly _sessionDepth = new Map<string, number>();
80 >
81 > constructor(
82 @IChatAgentService private readonly chatAgentService: IChatAgentService,
83 @IChatService private readonly chatService: IChatService,
92 super();
93 }
95 > getToolData(): IToolData {
96 const modelDescription = BaseModelDescription;
97
132 return runSubagentToolData;
133 }
135 > async invoke(invocation: IToolInvocation, _countTokens: CountTokensCallback, _progress: ToolProgress, token: CancellationToken): Promise<IToolResult> {
136 const args = invocation.parameters as IRunSubagentToolInputParams;
137
419 }
420 }
422 > private async getSubAgentByName(name: string): Promise<ICustomAgent | undefined> {
423 const agents = await this.promptsService.getCustomAgents(CancellationToken.None);
424 return agents.find(agent => agent.name === name && agent.enabled);
425 }
427 > /**
428 > * Checks if a model exceeds the main model's cost tier based on multiplier.
429 > * @returns An object with `exceeds: true` and a reason string if blocked, or `exceeds: false` if allowed.
430 > */
431 > private checkMultiplierConstraint(modelId: string, mainModelId: string | undefined): { exceeds: false } | { exceeds: true; reason: string } {
432 if (!mainModelId || modelId === mainModelId) {
433 return { exceeds: false };
448 return { exceeds: false };
449 }
451 > /**
452 > * Returns information about available models for error messages.
453 > * Includes which models are unavailable due to multiplier restrictions.
454 > */
455 > private getAvailableModelsInfo(mainModelId: string | undefined): string {
456 const models = this.languageModelsService.getLanguageModelIds()
457 .map(id => ({ id, metadata: this.languageModelsService.lookupLanguageModel(id) }))
491 return parts.join('. ') || 'No models available.';
492 }
494 > /**
495 > * Resolves the model to be used by a subagent.
496 > * @param explicitModelQualifiedName Optional explicit model specified by the caller.
497 > * If provided and not found or not allowed, throws an error with available models.
498 > * @throws Error if the requested model is not found or exceeds the main model's cost tier.
499 > */
500 > private resolveSubagentModel(subagent: ICustomAgent | undefined, mainModelId: string | undefined, explicitModelQualifiedName?: string): { modeModelId: string | undefined; resolvedModelName: string | undefined } {
501 let modeModelId = mainModelId;
502 let explicitModelResolved = false;
549 return { modeModelId, resolvedModelName: resolvedModelMetadata?.name };
550 }
552 > async prepareToolInvocation(context: IToolInvocationPreparationContext, _token: CancellationToken): Promise<IPreparedToolInvocation | undefined> {
553 const args = context.parameters as IRunSubagentToolInputParams;
554 const requestedAgentName = this.normalizeRequestedAgentName(args.agentName);
572 };
573 }
575 > private normalizeRequestedAgentName(agentName: string | undefined): string | undefined {
576 const normalized = agentName?.trim();
577 return normalized ? normalized : undefined;
578 }
580 > private getCurrentModeInstructions(sessionResource: URI): IChatRequestModeInstructions | undefined {
581 if (typeof this.chatService.getSession !== 'function') {
582 return undefined;
585 return model?.getRequests().at(-1)?.modeInfo?.modeInstructions;
586 }
src/vs/workbench/contrib/chat/common/tools/builtinTools/toolHelpers.ts 11 introduced LOC · 1 range

Open complete file

1 > /*--------------------------------------------------------------------------------------------- toolHelpers.ts
2 > * Copyright (c) Microsoft Corporation. All rights reserved.
3 > * Licensed under the MIT License. See License.txt in the project root for license information.
4 > *--------------------------------------------------------------------------------------------*/
5 >
6 > import { IToolResult } from '../languageModelToolsService.js';
7 >
8 > /**
9 > * Creates a tool result with a single text content part.
10 > */
11 > export function createToolSimpleTextResult(value: string): IToolResult {
12 return {
13 content: [{