chore: use system message tools by default (#7236)
* when native tools are present, prevent system message tools * make onlyusesystemmessagetools on by default * add tests * setting defaults to false * use system message tools when model does not support native tools * remove system message info from docs * correction * remove the seleectUseSystemMessageTools selector * native tool support enabled for claude * cleanup `useSystemTools` variable * remove `claude` from openrouter toolsupport * fix: bad merge --------- Co-authored-by: Dallin Romney <dallinromney@gmail.com>
This commit is contained in:
parent
200c2931f2
commit
b84888bd5b
7 changed files with 14 additions and 319 deletions
|
|
@ -1,31 +0,0 @@
|
|||
import { ModelDescription } from "../index.d";
|
||||
|
||||
/**
|
||||
* Determines if system message tools should be auto-enabled for the given model.
|
||||
* This is used to automatically enable system message tools for certain provider/model combinations
|
||||
* where we have a strong preference, taking priority over user manual settings.
|
||||
*
|
||||
* System message tools are an alternative to native tool calling where tool definitions and calls
|
||||
* are embedded in the system message as text rather than using the provider's native tool calling API.
|
||||
* This can be beneficial for providers/models that don't support native tool calling or have
|
||||
* poor tool calling performance.
|
||||
*
|
||||
* Current auto-enable rules:
|
||||
* - OpenRouter provider: true for all models except those containing "claude" (since Claude models
|
||||
* generally have good native tool calling support)
|
||||
* - All other providers: undefined (no auto-preference, use manual setting)
|
||||
*
|
||||
* @param model The model description to check
|
||||
* @returns true to force enable, false to force disable, undefined for no auto-preference
|
||||
*/
|
||||
export function shouldAutoEnableSystemMessageTools(
|
||||
model: ModelDescription,
|
||||
): boolean | undefined {
|
||||
// Auto-enable for OpenRouter, but exclude Claude models which have good native tool calling
|
||||
if (model.provider === "openrouter") {
|
||||
return !model.model.toLowerCase().includes("claude");
|
||||
}
|
||||
|
||||
// No auto-preference for all other providers - use manual setting
|
||||
return undefined;
|
||||
}
|
||||
|
|
@ -1,85 +0,0 @@
|
|||
import { describe, expect, test } from "vitest";
|
||||
import { ModelDescription } from "../index.d";
|
||||
import { shouldAutoEnableSystemMessageTools } from "./shouldAutoEnableSystemMessageTools";
|
||||
|
||||
describe("shouldAutoEnableSystemMessageTools", () => {
|
||||
const createModel = (provider: string, model: string): ModelDescription => ({
|
||||
title: "Test Model",
|
||||
provider,
|
||||
underlyingProviderName: provider,
|
||||
model,
|
||||
});
|
||||
|
||||
test("should return true for OpenRouter models that don't contain 'claude'", () => {
|
||||
expect(
|
||||
shouldAutoEnableSystemMessageTools(createModel("openrouter", "gpt-4o")),
|
||||
).toBe(true);
|
||||
expect(
|
||||
shouldAutoEnableSystemMessageTools(
|
||||
createModel("openrouter", "llama-3.3-70b-instruct"),
|
||||
),
|
||||
).toBe(true);
|
||||
expect(
|
||||
shouldAutoEnableSystemMessageTools(
|
||||
createModel("openrouter", "qwen/qwen-2.5-72b-instruct"),
|
||||
),
|
||||
).toBe(true);
|
||||
});
|
||||
|
||||
test("should return false for OpenRouter Claude models", () => {
|
||||
expect(
|
||||
shouldAutoEnableSystemMessageTools(
|
||||
createModel("openrouter", "anthropic/claude-3-sonnet"),
|
||||
),
|
||||
).toBe(false);
|
||||
expect(
|
||||
shouldAutoEnableSystemMessageTools(
|
||||
createModel("openrouter", "anthropic/claude-3.5-sonnet"),
|
||||
),
|
||||
).toBe(false);
|
||||
expect(
|
||||
shouldAutoEnableSystemMessageTools(
|
||||
createModel("openrouter", "claude-3-haiku"),
|
||||
),
|
||||
).toBe(false);
|
||||
});
|
||||
|
||||
test("should return undefined for all other providers", () => {
|
||||
expect(
|
||||
shouldAutoEnableSystemMessageTools(createModel("openai", "gpt-4o")),
|
||||
).toBe(undefined);
|
||||
expect(
|
||||
shouldAutoEnableSystemMessageTools(
|
||||
createModel("anthropic", "claude-3.5-sonnet"),
|
||||
),
|
||||
).toBe(undefined);
|
||||
expect(
|
||||
shouldAutoEnableSystemMessageTools(
|
||||
createModel("groq", "llama-3.3-70b-versatile"),
|
||||
),
|
||||
).toBe(undefined);
|
||||
expect(
|
||||
shouldAutoEnableSystemMessageTools(
|
||||
createModel("together", "meta-llama/Meta-Llama-3.1-70B-Instruct-Turbo"),
|
||||
),
|
||||
).toBe(undefined);
|
||||
});
|
||||
|
||||
test("should be case insensitive for 'claude' detection", () => {
|
||||
expect(
|
||||
shouldAutoEnableSystemMessageTools(
|
||||
createModel("openrouter", "CLAUDE-models"),
|
||||
),
|
||||
).toBe(false);
|
||||
expect(
|
||||
shouldAutoEnableSystemMessageTools(
|
||||
createModel("openrouter", "Claude-3.5"),
|
||||
),
|
||||
).toBe(false);
|
||||
expect(
|
||||
shouldAutoEnableSystemMessageTools(
|
||||
createModel("openrouter", "some-model-Claude"),
|
||||
),
|
||||
).toBe(false);
|
||||
});
|
||||
});
|
||||
|
|
@ -12,10 +12,6 @@ The models you set up for Chat mode will be used with Agent mode if the model su
|
|||
|
||||
## How System Message Tools Work
|
||||
|
||||
<Info>
|
||||
System message tools are experimental and may change in future releases.
|
||||
</Info>
|
||||
|
||||
Continue implements an innovative approach called **system message tools** that ensures consistent tool functionality across all models, regardless of their native capabilities. This allows Agent mode to work seamlessly with a wider range of models and providers.
|
||||
|
||||
### How System Message Tools Function
|
||||
|
|
|
|||
|
|
@ -5,14 +5,10 @@ import {
|
|||
InformationCircleIcon,
|
||||
} from "@heroicons/react/24/outline";
|
||||
import { MessageModes } from "core";
|
||||
import {
|
||||
isRecommendedAgentModel,
|
||||
modelSupportsNativeTools,
|
||||
} from "core/llm/toolSupport";
|
||||
import { isRecommendedAgentModel } from "core/llm/toolSupport";
|
||||
import { capitalize } from "lodash";
|
||||
import { useCallback, useEffect, useMemo } from "react";
|
||||
import { useAppDispatch, useAppSelector } from "../../redux/hooks";
|
||||
import { selectUseSystemMessageTools } from "../../redux/selectors/selectUseSystemMessageTools";
|
||||
import { selectSelectedChatModel } from "../../redux/slices/configSlice";
|
||||
import { setMode } from "../../redux/slices/sessionSlice";
|
||||
import { getFontSize, getMetaKeyLabel } from "../../util";
|
||||
|
|
@ -25,14 +21,6 @@ export function ModeSelect() {
|
|||
const dispatch = useAppDispatch();
|
||||
const mode = useAppSelector((store) => store.session.mode);
|
||||
const selectedModel = useAppSelector(selectSelectedChatModel);
|
||||
const useSystemTools = useAppSelector(selectUseSystemMessageTools);
|
||||
|
||||
const isAgentSupported = useMemo(() => {
|
||||
if (!selectedModel) {
|
||||
return undefined;
|
||||
}
|
||||
return !!useSystemTools || modelSupportsNativeTools(selectedModel);
|
||||
}, [selectedModel, useSystemTools]);
|
||||
|
||||
const isGoodAtAgentMode = useMemo(() => {
|
||||
if (!selectedModel) {
|
||||
|
|
@ -46,16 +34,6 @@ export function ModeSelect() {
|
|||
return getMetaKeyLabel();
|
||||
}, []);
|
||||
|
||||
// Switch to chat mode if agent mode is selected but not supported
|
||||
useEffect(() => {
|
||||
if (!selectedModel) {
|
||||
return;
|
||||
}
|
||||
if (mode !== "chat" && !isAgentSupported) {
|
||||
dispatch(setMode("chat"));
|
||||
}
|
||||
}, [mode, isAgentSupported, selectedModel]);
|
||||
|
||||
const cycleMode = useCallback(() => {
|
||||
if (mode === "chat") {
|
||||
dispatch(setMode("plan"));
|
||||
|
|
@ -95,7 +73,6 @@ export function ModeSelect() {
|
|||
return () => document.removeEventListener("keydown", handleKeyDown);
|
||||
}, [cycleMode]);
|
||||
|
||||
const notSupported = <span>(Not supported)</span>;
|
||||
const notGreatAtAgent = (
|
||||
<>
|
||||
<ExclamationTriangleIcon
|
||||
|
|
@ -172,16 +149,10 @@ export function ModeSelect() {
|
|||
Read-only/MCP tools available
|
||||
</ToolTip>
|
||||
</div>
|
||||
{isAgentSupported ? (
|
||||
<>
|
||||
{!isGoodAtAgentMode && notGreatAtAgent}
|
||||
<CheckIcon
|
||||
className={`ml-auto h-3 w-3 ${mode === "plan" ? "" : "opacity-0"}`}
|
||||
/>
|
||||
</>
|
||||
) : (
|
||||
notSupported
|
||||
)}
|
||||
{!isGoodAtAgentMode && notGreatAtAgent}
|
||||
<CheckIcon
|
||||
className={`ml-auto h-3 w-3 ${mode === "plan" ? "" : "opacity-0"}`}
|
||||
/>
|
||||
</ListboxOption>
|
||||
|
||||
<ListboxOption value="agent" className={"gap-1"}>
|
||||
|
|
@ -201,16 +172,10 @@ export function ModeSelect() {
|
|||
All tools available
|
||||
</ToolTip>
|
||||
</div>
|
||||
{isAgentSupported ? (
|
||||
<>
|
||||
{!isGoodAtAgentMode && notGreatAtAgent}
|
||||
<CheckIcon
|
||||
className={`ml-auto h-3 w-3 ${mode === "agent" ? "" : "opacity-0"}`}
|
||||
/>
|
||||
</>
|
||||
) : (
|
||||
notSupported
|
||||
)}
|
||||
{!isGoodAtAgentMode && notGreatAtAgent}
|
||||
<CheckIcon
|
||||
className={`ml-auto h-3 w-3 ${mode === "agent" ? "" : "opacity-0"}`}
|
||||
/>
|
||||
</ListboxOption>
|
||||
|
||||
<div className="text-description-muted px-2 py-1">
|
||||
|
|
|
|||
|
|
@ -1,112 +0,0 @@
|
|||
import { ModelDescription } from "core";
|
||||
import { describe, expect, test, vi } from "vitest";
|
||||
import { RootState } from "../store";
|
||||
|
||||
// Mock the shouldAutoEnableSystemMessageTools function
|
||||
vi.mock("core/config/shouldAutoEnableSystemMessageTools", () => ({
|
||||
shouldAutoEnableSystemMessageTools: vi.fn((model: ModelDescription) => {
|
||||
if (model.provider === "openrouter") {
|
||||
return !model.model.toLowerCase().includes("claude");
|
||||
}
|
||||
return undefined; // No auto-preference for other providers
|
||||
}),
|
||||
}));
|
||||
|
||||
// Mock the selectSelectedChatModel selector - we'll control its return value in tests
|
||||
vi.mock("../slices/configSlice", () => ({
|
||||
selectSelectedChatModel: vi.fn(),
|
||||
}));
|
||||
|
||||
// Import after mocking
|
||||
import { selectSelectedChatModel } from "../slices/configSlice";
|
||||
import { selectUseSystemMessageTools } from "./selectUseSystemMessageTools";
|
||||
|
||||
describe("selectUseSystemMessageTools", () => {
|
||||
const mockSelectSelectedChatModel = selectSelectedChatModel as any;
|
||||
|
||||
const createMockState = (manualSetting?: boolean): RootState => {
|
||||
return {
|
||||
config: {
|
||||
config: {
|
||||
experimental: {
|
||||
onlyUseSystemMessageTools: manualSetting,
|
||||
},
|
||||
},
|
||||
},
|
||||
} as any;
|
||||
};
|
||||
|
||||
const createModel = (provider: string, model: string): ModelDescription => ({
|
||||
title: "Test Model",
|
||||
provider,
|
||||
underlyingProviderName: provider,
|
||||
model,
|
||||
});
|
||||
|
||||
test("auto-detection takes priority: OpenRouter non-Claude returns true even with manual false", () => {
|
||||
mockSelectSelectedChatModel.mockReturnValue(
|
||||
createModel("openrouter", "gpt-4"),
|
||||
);
|
||||
const state = createMockState(false);
|
||||
expect(selectUseSystemMessageTools(state)).toBe(true);
|
||||
});
|
||||
|
||||
test("auto-detection takes priority: OpenRouter Claude returns false even with manual true", () => {
|
||||
mockSelectSelectedChatModel.mockReturnValue(
|
||||
createModel("openrouter", "claude-3.5-sonnet"),
|
||||
);
|
||||
const state = createMockState(true);
|
||||
expect(selectUseSystemMessageTools(state)).toBe(false);
|
||||
});
|
||||
|
||||
test("falls back to manual setting when no auto-preference: manual true", () => {
|
||||
mockSelectSelectedChatModel.mockReturnValue(createModel("openai", "gpt-4"));
|
||||
const state = createMockState(true);
|
||||
expect(selectUseSystemMessageTools(state)).toBe(true);
|
||||
});
|
||||
|
||||
test("falls back to manual setting when no auto-preference: manual false", () => {
|
||||
mockSelectSelectedChatModel.mockReturnValue(
|
||||
createModel("anthropic", "claude-3.5-sonnet"),
|
||||
);
|
||||
const state = createMockState(false);
|
||||
expect(selectUseSystemMessageTools(state)).toBe(false);
|
||||
});
|
||||
|
||||
test("defaults to false when no auto-preference and no manual setting", () => {
|
||||
mockSelectSelectedChatModel.mockReturnValue(
|
||||
createModel("groq", "llama-3.3-70b"),
|
||||
);
|
||||
const state = createMockState(undefined);
|
||||
expect(selectUseSystemMessageTools(state)).toBe(false);
|
||||
});
|
||||
|
||||
test("handles missing selected model: uses manual setting", () => {
|
||||
mockSelectSelectedChatModel.mockReturnValue(undefined);
|
||||
const state = createMockState(true);
|
||||
expect(selectUseSystemMessageTools(state)).toBe(true);
|
||||
});
|
||||
|
||||
test("handles missing selected model: defaults to false when no manual setting", () => {
|
||||
mockSelectSelectedChatModel.mockReturnValue(undefined);
|
||||
const state = createMockState(undefined);
|
||||
expect(selectUseSystemMessageTools(state)).toBe(false);
|
||||
});
|
||||
|
||||
test("auto-enable works for various OpenRouter models", () => {
|
||||
mockSelectSelectedChatModel.mockReturnValue(
|
||||
createModel("openrouter", "gpt-4o"),
|
||||
);
|
||||
expect(selectUseSystemMessageTools(createMockState(false))).toBe(true);
|
||||
|
||||
mockSelectSelectedChatModel.mockReturnValue(
|
||||
createModel("openrouter", "llama-3.3-70b"),
|
||||
);
|
||||
expect(selectUseSystemMessageTools(createMockState(false))).toBe(true);
|
||||
|
||||
mockSelectSelectedChatModel.mockReturnValue(
|
||||
createModel("openrouter", "claude-haiku"),
|
||||
);
|
||||
expect(selectUseSystemMessageTools(createMockState(true))).toBe(false);
|
||||
});
|
||||
});
|
||||
|
|
@ -1,37 +0,0 @@
|
|||
import { shouldAutoEnableSystemMessageTools } from "core/config/shouldAutoEnableSystemMessageTools";
|
||||
import { selectSelectedChatModel } from "../slices/configSlice";
|
||||
import { RootState } from "../store";
|
||||
|
||||
/**
|
||||
* Selector that determines if system message tools should be used.
|
||||
* This prioritizes auto-detection over manual configuration where we have a strong preference.
|
||||
*
|
||||
* Priority order:
|
||||
* 1. Auto-detection (if it returns true/false)
|
||||
* 2. Manual user configuration (if auto-detection returns undefined)
|
||||
* 3. Default to false
|
||||
*
|
||||
* @param state The Redux root state
|
||||
* @returns true if system message tools should be used, false otherwise
|
||||
*/
|
||||
export function selectUseSystemMessageTools(state: RootState): boolean {
|
||||
const selectedModel = selectSelectedChatModel(state);
|
||||
const manualSetting =
|
||||
state.config.config.experimental?.onlyUseSystemMessageTools;
|
||||
|
||||
// If no model is selected, fall back to manual setting or default
|
||||
if (!selectedModel) {
|
||||
return manualSetting ?? false;
|
||||
}
|
||||
|
||||
// Check auto-detection first
|
||||
const autoSetting = shouldAutoEnableSystemMessageTools(selectedModel);
|
||||
|
||||
// If auto-detection has a preference, use it (takes priority)
|
||||
if (autoSetting !== undefined) {
|
||||
return autoSetting;
|
||||
}
|
||||
|
||||
// If no auto-preference, use manual setting or default to false
|
||||
return manualSetting ?? false;
|
||||
}
|
||||
|
|
@ -3,7 +3,6 @@ import { LLMFullCompletionOptions, Tool } from "core";
|
|||
import { getRuleId } from "core/llm/rules/getSystemMessageWithRules";
|
||||
import { ToCoreProtocol } from "core/protocol";
|
||||
import { selectActiveTools } from "../selectors/selectActiveTools";
|
||||
import { selectUseSystemMessageTools } from "../selectors/selectUseSystemMessageTools";
|
||||
import { selectSelectedChatModel } from "../slices/configSlice";
|
||||
import {
|
||||
abortStream,
|
||||
|
|
@ -105,12 +104,12 @@ export const streamNormalInput = createAsyncThunk<
|
|||
// Get tools and filter them based on the selected model
|
||||
const activeTools = selectActiveTools(state);
|
||||
|
||||
const supportsNativeTools = modelSupportsNativeTools(selectedChatModel);
|
||||
|
||||
// Use the centralized selector to determine if system message tools should be used
|
||||
const useSystemTools = selectUseSystemMessageTools(state);
|
||||
const useNativeTools = !useSystemTools && supportsNativeTools;
|
||||
const systemToolsFramework = useSystemTools
|
||||
const useNativeTools = state.config.config.experimental
|
||||
?.onlyUseSystemMessageTools
|
||||
? false
|
||||
: modelSupportsNativeTools(selectedChatModel);
|
||||
const systemToolsFramework = !useNativeTools
|
||||
? new SystemMessageToolCodeblocksFramework()
|
||||
: undefined;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue