Skip to content

πŸ™Œ OpenHands: AI-Driven Development

Remove agent from the LLM settings page (#14033)

Graham Neubig71ce61acd274
diff --git a/frontend/__tests__/routes/llm-settings.test.tsx b/frontend/__tests__/routes/llm-settings.test.tsx
index 740dcc0ff1..0106dbb6e9 100644
--- a/frontend/__tests__/routes/llm-settings.test.tsx
+++ b/frontend/__tests__/routes/llm-settings.test.tsx
@@ -250,24 +250,18 @@ describe("LlmSettingsScreen", () => {
}
baseUrlField.default = "https://schema.default/v1";
- schema.sections.push({
- key: "general",
- label: "General",
- fields: [
- {
- key: "agent",
- label: "Agent",
- section: "general",
- section_label: "General",
- value_type: "string",
- default: "CodeActAgent",
- choices: [],
- depends_on: [],
- prominence: "major",
- secret: false,
- required: true,
- },
- ],
+ llmSection?.fields.push({
+ key: "llm.timeout",
+ label: "Timeout",
+ section: "llm",
+ section_label: "LLM",
+ value_type: "integer",
+ default: 30,
+ choices: [],
+ depends_on: [],
+ prominence: "major",
+ secret: false,
+ required: false,
});
vi.spyOn(SettingsService, "getSettings").mockResolvedValue(
@@ -292,7 +286,7 @@ describe("LlmSettingsScreen", () => {
);
});
- it("keeps the current agent visible in advanced view when the schema omits agent choices", async () => {
+ it("does not render the agent field even when the schema includes it", async () => {
const schema = structuredClone(
MOCK_DEFAULT_USER_SETTINGS.agent_settings_schema!,
);
@@ -336,9 +330,7 @@ describe("LlmSettingsScreen", () => {
await screen.findByTestId("llm-settings-form-advanced");
- await waitFor(() => {
- expect(screen.getByTestId("agent-input")).toHaveValue("BrowsingAgent");
- });
+ expect(screen.queryByTestId("agent-input")).not.toBeInTheDocument();
});
it("uses the docs.openhands.dev domain for the API key help link", async () => {
@@ -706,7 +698,6 @@ describe("LlmSettingsScreen", () => {
expect(saveSettingsSpy).toHaveBeenCalledWith(
expect.objectContaining({
agent_settings: expect.objectContaining({
- agent: "CodeActAgent",
llm: expect.objectContaining({
api_key: "test-api-key",
base_url: "https://schema.default/v1",
@@ -716,6 +707,133 @@ describe("LlmSettingsScreen", () => {
}),
);
});
+
+ const payload = saveSettingsSpy.mock.calls[0]?.[0] as Record<
+ string,
+ unknown
+ >;
+ expect(
+ (payload.agent_settings as Record<string, unknown>) ?? {},
+ ).not.toHaveProperty("agent");
+ });
+
+ it("preserves existing MCP settings when saving the LLM page", async () => {
+ const schema = structuredClone(
+ MOCK_DEFAULT_USER_SETTINGS.agent_settings_schema!,
+ );
+ const existingMcpConfig = {
+ mcpServers: {
+ tavily: {
+ transport: "http",
+ url: "https://example.com/mcp",
+ },
+ },
+ };
+
+ schema.sections.push({
+ key: "general",
+ label: "General",
+ fields: [
+ {
+ key: "agent",
+ label: "Agent",
+ section: "general",
+ section_label: "General",
+ value_type: "string",
+ default: "CodeActAgent",
+ choices: [],
+ depends_on: [],
+ prominence: "major",
+ secret: false,
+ required: true,
+ },
+ {
+ key: "mcp_config",
+ label: "MCP Config",
+ section: "general",
+ section_label: "General",
+ value_type: "object",
+ default: null,
+ choices: [],
+ depends_on: [],
+ prominence: "major",
+ secret: false,
+ required: false,
+ },
+ ],
+ });
+
+ let persistedSettings = buildSettingsWithAdvancedToggle({
+ llm_model: "openai/gpt-4o",
+ agent_settings_schema: schema,
+ agent_settings: {
+ agent: "BrowsingAgent",
+ llm: {
+ model: "openai/gpt-4o",
+ },
+ mcp_config: existingMcpConfig,
+ },
+ });
+
+ const getSettingsSpy = vi
+ .spyOn(SettingsService, "getSettings")
+ .mockImplementation(async () => structuredClone(persistedSettings));
+ const saveSettingsSpy = vi
+ .spyOn(SettingsService, "saveSettings")
+ .mockImplementation(async (payload) => {
+ const payloadAgentSettings = (payload.agent_settings ?? {}) as Record<
+ string,
+ unknown
+ >;
+
+ const nextAgentSettings: NonNullable<Settings["agent_settings"]> = {
+ ...(persistedSettings.agent_settings ?? {}),
+ ...(payloadAgentSettings as Record<string, SettingsValue>),
+ llm: {
+ ...((persistedSettings.agent_settings?.llm as Record<
+ string,
+ SettingsValue
+ >) ?? {}),
+ ...((payloadAgentSettings.llm as Record<string, SettingsValue>) ?? {}),
+ },
+ };
+
+ persistedSettings = buildSettingsWithAdvancedToggle({
+ ...persistedSettings,
+ agent_settings_schema: schema,
+ agent_settings: nextAgentSettings,
+ });
+
+ return true;
+ });
+
+ renderLlmSettingsScreen({ appMode: "oss" });
+
+ await screen.findByTestId("llm-settings-form-basic");
+
+ const apiKeyInput = await screen.findByTestId("llm-api-key-input");
+ await userEvent.type(apiKeyInput, "test-api-key");
+ await userEvent.click(screen.getByTestId("save-button"));
+
+ await waitFor(() => {
+ expect(saveSettingsSpy).toHaveBeenCalledTimes(1);
+ });
+
+ const payload = saveSettingsSpy.mock.calls[0]?.[0] as Record<
+ string,
+ unknown
+ >;
+ expect(
+ (payload.agent_settings as Record<string, unknown>) ?? {},
+ ).not.toHaveProperty("mcp_config");
+
+ await waitFor(() => {
+ expect(getSettingsSpy).toHaveBeenCalledTimes(2);
+ });
+
+ expect(persistedSettings.agent_settings?.mcp_config).toEqual(
+ existingMcpConfig,
+ );
});
it("does not include search API key updates when saving basic LLM settings", async () => {
@@ -772,7 +890,10 @@ describe("LlmSettingsScreen", () => {
);
});
- const payload = saveSettingsSpy.mock.calls[0]?.[0] as Record<string, unknown>;
+ const payload = saveSettingsSpy.mock.calls[0]?.[0] as Record<
+ string,
+ unknown
+ >;
expect(payload).not.toHaveProperty("search_api_key");
await waitFor(() => {
@@ -1091,7 +1212,9 @@ describe("LlmSettingsScreen", () => {
expect(
screen.getByTestId("llm-settings-form-advanced"),
).toBeInTheDocument();
- expect(screen.queryByTestId("search-api-key-input")).not.toBeInTheDocument();
+ expect(
+ screen.queryByTestId("search-api-key-input"),
+ ).not.toBeInTheDocument();
});
});
@@ -1174,10 +1297,8 @@ describe("LlmSettingsScreen", () => {
renderLlmSettingsScreen({ appMode: "oss" });
await screen.findByTestId("llm-settings-form-basic");
- await userEvent.click(screen.getByTestId("sdk-section-advanced-toggle"));
- expect(
- screen.queryByTestId("sdk-settings-llm.timeout"),
- ).not.toBeInTheDocument();
+ await userEvent.click(screen.getByTestId("sdk-section-all-toggle"));
+ expect(screen.getByTestId("sdk-settings-llm.timeout")).toBeInTheDocument();
const apiKeyInput = await screen.findByTestId("llm-api-key-input");
await userEvent.type(apiKeyInput, "test-api-key");
diff --git a/frontend/src/routes/llm-settings.tsx b/frontend/src/routes/llm-settings.tsx
index c48aba90d7..4a3680bc8e 100644
--- a/frontend/src/routes/llm-settings.tsx
+++ b/frontend/src/routes/llm-settings.tsx
@@ -10,7 +10,6 @@ import { HelpLink } from "#/ui/help-link";
import { useConfig } from "#/hooks/query/use-config";
import { KeyStatusIcon } from "#/components/features/settings/key-status-icon";
import { useOrgTypeAndAccess } from "#/hooks/use-org-type-and-access";
-import { SettingsDropdownInput } from "#/components/features/settings/settings-dropdown-input";
import {
SdkSectionHeaderProps,
SdkSectionPage,
@@ -29,28 +28,13 @@ import {
} from "#/utils/sdk-settings-schema";
import { DEFAULT_SETTINGS } from "#/services/settings";
-const LLM_EXCLUDED_KEYS = new Set([
- "llm.model",
- "llm.api_key",
- "llm.base_url",
- "agent",
- "tools",
- "mcp_config",
-]);
+const LLM_EXCLUDED_KEYS = new Set(["llm.model", "llm.api_key", "llm.base_url"]);
const buildModelId = (provider: string | null, model: string | null) => {
if (!provider || !model) return null;
return `${provider}/${model}`;
};
-const hasSchemaField = (
- schema: SettingsSchema | null | undefined,
- fieldKey: string,
-) =>
- schema?.sections.some((section) =>
- section.fields.some((field) => field.key === fieldKey),
- ) ?? false;
-
const getSchemaFieldDefaultValue = (
schema: SettingsSchema | null | undefined,
fieldKey: string,
@@ -59,14 +43,6 @@ const getSchemaFieldDefaultValue = (
.flatMap((section) => section.fields)
.find((field) => field.key === fieldKey)?.default ?? null;
-const getSchemaFieldChoices = (
- schema: SettingsSchema | null | undefined,
- fieldKey: string,
-) =>
- schema?.sections
- .flatMap((section) => section.fields)
- .find((field) => field.key === fieldKey)?.choices ?? [];
-
const KNOWN_PROVIDER_DEFAULT_BASE_URLS: Partial<Record<string, Set<string>>> = {
openai: new Set(["https://api.openai.com", "https://api.openai.com/v1"]),
openhands: new Set([
@@ -162,7 +138,6 @@ export function LlmSettingsScreen({
);
const isSaasMode = config?.app_mode === "saas";
- const hasAgentField = hasSchemaField(schema, "agent");
React.useEffect(() => {
if (settings?.llm_model) {
@@ -233,8 +208,6 @@ export function LlmSettingsScreen({
typeof values["llm.base_url"] === "string"
? values["llm.base_url"]
: "";
- const agentValue =
- typeof values.agent === "string" ? values.agent : undefined;
const derivedProvider = modelValue
? extractModelAndProvider(modelValue).provider || null
: null;
@@ -283,21 +256,6 @@ export function LlmSettingsScreen({
);
};
- const agentItems = getSchemaFieldChoices(schema, "agent").map(
- (choice) => ({
- key: String(choice.value),
- label: choice.label,
- }),
- );
-
- if (
- hasAgentField &&
- agentValue &&
- !agentItems.some((item) => item.key === agentValue)
- ) {
- agentItems.unshift({ key: agentValue, label: agentValue });
- }
-
return (
<div className="flex flex-col gap-6">
{scope === "org" ? <OrgWideSettingsBadge /> : null}
@@ -373,35 +331,15 @@ export function LlmSettingsScreen({
"llm-api-key-input",
"llm-api-key-help-anchor-advanced",
)}
-
- {!isSaasMode && hasAgentField ? (
- <SettingsDropdownInput
- testId="agent-input"
- name="agent-input"
- label={t(I18nKey.SETTINGS$AGENT)}
- items={agentItems}
- selectedKey={agentValue}
- isClearable={false}
- onSelectionChange={(key) => {
- if (key) {
- onChange("agent", String(key));
- }
- }}
- isDisabled={isDisabled}
- wrapperClassName="w-full"
- />
- ) : null}
</div>
)}
</div>
);
},
[
- hasAgentField,
infoMessageKey,
isSaasMode,
defaultModel,
- schema,
selectedProvider,
settings?.llm_api_key_set,
t,
@@ -442,21 +380,17 @@ export function LlmSettingsScreen({
if (context.view === "basic") {
llm.base_url = getSchemaFieldDefaultValue(schema, "llm.base_url");
agentSettings.llm = llm;
-
- if (hasAgentField) {
- agentSettings.agent = getSchemaFieldDefaultValue(schema, "agent");
- }
}
return { agent_settings: agentSettings };
},
- [hasAgentField, isSaasMode, schema, selectedProvider],
+ [isSaasMode, schema, selectedProvider],
);
return (
<SdkSectionPage
scope={scope}
- sectionKeys={["llm", "general"]}
+ sectionKeys={["llm"]}
excludeKeys={LLM_EXCLUDED_KEYS}
header={buildHeader}
buildPayload={buildPayload}