feat(coding-agent): add exclude tools option closes #5109

This commit is contained in:
Mario Zechner
2026-05-28 23:49:01 +02:00
parent 1ab2899800
commit 9380d5f2e4
12 changed files with 147 additions and 6 deletions

View File

@@ -54,6 +54,7 @@ export interface CreateAgentSessionFromServicesOptions {
thinkingLevel?: ThinkingLevel;
scopedModels?: Array<{ model: Model<any>; thinkingLevel?: ThinkingLevel }>;
tools?: string[];
excludeTools?: CreateAgentSessionOptions["excludeTools"];
noTools?: CreateAgentSessionOptions["noTools"];
customTools?: ToolDefinition[];
}
@@ -192,6 +193,7 @@ export async function createAgentSessionFromServices(
thinkingLevel: options.thinkingLevel,
scopedModels: options.scopedModels,
tools: options.tools,
excludeTools: options.excludeTools,
noTools: options.noTools,
customTools: options.customTools,
sessionStartEvent: options.sessionStartEvent,

View File

@@ -170,6 +170,8 @@ export interface AgentSessionConfig {
initialActiveToolNames?: string[];
/** Optional allowlist of tool names. When provided, only these tool names are exposed. */
allowedToolNames?: string[];
/** Optional denylist of tool names. When provided, these tool names are not exposed. */
excludedToolNames?: string[];
/**
* Override base tools (useful for custom runtimes).
*
@@ -294,6 +296,7 @@ export class AgentSession {
private _extensionRunnerRef?: { current?: ExtensionRunner };
private _initialActiveToolNames?: string[];
private _allowedToolNames?: Set<string>;
private _excludedToolNames?: Set<string>;
private _baseToolsOverride?: Record<string, AgentTool>;
private _sessionStartEvent: SessionStartEvent;
private _extensionUIContext?: ExtensionUIContext;
@@ -328,6 +331,7 @@ export class AgentSession {
this._extensionRunnerRef = config.extensionRunnerRef;
this._initialActiveToolNames = config.initialActiveToolNames;
this._allowedToolNames = config.allowedToolNames ? new Set(config.allowedToolNames) : undefined;
this._excludedToolNames = config.excludedToolNames ? new Set(config.excludedToolNames) : undefined;
this._baseToolsOverride = config.baseToolsOverride;
this._sessionStartEvent = config.sessionStartEvent ?? { type: "session_start", reason: "startup" };
@@ -2272,7 +2276,9 @@ export class AgentSession {
const previousRegistryNames = new Set(this._toolRegistry.keys());
const previousActiveToolNames = this.getActiveToolNames();
const allowedToolNames = this._allowedToolNames;
const isAllowedTool = (name: string): boolean => !allowedToolNames || allowedToolNames.has(name);
const excludedToolNames = this._excludedToolNames;
const isAllowedTool = (name: string): boolean =>
(!allowedToolNames || allowedToolNames.has(name)) && !excludedToolNames?.has(name);
const registeredTools = this._extensionRunner.getAllRegisteredTools();
const allCustomTools = [

View File

@@ -65,6 +65,8 @@ export interface CreateAgentSessionOptions {
* When provided, only the listed tool names are enabled.
*/
tools?: string[];
/** Optional denylist of tool names to disable. Applies after `tools` when both are provided. */
excludeTools?: string[];
/** Custom tools to register (in addition to built-in tools). */
customTools?: ToolDefinition[];
@@ -279,11 +281,11 @@ export async function createAgentSession(options: CreateAgentSessionOptions = {}
const defaultActiveToolNames: ToolName[] = ["read", "bash", "edit", "write"];
const allowedToolNames = options.tools ?? (options.noTools === "all" ? [] : undefined);
const initialActiveToolNames: string[] = options.tools
? [...options.tools]
: options.noTools
? []
: defaultActiveToolNames;
const excludedToolNames = options.excludeTools;
const excludedToolNameSet = excludedToolNames ? new Set(excludedToolNames) : undefined;
const initialActiveToolNames: string[] = (
options.tools ? [...options.tools] : options.noTools ? [] : defaultActiveToolNames
).filter((name) => !excludedToolNameSet?.has(name));
let agent: Agent;
@@ -416,6 +418,7 @@ export async function createAgentSession(options: CreateAgentSessionOptions = {}
modelRegistry,
initialActiveToolNames,
allowedToolNames,
excludedToolNames,
extensionRunnerRef,
sessionStartEvent: options.sessionStartEvent,
});