diff --git a/core/config/load.ts b/core/config/load.ts index a084bbd38..0db0b72aa 100644 --- a/core/config/load.ts +++ b/core/config/load.ts @@ -643,6 +643,7 @@ function llmToSerializedModelDescription(llm: ILLM): ModelDescription { template: llm.template, completionOptions: llm.completionOptions, baseAgentSystemMessage: llm.baseAgentSystemMessage, + basePlanSystemMessage: llm.basePlanSystemMessage, baseChatSystemMessage: llm.baseChatSystemMessage, requestOptions: llm.requestOptions, promptTemplates: serializePromptTemplates(llm.promptTemplates), diff --git a/core/config/yaml/models.ts b/core/config/yaml/models.ts index edb47f59e..f1a3df43b 100644 --- a/core/config/yaml/models.ts +++ b/core/config/yaml/models.ts @@ -63,6 +63,7 @@ async function modelConfigToBaseLLM({ template: model.promptTemplates?.chat, promptTemplates: model.promptTemplates, baseAgentSystemMessage: model.chatOptions?.baseAgentSystemMessage, + basePlanSystemMessage: model.chatOptions?.basePlanSystemMessage, baseChatSystemMessage: model.chatOptions?.baseSystemMessage, capabilities: { tools: model.capabilities?.includes("tool_use"), diff --git a/core/index.d.ts b/core/index.d.ts index 997ffd85e..3c5931440 100644 --- a/core/index.d.ts +++ b/core/index.d.ts @@ -428,7 +428,7 @@ export interface PromptLog { completion: string; } -export type MessageModes = "chat" | "agent"; +export type MessageModes = "chat" | "agent" | "plan"; export type ToolStatus = | "generating" @@ -568,6 +568,7 @@ export interface LLMOptions { title?: string; uniqueId?: string; baseAgentSystemMessage?: string; + basePlanSystemMessage?: string; baseChatSystemMessage?: string; autocompleteOptions?: Partial; contextLength?: number; @@ -1091,6 +1092,7 @@ export interface ModelDescription { template?: TemplateType; completionOptions?: BaseCompletionOptions; baseAgentSystemMessage?: string; + basePlanSystemMessage?: string; baseChatSystemMessage?: string; requestOptions?: RequestOptions; promptTemplates?: { [key: string]: string }; @@ -1637,9 +1639,11 @@ export interface TerminalOptions { export type RuleSource = | "default-chat" + | "default-plan" | "default-agent" - | "model-chat-options" - | "model-agent-options" + | "model-options-chat" + | "model-options-plan" + | "model-options-agent" | "rules-block" | "json-systemMessage" | ".continuerules"; diff --git a/core/llm/defaultSystemMessages.ts b/core/llm/defaultSystemMessages.ts index c2f82bac4..a6b3afc6c 100644 --- a/core/llm/defaultSystemMessages.ts +++ b/core/llm/defaultSystemMessages.ts @@ -1,7 +1,4 @@ -export const DEFAULT_CHAT_SYSTEM_MESSAGE_URL = - "https://github.com/continuedev/continue/blob/main/core/llm/defaultSystemMessages.ts"; - -export const DEFAULT_AGENT_SYSTEM_MESSAGE_URL = +export const DEFAULT_SYSTEM_MESSAGES_URL = "https://github.com/continuedev/continue/blob/main/core/llm/defaultSystemMessages.ts"; export const CODEBLOCK_FORMATTING_INSTRUCTIONS = `\ @@ -66,3 +63,17 @@ export const DEFAULT_AGENT_SYSTEM_MESSAGE = `\ ${CODEBLOCK_FORMATTING_INSTRUCTIONS} `; + +// The note about read-only tools is for MCP servers +// For now, all MCP tools are included so model can decide if they are read-only +export const DEFAULT_PLAN_SYSTEM_MESSAGE = `\ + + You are in plan mode, in which you help the user understand and construct a plan. + Only use read-only tools. Do not use any tools that would write to non-temporary files. + If the user wants to make changes, offer that they can switch to Agent mode to give you access to write tools to make the suggested updates. + +${CODEBLOCK_FORMATTING_INSTRUCTIONS} +${EDIT_CODE_INSTRUCTIONS} + + In plan mode, only write code when directly suggesting changes. Prioritize understanding and developing a plan. +`; diff --git a/core/llm/index.ts b/core/llm/index.ts index 47fdf8011..5fc3d6c2b 100644 --- a/core/llm/index.ts +++ b/core/llm/index.ts @@ -141,6 +141,7 @@ export abstract class BaseLLM implements ILLM { title?: string; baseChatSystemMessage?: string; + basePlanSystemMessage?: string; baseAgentSystemMessage?: string; contextLength: number; maxStopWords?: number | undefined; @@ -209,6 +210,7 @@ export abstract class BaseLLM implements ILLM { this.title = options.title; this.uniqueId = options.uniqueId ?? "None"; this.baseAgentSystemMessage = options.baseAgentSystemMessage; + this.basePlanSystemMessage = options.basePlanSystemMessage; this.baseChatSystemMessage = options.baseChatSystemMessage; this.contextLength = options.contextLength ?? llmInfo?.contextLength ?? DEFAULT_CONTEXT_LENGTH; diff --git a/core/llm/llms/index.ts b/core/llm/llms/index.ts index e45828c40..0522bbda6 100644 --- a/core/llm/llms/index.ts +++ b/core/llm/llms/index.ts @@ -8,7 +8,6 @@ import { LLMOptions, } from "../.."; import { renderTemplatedString } from "../../util/handlebars/renderTemplatedString"; -import { DEFAULT_CHAT_SYSTEM_MESSAGE } from "../defaultSystemMessages"; import { BaseLLM } from "../index"; import Anthropic from "./Anthropic"; import Asksage from "./Asksage"; @@ -141,9 +140,9 @@ export async function llmFromDescription( let baseChatSystemMessage: string | undefined = undefined; if (desc.systemMessage !== undefined) { - baseChatSystemMessage = DEFAULT_CHAT_SYSTEM_MESSAGE; - baseChatSystemMessage += "\n\n"; - baseChatSystemMessage += await renderTemplatedString( + // baseChatSystemMessage = DEFAULT_CHAT_SYSTEM_MESSAGE; + // baseChatSystemMessage += "\n\n"; + baseChatSystemMessage = await renderTemplatedString( Handlebars, desc.systemMessage, {}, @@ -163,6 +162,7 @@ export async function llmFromDescription( cls.defaultOptions?.completionOptions?.maxTokens, }, baseChatSystemMessage, + basePlanSystemMessage: baseChatSystemMessage, baseAgentSystemMessage: baseChatSystemMessage, logger: llmLogger, uniqueId, diff --git a/gui/src/components/ModeSelect/ModeIcon.tsx b/gui/src/components/ModeSelect/ModeIcon.tsx index 83201d5ae..92dfc1723 100644 --- a/gui/src/components/ModeSelect/ModeIcon.tsx +++ b/gui/src/components/ModeSelect/ModeIcon.tsx @@ -1,4 +1,8 @@ -import { ChatBubbleLeftIcon, SparklesIcon } from "@heroicons/react/24/outline"; +import { + ChatBubbleLeftIcon, + SparklesIcon, + SwatchIcon, +} from "@heroicons/react/24/outline"; import { MessageModes } from "core"; interface ModeIconProps { @@ -13,6 +17,8 @@ export function ModeIcon({ switch (mode) { case "agent": return ; + case "plan": + return ; case "chat": return ; } diff --git a/gui/src/components/ModeSelect/ModeSelect.tsx b/gui/src/components/ModeSelect/ModeSelect.tsx index 9e1b5afef..9de391852 100644 --- a/gui/src/components/ModeSelect/ModeSelect.tsx +++ b/gui/src/components/ModeSelect/ModeSelect.tsx @@ -1,4 +1,8 @@ -import { CheckIcon, ChevronDownIcon } from "@heroicons/react/24/outline"; +import { + CheckIcon, + ChevronDownIcon, + InformationCircleIcon, +} from "@heroicons/react/24/outline"; import { MessageModes } from "core"; import { modelSupportsTools } from "core/llm/autodetect"; import { useCallback, useEffect, useMemo } from "react"; @@ -6,6 +10,7 @@ import { useAppDispatch, useAppSelector } from "../../redux/hooks"; import { selectSelectedChatModel } from "../../redux/slices/configSlice"; import { setMode } from "../../redux/slices/sessionSlice"; import { getFontSize, getMetaKeyLabel } from "../../util"; +import { ToolTip } from "../gui/Tooltip"; import { useMainEditor } from "../mainInput/TipTapEditor"; import { Listbox, ListboxButton, ListboxOption, ListboxOptions } from "../ui"; import { ModeIcon } from "./ModeIcon"; @@ -27,13 +32,19 @@ export function ModeSelect() { if (!selectedModel) { return; } - if (mode === "agent" && !agentModeSupported) { + if (mode !== "chat" && !agentModeSupported) { dispatch(setMode("chat")); } }, [mode, agentModeSupported, dispatch, selectedModel]); const cycleMode = useCallback(() => { - dispatch(setMode(mode === "chat" ? "agent" : "chat")); + if (mode === "chat") { + dispatch(setMode("plan")); + } else if (mode === "plan") { + dispatch(setMode("agent")); + } else { + dispatch(setMode("chat")); + } // Only focus main editor if another one doesn't already have focus if (!document.activeElement?.classList?.contains("ProseMirror")) { mainEditor?.commands.focus(); @@ -74,7 +85,7 @@ export function ModeSelect() { > - {mode.charAt(0).toUpperCase() + mode.slice(1)} + {mode === "chat" ? "Chat" : mode === "agent" ? "Agent" : "Plan"} {mode === "chat" && } - + +
+ + Plan + + + In Plan mode, only read-only and MCP tools are enabled + +
+ {agentModeSupported ? ( + + ) : ( + (Not supported) + )} +
Agent + + + All tools are enabled based on policies + {agentModeSupported ? ( - mode === "agent" && + ) : ( (Not supported) )} diff --git a/gui/src/components/gui/Switch.tsx b/gui/src/components/gui/Switch.tsx index 7004ae9d8..2422c6cd5 100644 --- a/gui/src/components/gui/Switch.tsx +++ b/gui/src/components/gui/Switch.tsx @@ -7,6 +7,7 @@ type ToggleSwitchProps = { text: string; size?: number; showIfToggled?: ReactNode; + disabled?: boolean; }; const ToggleSwitch: React.FC = ({ @@ -15,15 +16,18 @@ const ToggleSwitch: React.FC = ({ text, size = 16, showIfToggled, + disabled = false, }) => { return ( -
+
{text}
{isToggled && !!showIfToggled && showIfToggled}
= ({ rule }) => { ideMessenger.post("openFile", { path: rule.ruleFile, }); - } else if (rule.source === "default-chat" && mode === "chat") { - ideMessenger.post("openUrl", DEFAULT_CHAT_SYSTEM_MESSAGE_URL); - } else if (rule.source === "default-agent" && mode === "agent") { - ideMessenger.post("openUrl", DEFAULT_AGENT_SYSTEM_MESSAGE_URL); + } else if ( + rule.source === "default-chat" || + rule.source === "default-plan" || + rule.source === "default-agent" + ) { + ideMessenger.post("openUrl", DEFAULT_SYSTEM_MESSAGES_URL); } else { ideMessenger.post("config/openProfile", { profileId: undefined, @@ -81,9 +82,11 @@ const RuleCard: React.FC = ({ rule }) => { return "Default agent system message"; } else if (rule.source === "json-systemMessage") { return "JSON systemMessage)"; - } else if (rule.source === "model-agent-options") { + } else if (rule.source === "model-options-agent") { return "Base System Agent Message"; - } else if (rule.source === "model-chat-options") { + } else if (rule.source === "model-options-plan") { + return "Base System Plan Message"; + } else if (rule.source === "model-options-chat") { return "Base System Chat Message"; } else { return "Assistant rule"; @@ -215,11 +218,24 @@ export function RulesSection() { } } - if (mode === "agent") { + if (mode === "chat") { + if (config.selectedModelByRole.chat?.baseChatSystemMessage) { + rules.unshift({ + rule: config.selectedModelByRole.chat?.baseChatSystemMessage, + source: "model-options-chat", + }); + } else { + rules.unshift({ + rule: DEFAULT_CHAT_SYSTEM_MESSAGE, + source: "default-chat", + }); + } + } else if (mode === "agent") { + // agent if (config.selectedModelByRole.chat?.baseAgentSystemMessage) { rules.unshift({ rule: config.selectedModelByRole.chat?.baseAgentSystemMessage, - source: "model-agent-options", + source: "model-options-agent", }); } else { rules.unshift({ @@ -228,15 +244,16 @@ export function RulesSection() { }); } } else { - if (config.selectedModelByRole.chat?.baseChatSystemMessage) { + // plan + if (config.selectedModelByRole.chat?.basePlanSystemMessage) { rules.unshift({ - rule: config.selectedModelByRole.chat?.baseChatSystemMessage, - source: "model-chat-options", + rule: config.selectedModelByRole.chat?.basePlanSystemMessage, + source: "model-options-plan", }); } else { rules.unshift({ - rule: DEFAULT_CHAT_SYSTEM_MESSAGE, - source: "default-chat", + rule: DEFAULT_AGENT_SYSTEM_MESSAGE, + source: "default-agent", }); } } diff --git a/gui/src/components/mainInput/Lump/sections/tool-policies/ToolPoliciesSection.tsx b/gui/src/components/mainInput/Lump/sections/tool-policies/ToolPoliciesSection.tsx index c6e96c16b..9303f3392 100644 --- a/gui/src/components/mainInput/Lump/sections/tool-policies/ToolPoliciesSection.tsx +++ b/gui/src/components/mainInput/Lump/sections/tool-policies/ToolPoliciesSection.tsx @@ -1,3 +1,4 @@ +import { InformationCircleIcon } from "@heroicons/react/24/outline"; import { Tool } from "core"; import { useMemo } from "react"; import { useAppDispatch, useAppSelector } from "../../../../../redux/hooks"; @@ -6,7 +7,26 @@ import { fontSize } from "../../../../../util"; import ToggleSwitch from "../../../../gui/Switch"; import ToolPolicyItem from "./ToolPolicyItem"; +interface ModeBadgeProps { + text: string; + icon: React.ReactNode; + onClick: () => void; + isSelected: boolean; +} +const ModeBadge = ({ text, onClick, isSelected, icon }: ModeBadgeProps) => { + return ( +
+ {icon} + {text} +
+ ); +}; + export const ToolPoliciesSection = () => { + const mode = useAppSelector((state) => state.session.mode); const availableTools = useAppSelector((state) => state.config.config.tools); const toolGroupSettings = useAppSelector( (store) => store.ui.toolGroupSettings, @@ -39,38 +59,56 @@ export const ToolPoliciesSection = () => { ); }, [availableTools]); + const allToolsOff = mode === "chat"; + + const message = + mode === "chat" + ? "All tools are disabled in Chat mode" + : mode === "plan" + ? "Plan mode: only read-only and MCP tools" + : "Agent mode: all tool policies apply"; + return ( <> - {toolsByGroup.map(([groupName, tools]) => ( -
-
-

- {groupName} -

- dispatch(toggleToolGroupSetting(groupName))} - text="" - size={10} - /> -
-
- {tools.map((tool) => ( - + + {message} +
+ {toolsByGroup.map(([groupName, tools]) => { + const isGroupEnabled = + !allToolsOff && toolGroupSettings[groupName] !== "exclude"; + return ( +
+
+

+ {groupName} +

+ dispatch(toggleToolGroupSetting(groupName))} + text="" + size={10} + disabled={allToolsOff} /> - ))} +
+
+ {tools.map((tool) => ( + + ))} +
-
- ))} + ); + })} ); }; diff --git a/gui/src/components/mainInput/Lump/sections/tool-policies/ToolPolicyItem.tsx b/gui/src/components/mainInput/Lump/sections/tool-policies/ToolPolicyItem.tsx index b92816839..edccf3923 100644 --- a/gui/src/components/mainInput/Lump/sections/tool-policies/ToolPolicyItem.tsx +++ b/gui/src/components/mainInput/Lump/sections/tool-policies/ToolPolicyItem.tsx @@ -3,6 +3,7 @@ import { InformationCircleIcon, } from "@heroicons/react/24/outline"; import { Tool } from "core"; +import { BUILT_IN_GROUP_NAME } from "core/tools/builtIn"; import { useEffect, useMemo, useState } from "react"; import { useDispatch } from "react-redux"; import { useAppSelector } from "../../../../../redux/hooks"; @@ -16,7 +17,7 @@ import { useFontSize } from "../../../../ui/font"; interface ToolDropdownItemProps { tool: Tool; duplicatesDetected: boolean; - excluded: boolean; + isGroupEnabled: boolean; } function ToolPolicyItem(props: ToolDropdownItemProps) { @@ -25,6 +26,7 @@ function ToolPolicyItem(props: ToolDropdownItemProps) { (state) => state.ui.toolSettings[props.tool.function.name], ); const [isExpanded, setIsExpanded] = useState(false); + const mode = useAppSelector((state) => state.session.mode); useEffect(() => { if (!policy) { @@ -44,6 +46,12 @@ function ToolPolicyItem(props: ToolDropdownItemProps) { const fontSize = useFontSize(-2); + const disabled = + !props.isGroupEnabled || + (mode === "plan" && + props.tool.group === BUILT_IN_GROUP_NAME && + !props.tool.readonly); + if (!policy) { return null; } @@ -106,16 +114,21 @@ function ToolPolicyItem(props: ToolDropdownItemProps) {
+
{ - dispatch(toggleToolSetting(props.tool.function.name)); - e.stopPropagation(); - e.preventDefault(); - }} + onClick={ + disabled + ? undefined + : (e) => { + dispatch(toggleToolSetting(props.tool.function.name)); + e.stopPropagation(); + e.preventDefault(); + } + } > - {props.excluded || policy === "disabled" ? ( + {disabled || policy === "disabled" ? ( <> Off diff --git a/gui/src/components/mainInput/belowMainInput/RulesPeek.tsx b/gui/src/components/mainInput/belowMainInput/RulesPeek.tsx index 992d5b491..c9c60acc7 100644 --- a/gui/src/components/mainInput/belowMainInput/RulesPeek.tsx +++ b/gui/src/components/mainInput/belowMainInput/RulesPeek.tsx @@ -19,9 +19,11 @@ const getSourceLabel = (source: RuleSource): string => { return "Default Chat"; case "default-agent": return "Default Agent"; - case "model-chat-options": + case "model-options-chat": return "Model Chat Options"; - case "model-agent-options": + case "model-options-plan": + return "Model Plan Options"; + case "model-options-agent": return "Model Agent Options"; case "rules-block": return "Rules Block"; diff --git a/gui/src/pages/gui/chat-tests/Chat.test.tsx b/gui/src/pages/gui/chat-tests/Chat.test.tsx index d3e6aa18b..b0164a437 100644 --- a/gui/src/pages/gui/chat-tests/Chat.test.tsx +++ b/gui/src/pages/gui/chat-tests/Chat.test.tsx @@ -27,6 +27,18 @@ test("should be able to toggle modes", async () => { ); }); + // Check that it switched to Plan mode + await getElementByText("Plan"); + + act(() => { + document.dispatchEvent( + new KeyboardEvent("keydown", { + key: ".", + metaKey: true, // cmd key on Mac + }), + ); + }); + // Check that it switched to Agent mode await getElementByText("Agent"); diff --git a/gui/src/redux/selectors/selectActiveTools.ts b/gui/src/redux/selectors/selectActiveTools.ts index 7aae43765..2e90bbfd5 100644 --- a/gui/src/redux/selectors/selectActiveTools.ts +++ b/gui/src/redux/selectors/selectActiveTools.ts @@ -1,5 +1,6 @@ import { createSelector } from "@reduxjs/toolkit"; import { Tool } from "core"; +import { BUILT_IN_GROUP_NAME } from "core/tools/builtIn"; import { RootState } from "../store"; export const selectActiveTools = createSelector( @@ -12,14 +13,18 @@ export const selectActiveTools = createSelector( (mode, tools, policies, groupPolicies): Tool[] => { if (mode === "chat") { return []; - } else if (mode === "agent") { - return tools.filter( + } else { + const enabledTools = tools.filter( (tool) => policies[tool.function.name] !== "disabled" && groupPolicies[tool.group] !== "exclude", ); - } else { - return []; + if (mode === "plan") { + return enabledTools.filter( + (t) => t.group !== BUILT_IN_GROUP_NAME || t.readonly, + ); + } + return enabledTools; } }, ); diff --git a/gui/src/redux/thunks/edit.ts b/gui/src/redux/thunks/edit.ts index 059b285ce..806b88fa7 100644 --- a/gui/src/redux/thunks/edit.ts +++ b/gui/src/redux/thunks/edit.ts @@ -75,52 +75,49 @@ export const streamEditThunk = createAsyncThunk< export const exitEdit = createAsyncThunk< void, - { goToMode?: MessageModes; openNewSession?: boolean }, + { openNewSession?: boolean }, ThunkApiType ->( - "edit/exit", - async ({ goToMode, openNewSession }, { dispatch, extra, getState }) => { - const state = getState(); - const codeToEdit = state.editModeState.codeToEdit; - const isInEdit = state.session.isInEdit; - const previousModeEditorContent = - state.editModeState.previousModeEditorContent; +>("edit/exit", async ({ openNewSession }, { dispatch, extra, getState }) => { + const state = getState(); + const codeToEdit = state.editModeState.codeToEdit; + const isInEdit = state.session.isInEdit; + const previousModeEditorContent = + state.editModeState.previousModeEditorContent; - if (!isInEdit) { - return; - } + if (!isInEdit) { + return; + } - if (codeToEdit[0] && state.editModeState.applyState.numDiffs) { - extra.ideMessenger.post("rejectDiff", { - filepath: codeToEdit[0].filepath, - }); - } + if (codeToEdit[0] && state.editModeState.applyState.numDiffs) { + extra.ideMessenger.post("rejectDiff", { + filepath: codeToEdit[0].filepath, + }); + } - extra.ideMessenger.post("edit/clearDecorations", undefined); + extra.ideMessenger.post("edit/clearDecorations", undefined); - dispatch(clearCodeToEdit()); - dispatch(updateEditStateApplyState(INITIAL_EDIT_APPLY_STATE)); - dispatch(setIsInEdit(false)); + dispatch(clearCodeToEdit()); + dispatch(updateEditStateApplyState(INITIAL_EDIT_APPLY_STATE)); + dispatch(setIsInEdit(false)); - // Restore the previous editor content if available - if (previousModeEditorContent) { - dispatch(setMainEditorContentTrigger(previousModeEditorContent)); - dispatch(setPreviousModeEditorContent(undefined)); - } + // Restore the previous editor content if available + if (previousModeEditorContent) { + dispatch(setMainEditorContentTrigger(previousModeEditorContent)); + dispatch(setPreviousModeEditorContent(undefined)); + } - if (openNewSession || state.editModeState.lastNonEditSessionWasEmpty) { - dispatch(newSession()); - } else { - await dispatch( - loadLastSession({ - saveCurrentSession: false, - }), - ); - } + if (openNewSession || state.editModeState.lastNonEditSessionWasEmpty) { + dispatch(newSession()); + } else { + await dispatch( + loadLastSession({ + saveCurrentSession: false, + }), + ); + } - dispatch(setMode(goToMode ?? state.editModeState.returnToMode)); - }, -); + dispatch(setMode(state.editModeState.returnToMode)); +}); export const enterEdit = createAsyncThunk< void, diff --git a/gui/src/redux/thunks/streamNormalInput.ts b/gui/src/redux/thunks/streamNormalInput.ts index c7c4de02d..ab86aa85c 100644 --- a/gui/src/redux/thunks/streamNormalInput.ts +++ b/gui/src/redux/thunks/streamNormalInput.ts @@ -115,21 +115,19 @@ export const streamNormalInput = createAsyncThunk< dispatch(addPromptCompletionPair([next.value])); try { - if (state.session.mode === "chat" || state.session.mode === "agent") { - extra.ideMessenger.post("devdata/log", { - name: "chatInteraction", - data: { - prompt: next.value.prompt, - completion: next.value.completion, - modelProvider: selectedChatModel.underlyingProviderName, - modelTitle: selectedChatModel.title, - sessionId: state.session.id, - ...(state.session.mode === "agent" && { - tools: activeTools.map((tool) => tool.function.name), - }), - }, - }); - } + extra.ideMessenger.post("devdata/log", { + name: "chatInteraction", + data: { + prompt: next.value.prompt, + completion: next.value.completion, + modelProvider: selectedChatModel.underlyingProviderName, + modelTitle: selectedChatModel.title, + sessionId: state.session.id, + ...(!!activeTools.length && { + tools: activeTools.map((tool) => tool.function.name), + }), + }, + }); // else if (state.session.mode === "edit") { // extra.ideMessenger.post("devdata/log", { // name: "editInteraction", diff --git a/gui/src/redux/thunks/streamThunkWrapper.tsx b/gui/src/redux/thunks/streamThunkWrapper.tsx index 6e5c032d4..0a29f3a8f 100644 --- a/gui/src/redux/thunks/streamThunkWrapper.tsx +++ b/gui/src/redux/thunks/streamThunkWrapper.tsx @@ -17,7 +17,7 @@ export const streamThunkWrapper = createAsyncThunk< try { await runStream(); const state = getState(); - if (state.session.mode === "chat" || state.session.mode === "agent") { + if (!state.session.isInEdit) { await dispatch( saveCurrentSession({ openNewSession: false, diff --git a/gui/src/redux/util/constructMessages.test.ts b/gui/src/redux/util/constructMessages.test.ts index 18ab0ed45..b1d808662 100644 --- a/gui/src/redux/util/constructMessages.test.ts +++ b/gui/src/redux/util/constructMessages.test.ts @@ -12,6 +12,7 @@ import { import { DEFAULT_AGENT_SYSTEM_MESSAGE, DEFAULT_CHAT_SYSTEM_MESSAGE, + DEFAULT_PLAN_SYSTEM_MESSAGE, } from "core/llm/defaultSystemMessages"; import { renderChatMessage } from "core/util/messageContent"; import { beforeEach, describe, expect, test, vi } from "vitest"; @@ -90,8 +91,9 @@ vi.mock("core/llm/rules/getSystemMessageWithRules", async (importOriginal) => { test("getBaseSystemMessage should return the correct system message based on mode", () => { const mockModel = { - baseAgentSystemMessage: "Custom Agent System Message", baseChatSystemMessage: "Custom Chat System Message", + basePlanSystemMessage: "Custom Plan System Message", + baseAgentSystemMessage: "Custom Agent System Message", } as ModelDescription; // Test agent mode with custom message @@ -99,6 +101,11 @@ test("getBaseSystemMessage should return the correct system message based on mod "Custom Agent System Message", ); + // Test plan mode with custom message + expect(getBaseSystemMessage("plan", mockModel)).toBe( + "Custom Plan System Message", + ); + // Test chat mode with custom message expect(getBaseSystemMessage("chat", mockModel)).toBe( "Custom Chat System Message", @@ -109,6 +116,11 @@ test("getBaseSystemMessage should return the correct system message based on mod DEFAULT_AGENT_SYSTEM_MESSAGE, ); + // Test agent mode with default message + expect(getBaseSystemMessage("plan", {} as ModelDescription)).toBe( + DEFAULT_PLAN_SYSTEM_MESSAGE, + ); + // Test chat mode with default message expect(getBaseSystemMessage("chat", {} as ModelDescription)).toBe( DEFAULT_CHAT_SYSTEM_MESSAGE, diff --git a/gui/src/redux/util/constructMessages.ts b/gui/src/redux/util/constructMessages.ts index 15f8120db..566608d67 100644 --- a/gui/src/redux/util/constructMessages.ts +++ b/gui/src/redux/util/constructMessages.ts @@ -11,6 +11,7 @@ import { import { DEFAULT_AGENT_SYSTEM_MESSAGE, DEFAULT_CHAT_SYSTEM_MESSAGE, + DEFAULT_PLAN_SYSTEM_MESSAGE, } from "core/llm/defaultSystemMessages"; import { chatMessageIsEmpty } from "core/llm/messages"; import { getSystemMessageWithRules } from "core/llm/rules/getSystemMessageWithRules"; @@ -167,6 +168,8 @@ export function getBaseSystemMessage( ): string { if (messageMode === "agent") { return model.baseAgentSystemMessage ?? DEFAULT_AGENT_SYSTEM_MESSAGE; + } else if (messageMode === "plan") { + return model.basePlanSystemMessage ?? DEFAULT_PLAN_SYSTEM_MESSAGE; } else { return model.baseChatSystemMessage ?? DEFAULT_CHAT_SYSTEM_MESSAGE; } diff --git a/packages/config-yaml/src/schemas/models.ts b/packages/config-yaml/src/schemas/models.ts index 99d324ac2..103cdff55 100644 --- a/packages/config-yaml/src/schemas/models.ts +++ b/packages/config-yaml/src/schemas/models.ts @@ -85,6 +85,7 @@ export type EmbedOptions = z.infer; export const chatOptionsSchema = z.object({ baseSystemMessage: z.string().optional(), baseAgentSystemMessage: z.string().optional(), + basePlanSystemMessage: z.string().optional(), }); export type ChatOptions = z.infer;