feat: add tool prompt override support in .continuerc.json (#9314)

* feat: add tool prompt overrides support in YAML model config

Adds per-model tool prompt overrides under chatOptions in YAML config:

```yaml
models:
  - name: my-model
    chatOptions:
      toolPromptOverrides:
        run_terminal_command:
          description: "Custom description"
        view_diff:
          disabled: true
```

This replaces the JSON-only implementation with YAML-only support as
requested by maintainers. The JSON implementation is preserved on the
`feature/tool-prompt-overrides-json` branch for reference.

Changes:
- Add toolOverrideSchema to chatOptionsSchema (packages/config-yaml)
- Add ToolOverride interface and toolPromptOverrides to LLMOptions (core)
- Store and apply overrides in BaseLLM.streamChat()
- Add applyToolOverrides utility with comprehensive tests

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

* feat(cli): add tool prompt overrides support for CLI parity

Apply toolPromptOverrides from YAML model config in CLI,
ensuring feature parity with VS Code extension.

- Add applyChatCompletionToolOverrides helper for CLI tool format
- Apply overrides in streamChatResponse before LLM calls
- Support description changes and disabling tools
- Add unit tests for override logic

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

* chore: package lock update

* ci: retrigger after hub 502

* refactor: rename toolPromptOverrides to toolOverrides

- Rename property across core, config-yaml, and CLI
- Consolidate ToolOverride type to extend ToolOverrideConfig from
  config-yaml instead of duplicating 7 fields
- Inline record-to-array conversion to match file patterns

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

* chore: retrigger CI (clean run)

* chore: revert gui package-lock to main

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
Co-authored-by: Dallin Romney <dallinromney@gmail.com>
This commit is contained in:
shanevcantwell 2026-02-02 22:55:21 -07:00 • committed by GitHub
parent dcac6260a7
commit d80845c403
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 431 additions and 3 deletions

View file

@ -67,6 +67,12 @@ async function modelConfigToBaseLLM({
baseAgentSystemMessage: model.chatOptions?.baseAgentSystemMessage,
basePlanSystemMessage: model.chatOptions?.basePlanSystemMessage,
baseChatSystemMessage: model.chatOptions?.baseSystemMessage,
toolOverrides: model.chatOptions?.toolOverrides
? Object.entries(model.chatOptions.toolOverrides).map(([name, o]) => ({
name,
...o,
}))
: undefined,
capabilities: {
tools: model.capabilities?.includes("tool_use"),
uploadImage: model.capabilities?.includes("image_input"),

13
core/index.d.ts vendored
View file

@ -2,6 +2,7 @@ import {
DataDestination,
ModelRole,
PromptTemplates,
ToolOverrideConfig,
} from "@continuedev/config-yaml";
import Parser from "web-tree-sitter";
import { CodebaseIndexer } from "./indexing/CodebaseIndexer";
@ -695,6 +696,9 @@ export interface LLMOptions {
sourceFile?: string;
isFromAutoDetect?: boolean;
/** Tool overrides for this model */
toolOverrides?: ToolOverride[];
}
type RequireAtLeastOne<T, Keys extends keyof T = keyof T> = Pick<
@ -1142,6 +1146,15 @@ export interface Tool {
) => ToolPolicy;
}
/**
* Configuration for overriding built-in tool prompts.
* Extends ToolOverrideConfig with required name for array usage.
*/
export type ToolOverride = ToolOverrideConfig & {
/** Tool name to override (matches function.name, e.g., "read_file") */
name: string;
};
interface ToolChoice {
type: "function";
function: {

View file

@ -28,6 +28,7 @@ import {
RequestOptions,
TabAutocompleteOptions,
TemplateType,
ToolOverride,
Usage,
} from "../index.js";
import { isLemonadeInstalled } from "../util/lemonadeHelper.js";
@ -65,6 +66,8 @@ import {
toCompleteBody,
toFimBody,
} from "./openaiTypeConverters.js";
import { applyToolOverrides } from "../tools/applyToolOverrides.js";
export class LLMError extends Error {
constructor(
message: string,
@ -196,6 +199,9 @@ export abstract class BaseLLM implements ILLM {
isFromAutoDetect?: boolean;
/** Tool overrides for this model */
toolOverrides?: ToolOverride[];
lastRequestId: string | undefined;
private _llmOptions: LLMOptions;
@ -303,6 +309,7 @@ export abstract class BaseLLM implements ILLM {
this.autocompleteOptions = options.autocompleteOptions;
this.sourceFile = options.sourceFile;
this.isFromAutoDetect = options.isFromAutoDetect;
this.toolOverrides = options.toolOverrides;
}
get contextLength() {
@ -1111,8 +1118,28 @@ export abstract class BaseLLM implements ILLM {
messageOptions?: MessageOption,
): AsyncGenerator<ChatMessage, PromptLog> {
this.lastRequestId = undefined;
// Apply per-model tool overrides if configured
let effectiveTools = options.tools;
if (this.toolOverrides?.length && options.tools?.length) {
const { tools: overriddenTools, errors } = applyToolOverrides(
options.tools,
this.toolOverrides,
);
effectiveTools = overriddenTools;
// Log any warnings for unknown tool names
for (const error of errors) {
if (!error.fatal) {
console.warn(`Tool override warning: ${error.message}`);
}
}
}
// Use effectiveTools for the rest of this method
const optionsWithOverrides = { ...options, tools: effectiveTools };
let { completionOptions, logEnabled } =
this._parseCompletionOptions(options);
this._parseCompletionOptions(optionsWithOverrides);
const interaction = logEnabled
? this.logger?.createInteractionLog()
: undefined;
@ -1130,7 +1157,7 @@ export abstract class BaseLLM implements ILLM {
knownContextLength: this._contextLength,
maxTokens: completionOptions.maxTokens ?? DEFAULT_MAX_TOKENS,
supportsImages: this.supportsImages(),
tools: options.tools,
tools: optionsWithOverrides.tools,
});
messages = compiledChatMessages;

View file

@ -0,0 +1,69 @@
import { ConfigValidationError } from "@continuedev/config-yaml";
import { Tool, ToolOverride } from "..";
export interface ApplyToolOverridesResult {
tools: Tool[];
errors: ConfigValidationError[];
}
/**
* Applies tool overrides from config to the list of tools.
* Overrides can modify tool descriptions, display titles, action phrases,
* system message descriptions, or disable tools entirely.
*/
export function applyToolOverrides(
tools: Tool[],
overrides: ToolOverride[] | undefined,
): ApplyToolOverridesResult {
if (!overrides?.length) {
return { tools, errors: [] };
}
const errors: ConfigValidationError[] = [];
const toolsByName = new Map(tools.map((t) => [t.function.name, t]));
for (const override of overrides) {
const tool = toolsByName.get(override.name);
if (!tool) {
errors.push({
fatal: false,
message: `Tool override "${override.name}" does not match any known tool. Available tools: ${Array.from(toolsByName.keys()).join(", ")}`,
});
continue;
}
if (override.disabled) {
toolsByName.delete(override.name);
continue;
}
const updatedTool: Tool = {
...tool,
function: {
...tool.function,
description: override.description ?? tool.function.description,
},
displayTitle: override.displayTitle ?? tool.displayTitle,
wouldLikeTo: override.wouldLikeTo ?? tool.wouldLikeTo,
isCurrently: override.isCurrently ?? tool.isCurrently,
hasAlready: override.hasAlready ?? tool.hasAlready,
};
if (override.systemMessageDescription) {
updatedTool.systemMessageDescription = {
prefix:
override.systemMessageDescription.prefix ??
tool.systemMessageDescription?.prefix ??
"",
exampleArgs:
override.systemMessageDescription.exampleArgs ??
tool.systemMessageDescription?.exampleArgs,
};
}
toolsByName.set(override.name, updatedTool);
}
return { tools: Array.from(toolsByName.values()), errors };
}

View file

@ -0,0 +1,185 @@
import { describe, expect, it } from "vitest";
import { Tool, ToolOverride } from "..";
import { applyToolOverrides } from "./applyToolOverrides";
const mockTool = (name: string, description: string): Tool => ({
type: "function",
displayTitle: name,
readonly: true,
group: "test",
function: { name, description },
});
describe("applyToolOverrides", () => {
it("should return tools unchanged when no overrides provided", () => {
const tools = [mockTool("read_file", "Read a file")];
const result = applyToolOverrides(tools, undefined);
expect(result.tools).toEqual(tools);
expect(result.errors).toHaveLength(0);
});
it("should return tools unchanged when empty overrides array provided", () => {
const tools = [mockTool("read_file", "Read a file")];
const result = applyToolOverrides(tools, []);
expect(result.tools).toEqual(tools);
expect(result.errors).toHaveLength(0);
});
it("should override description when specified", () => {
const tools = [mockTool("read_file", "Original description")];
const overrides: ToolOverride[] = [
{ name: "read_file", description: "New description" },
];
const result = applyToolOverrides(tools, overrides);
expect(result.tools[0].function.description).toBe("New description");
expect(result.errors).toHaveLength(0);
});
it("should override displayTitle when specified", () => {
const tools = [mockTool("read_file", "Read a file")];
const overrides: ToolOverride[] = [
{ name: "read_file", displayTitle: "Custom Read File" },
];
const result = applyToolOverrides(tools, overrides);
expect(result.tools[0].displayTitle).toBe("Custom Read File");
});
it("should override action phrases when specified", () => {
const tools = [mockTool("read_file", "Read a file")];
tools[0].wouldLikeTo = "read {{{ filepath }}}";
tools[0].isCurrently = "reading {{{ filepath }}}";
tools[0].hasAlready = "read {{{ filepath }}}";
const overrides: ToolOverride[] = [
{
name: "read_file",
wouldLikeTo: "open {{{ filepath }}}",
isCurrently: "opening {{{ filepath }}}",
hasAlready: "opened {{{ filepath }}}",
},
];
const result = applyToolOverrides(tools, overrides);
expect(result.tools[0].wouldLikeTo).toBe("open {{{ filepath }}}");
expect(result.tools[0].isCurrently).toBe("opening {{{ filepath }}}");
expect(result.tools[0].hasAlready).toBe("opened {{{ filepath }}}");
});
it("should disable tools when disabled: true", () => {
const tools = [
mockTool("read_file", "Read"),
mockTool("write_file", "Write"),
];
const overrides: ToolOverride[] = [{ name: "read_file", disabled: true }];
const result = applyToolOverrides(tools, overrides);
expect(result.tools).toHaveLength(1);
expect(result.tools[0].function.name).toBe("write_file");
expect(result.errors).toHaveLength(0);
});
it("should warn when override references unknown tool", () => {
const tools = [mockTool("read_file", "Read")];
const overrides: ToolOverride[] = [
{ name: "unknown_tool", description: "test" },
];
const result = applyToolOverrides(tools, overrides);
expect(result.tools).toHaveLength(1);
expect(result.errors).toHaveLength(1);
expect(result.errors[0].message).toContain("unknown_tool");
expect(result.errors[0].fatal).toBe(false);
});
it("should preserve unmodified fields", () => {
const tools = [mockTool("read_file", "Original")];
tools[0].readonly = true;
tools[0].group = "Built-In";
const overrides: ToolOverride[] = [
{ name: "read_file", description: "New description" },
];
const result = applyToolOverrides(tools, overrides);
expect(result.tools[0].readonly).toBe(true);
expect(result.tools[0].group).toBe("Built-In");
expect(result.tools[0].displayTitle).toBe("read_file");
});
it("should override systemMessageDescription", () => {
const tools = [mockTool("read_file", "Read")];
tools[0].systemMessageDescription = {
prefix: "old prefix",
exampleArgs: [["filepath", "/old/path"]],
};
const overrides: ToolOverride[] = [
{
name: "read_file",
systemMessageDescription: {
prefix: "new prefix",
exampleArgs: [["filepath", "/new/path"]],
},
},
];
const result = applyToolOverrides(tools, overrides);
expect(result.tools[0].systemMessageDescription?.prefix).toBe("new prefix");
expect(result.tools[0].systemMessageDescription?.exampleArgs).toEqual([
["filepath", "/new/path"],
]);
});
it("should partially override systemMessageDescription", () => {
const tools = [mockTool("read_file", "Read")];
tools[0].systemMessageDescription = {
prefix: "old prefix",
exampleArgs: [["filepath", "/old/path"]],
};
const overrides: ToolOverride[] = [
{
name: "read_file",
systemMessageDescription: {
prefix: "new prefix",
// exampleArgs not specified - should preserve original
},
},
];
const result = applyToolOverrides(tools, overrides);
expect(result.tools[0].systemMessageDescription?.prefix).toBe("new prefix");
expect(result.tools[0].systemMessageDescription?.exampleArgs).toEqual([
["filepath", "/old/path"],
]);
});
it("should apply multiple overrides", () => {
const tools = [
mockTool("read_file", "Read"),
mockTool("write_file", "Write"),
mockTool("delete_file", "Delete"),
];
const overrides: ToolOverride[] = [
{ name: "read_file", description: "Custom read" },
{ name: "write_file", disabled: true },
{ name: "delete_file", displayTitle: "Remove File" },
];
const result = applyToolOverrides(tools, overrides);
expect(result.tools).toHaveLength(2);
expect(result.tools[0].function.description).toBe("Custom read");
expect(result.tools[1].displayTitle).toBe("Remove File");
expect(result.errors).toHaveLength(0);
});
it("should not mutate original tools array", () => {
const tools = [mockTool("read_file", "Original")];
const originalDescription = tools[0].function.description;
const overrides: ToolOverride[] = [
{ name: "read_file", description: "New description" },
];
const result = applyToolOverrides(tools, overrides);
// Original should be unchanged
expect(tools[0].function.description).toBe(originalDescription);
// Result should have new description
expect(result.tools[0].function.description).toBe("New description");
});
});

View file

@ -12,6 +12,7 @@ import { pruneLastMessage } from "../compaction.js";
import { services } from "../services/index.js";
import { posthogService } from "../telemetry/posthogService.js";
import { telemetryService } from "../telemetry/telemetryService.js";
import { applyChatCompletionToolOverrides } from "../tools/applyToolOverrides.js";
import { ToolCall } from "../tools/index.js";
import {
chatCompletionStreamWithBackoff,
@ -460,7 +461,11 @@ export async function streamChatResponse(
);
// Recompute tools on each iteration to handle mode changes during streaming
const tools = await getRequestTools(isHeadless);
const rawTools = await getRequestTools(isHeadless);
const tools = applyChatCompletionToolOverrides(
rawTools,
model.chatOptions?.toolOverrides,
);
// Pre-API auto-compaction checkpoint (now includes tools)
const preCompactionResult = await handlePreApiCompaction(chatHistory, {

View file

@ -0,0 +1,64 @@
import type { ChatCompletionTool } from "openai/resources.mjs";
import { describe, expect, it } from "vitest";
import { applyChatCompletionToolOverrides } from "./applyToolOverrides.js";
describe("applyChatCompletionToolOverrides", () => {
const mockTools: ChatCompletionTool[] = [
{
type: "function",
function: { name: "read_file", description: "Read a file" },
},
{
type: "function",
function: { name: "write_file", description: "Write a file" },
},
];
it("returns tools unchanged when no overrides", () => {
expect(applyChatCompletionToolOverrides(mockTools, undefined)).toEqual(
mockTools,
);
expect(applyChatCompletionToolOverrides(mockTools, {})).toEqual(mockTools);
});
it("applies description override", () => {
const result = applyChatCompletionToolOverrides(mockTools, {
read_file: { description: "Custom read description" },
});
expect(result[0].function.description).toBe("Custom read description");
expect(result[1].function.description).toBe("Write a file");
});
it("filters out disabled tools", () => {
const result = applyChatCompletionToolOverrides(mockTools, {
read_file: { disabled: true },
});
expect(result).toHaveLength(1);
expect(result[0].function.name).toBe("write_file");
});
it("handles multiple overrides", () => {
const result = applyChatCompletionToolOverrides(mockTools, {
read_file: { description: "Custom read" },
write_file: { description: "Custom write" },
});
expect(result[0].function.description).toBe("Custom read");
expect(result[1].function.description).toBe("Custom write");
});
it("ignores overrides for non-existent tools", () => {
const result = applyChatCompletionToolOverrides(mockTools, {
non_existent_tool: { description: "Should be ignored" },
});
expect(result).toEqual(mockTools);
});
it("does not mutate original tools", () => {
const originalDescription = mockTools[0].function.description;
applyChatCompletionToolOverrides(mockTools, {
read_file: { description: "Modified description" },
});
expect(mockTools[0].function.description).toBe(originalDescription);
});
});

View file

@ -0,0 +1,31 @@
import type { ToolOverrideConfig } from "@continuedev/config-yaml";
import type { ChatCompletionTool } from "openai/resources.mjs";
/**
* Applies tool prompt overrides from YAML config to CLI tools.
* Supports description changes and disabling tools.
*/
export function applyChatCompletionToolOverrides(
tools: ChatCompletionTool[],
overrides: Record<string, ToolOverrideConfig> | undefined,
): ChatCompletionTool[] {
if (!overrides) {
return tools;
}
return tools
.filter((tool) => !overrides[tool.function.name]?.disabled)
.map((tool) => {
const override = overrides[tool.function.name];
if (!override?.description) {
return tool;
}
return {
...tool,
function: {
...tool.function,
description: override.description,
},
};
});
}

View file

@ -87,10 +87,38 @@ export const embedOptionsSchema = z.object({
});
export type EmbedOptions = z.infer<typeof embedOptionsSchema>;
/**
* Schema for overriding a tool's system message description.
* Used for models that don't support native tool calling.
*/
export const systemMessageDescriptionOverrideSchema = z.object({
prefix: z.string().optional(),
exampleArgs: z
.array(z.tuple([z.string(), z.union([z.string(), z.number()])]))
.optional(),
});
/**
* Schema for overriding built-in tool prompts.
* Allows customization of tool descriptions and behavior per model.
*/
export const toolOverrideSchema = z.object({
description: z.string().optional(),
displayTitle: z.string().optional(),
wouldLikeTo: z.string().optional(),
isCurrently: z.string().optional(),
hasAlready: z.string().optional(),
systemMessageDescription: systemMessageDescriptionOverrideSchema.optional(),
disabled: z.boolean().optional(),
});
export type ToolOverrideConfig = z.infer<typeof toolOverrideSchema>;
export const chatOptionsSchema = z.object({
baseSystemMessage: z.string().optional(),
baseAgentSystemMessage: z.string().optional(),
basePlanSystemMessage: z.string().optional(),
/** Tool overrides keyed by tool name (e.g., "run_terminal_command") */
toolOverrides: z.record(z.string(), toolOverrideSchema).optional(),
});
export type ChatOptions = z.infer<typeof chatOptionsSchema>;