diff --git a/core/llm/autodetect.ts b/core/llm/autodetect.ts index a49749e2e..226102e88 100644 --- a/core/llm/autodetect.ts +++ b/core/llm/autodetect.ts @@ -85,8 +85,9 @@ const MODEL_SUPPORTS_IMAGES: string[] = [ "llama3.2", ]; -function modelSupportsTools(modelName: string) { +function modelSupportsTools(modelName: string, provider: string) { return ( + provider === "anthropic" && modelName.includes("claude") && (modelName.includes("3-5") || modelName.includes("3.5")) ); diff --git a/core/llm/constructMessages.ts b/core/llm/constructMessages.ts index 985506a08..7b6a5151a 100644 --- a/core/llm/constructMessages.ts +++ b/core/llm/constructMessages.ts @@ -66,11 +66,15 @@ Always follow these guidelines when generating code responses.`; const TOOL_USE_RULES = `When using tools, follow the following guidelines: - Avoid calling tools unless they are absolutely necessary. For example, if you are asked a simple programming question you do not need web search. As another example, if the user asks you to explain something about code, do not create a new file.`; -function constructSystemPrompt(model: string): string | null { +function constructSystemPrompt( + model: string, + provider: string, + useTools: boolean, +): string | null { if (CUSTOM_SYS_MSG_MODEL_FAMILIES.some((family) => model.includes(family))) { return SYSTEM_MESSAGE + "\n\n" + TOOL_USE_RULES; } - if (modelSupportsTools(model)) { + if (useTools && modelSupportsTools(model, provider)) { return TOOL_USE_RULES; } @@ -83,10 +87,12 @@ const CANCELED_TOOL_CALL_MESSAGE = export function constructMessages( history: ChatHistoryItem[], model: string, + provider: string, + useTools: boolean, ): ChatMessage[] { const msgs: ChatMessage[] = []; - const systemMessage = constructSystemPrompt(model); + const systemMessage = constructSystemPrompt(model, provider, useTools); if (systemMessage) { msgs.push({ role: "system" as const, diff --git a/gui/src/redux/thunks/streamResponse.ts b/gui/src/redux/thunks/streamResponse.ts index 1411828d3..3b70ecba1 100644 --- a/gui/src/redux/thunks/streamResponse.ts +++ b/gui/src/redux/thunks/streamResponse.ts @@ -4,18 +4,18 @@ import { InputModifiers, MessageContent, SlashCommandDescription } from "core"; import { constructMessages } from "core/llm/constructMessages"; import { renderChatMessage } from "core/util/messageContent"; import posthog from "posthog-js"; +import { v4 as uuidv4 } from "uuid"; +import { selectDefaultModel } from "../slices/configSlice"; import { submitEditorAndInitAtIndex, updateHistoryItemAtIndex, } from "../slices/sessionSlice"; import { ThunkApiType } from "../store"; import { gatherContext } from "./gatherContext"; -import { streamThunkWrapper } from "./streamThunkWrapper"; import { resetStateForNewMessage } from "./resetStateForNewMessage"; import { streamNormalInput } from "./streamNormalInput"; import { streamSlashCommand } from "./streamSlashCommand"; -import { selectDefaultModel } from "../slices/configSlice"; -import { v4 as uuidv4 } from "uuid"; +import { streamThunkWrapper } from "./streamThunkWrapper"; const getSlashCommandForInput = ( input: MessageContent, @@ -61,6 +61,7 @@ export const streamResponseThunk = createAsyncThunk< await dispatch( streamThunkWrapper(async () => { const state = getState(); + const useTools = state.ui.useTools; const defaultModel = selectDefaultModel(state); const slashCommands = state.config.config.slashCommands || []; const inputIndex = index ?? state.session.history.length; @@ -94,7 +95,12 @@ export const streamResponseThunk = createAsyncThunk< // Construct messages from updated history const updatedHistory = getState().session.history; - const messages = constructMessages(updatedHistory, defaultModel.model); + const messages = constructMessages( + updatedHistory, + defaultModel.model, + defaultModel.provider, + useTools, + ); posthog.capture("step run", { step_name: "User Input", diff --git a/gui/src/redux/thunks/streamResponseAfterToolCall.ts b/gui/src/redux/thunks/streamResponseAfterToolCall.ts index 39ba0a24a..fd503560e 100644 --- a/gui/src/redux/thunks/streamResponseAfterToolCall.ts +++ b/gui/src/redux/thunks/streamResponseAfterToolCall.ts @@ -9,9 +9,9 @@ import { streamUpdate, } from "../slices/sessionSlice"; import { ThunkApiType } from "../store"; -import { streamThunkWrapper } from "./streamThunkWrapper"; import { resetStateForNewMessage } from "./resetStateForNewMessage"; import { streamNormalInput } from "./streamNormalInput"; +import { streamThunkWrapper } from "./streamThunkWrapper"; export const streamResponseAfterToolCall = createAsyncThunk< void, @@ -26,6 +26,7 @@ export const streamResponseAfterToolCall = createAsyncThunk< await dispatch( streamThunkWrapper(async () => { const state = getState(); + const useTools = state.ui.useTools; const initialHistory = state.session.history; const defaultModel = selectDefaultModel(state); @@ -59,6 +60,8 @@ export const streamResponseAfterToolCall = createAsyncThunk< const messages = constructMessages( [...updatedHistory], defaultModel.model, + defaultModel.provider, + useTools, ); unwrapResult(await dispatch(streamNormalInput(messages))); }),