Skip to content

πŸ™Œ OpenHands: AI-Driven Development

feat: allow changing the LLM profile when editing an automation (#1527)

Hiep Le65040758abb6
diff --git a/__tests__/components/automations/detail/edit-automation-modal.test.tsx b/__tests__/components/automations/detail/edit-automation-modal.test.tsx
index 29e47e0744..81e190daa4 100644
--- a/__tests__/components/automations/detail/edit-automation-modal.test.tsx
+++ b/__tests__/components/automations/detail/edit-automation-modal.test.tsx
@@ -5,6 +5,7 @@ import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
import { EditAutomationModal } from "#/components/features/automations/detail/edit-automation-modal";
import AutomationService from "#/api/automation-service/automation-service.api";
+import ProfilesService from "#/api/profiles-service/profiles-service.api";
import { ActiveBackendProvider } from "#/contexts/active-backend-context";
import {
__resetActiveStoreForTests,
@@ -24,6 +25,12 @@ vi.mock("#/api/automation-service/automation-service.api", () => ({
},
}));
+vi.mock("#/api/profiles-service/profiles-service.api", () => ({
+ default: {
+ listProfiles: vi.fn(),
+ },
+}));
+
vi.mock("#/utils/custom-toast-handlers", () => ({
displaySuccessToast: vi.fn(),
displayErrorToast: vi.fn(),
@@ -55,6 +62,32 @@ const customAutomation: Automation = {
trigger: { type: "cron", schedule: "0 9,17 * * *" },
};
+// A schedule automation pinned to a concrete LLM profile, used to exercise
+// the profile picker (the base fixtures intentionally leave `model` unset).
+const modeledAutomation: Automation = {
+ ...dailyAutomation,
+ id: "auto-3",
+ model: "fast",
+};
+
+const profilesResponse = {
+ profiles: [
+ {
+ name: "fast",
+ model: "anthropic/claude-haiku-4-5",
+ base_url: null,
+ api_key_set: true,
+ },
+ {
+ name: "careful",
+ model: "anthropic/claude-opus-4-8",
+ base_url: null,
+ api_key_set: true,
+ },
+ ],
+ active_profile: "fast",
+};
+
function renderModal(automation: Automation) {
const onClose = vi.fn();
const queryClient = new QueryClient({
@@ -79,6 +112,11 @@ beforeEach(() => {
__resetActiveStoreForTests();
setRegisteredBackends([localBackend]);
setActiveSelection({ backendId: localBackend.id });
+ // Default to no profiles; tests that exercise the picker override this.
+ vi.mocked(ProfilesService.listProfiles).mockResolvedValue({
+ profiles: [],
+ active_profile: null,
+ });
});
describe("EditAutomationModal", () => {
@@ -201,4 +239,78 @@ describe("EditAutomationModal", () => {
});
expect(onClose).not.toHaveBeenCalled();
});
+
+ it("persists the newly selected LLM profile in the update payload", async () => {
+ // Arrange β€” automation currently runs on the "fast" profile, with a
+ // second "careful" profile available to switch to.
+ vi.mocked(ProfilesService.listProfiles).mockResolvedValue(profilesResponse);
+ vi.mocked(AutomationService.updateAutomation).mockResolvedValue({
+ ...modeledAutomation,
+ model: "careful",
+ });
+ const user = userEvent.setup();
+ const { onClose } = renderModal(modeledAutomation);
+
+ // The picker pre-fills with the automation's current profile once the
+ // available profiles have loaded.
+ await waitFor(() =>
+ expect(screen.getByLabelText("AUTOMATIONS$DETAIL$MODEL")).toHaveValue(
+ "fast",
+ ),
+ );
+
+ // Act β€” switch to "careful" and save.
+ await user.click(screen.getByLabelText("AUTOMATIONS$DETAIL$MODEL"));
+ await user.click(await screen.findByText("careful"));
+ await user.click(screen.getByTestId("edit-automation-save"));
+
+ // Assert β€” only the profile changed, so the PATCH carries just `model`.
+ await waitFor(() => {
+ expect(AutomationService.updateAutomation).toHaveBeenCalledTimes(1);
+ });
+ expect(AutomationService.updateAutomation).toHaveBeenCalledWith("auto-3", {
+ model: "careful",
+ });
+ expect(onClose).toHaveBeenCalled();
+ });
+
+ it("omits the LLM profile from the payload when it is left unchanged", async () => {
+ // Arrange β€” profiles available; the user will only rename the automation.
+ vi.mocked(ProfilesService.listProfiles).mockResolvedValue(profilesResponse);
+ vi.mocked(AutomationService.updateAutomation).mockResolvedValue(
+ modeledAutomation,
+ );
+ const user = userEvent.setup();
+ renderModal(modeledAutomation);
+
+ // Ensure we're on the profiles-available path before editing.
+ await screen.findByLabelText("AUTOMATIONS$DETAIL$MODEL");
+
+ // Act β€” change only the name; leave the profile on "fast".
+ const nameInput = screen.getByTestId("edit-automation-name");
+ await user.clear(nameInput);
+ await user.type(nameInput, "Renamed digest");
+ await user.click(screen.getByTestId("edit-automation-save"));
+
+ // Assert β€” the PATCH renames but does not resend the unchanged profile.
+ await waitFor(() => {
+ expect(AutomationService.updateAutomation).toHaveBeenCalledTimes(1);
+ });
+ const [, body] = vi.mocked(AutomationService.updateAutomation).mock
+ .calls[0];
+ expect(body).toMatchObject({ name: "Renamed digest" });
+ expect(body).not.toHaveProperty("model");
+ });
+
+ it("hides the LLM profile picker when no profiles are available", async () => {
+ // Arrange β€” beforeEach already mocks an empty profile list.
+ renderModal(dailyAutomation);
+
+ // Assert β€” once the (empty) profile list resolves, no picker is offered.
+ await waitFor(() => {
+ expect(
+ screen.queryByLabelText("AUTOMATIONS$DETAIL$MODEL"),
+ ).not.toBeInTheDocument();
+ });
+ });
});
diff --git a/src/components/features/automations/detail/edit-automation-modal.tsx b/src/components/features/automations/detail/edit-automation-modal.tsx
index 28c1be83ac..d7b0dc245f 100644
--- a/src/components/features/automations/detail/edit-automation-modal.tsx
+++ b/src/components/features/automations/detail/edit-automation-modal.tsx
@@ -4,6 +4,7 @@ import { isAxiosError } from "axios";
import { I18nKey } from "#/i18n/declaration";
import type { Automation } from "#/types/automation";
import { useUpdateAutomation } from "#/hooks/query/use-automations";
+import { useLlmProfiles } from "#/hooks/query/use-llm-profiles";
import { SettingsInput } from "#/components/features/settings/settings-input";
import { SettingsDropdownInput } from "#/components/features/settings/settings-dropdown-input";
import { BrandButton } from "#/components/features/settings/brand-button";
@@ -48,6 +49,7 @@ const WEEKDAY_KEYS: I18nKey[] = [
interface FormState {
name: string;
prompt: string;
+ model: string;
frequency: FrequencyKey;
weekday: number;
timeOfDay: string;
@@ -60,6 +62,7 @@ function buildInitialState(automation: Automation): FormState {
return {
name: automation.name,
prompt: automation.prompt ?? "",
+ model: automation.model ?? "",
frequency: "custom",
weekday: 1,
timeOfDay: "",
@@ -72,6 +75,7 @@ function buildInitialState(automation: Automation): FormState {
return {
name: automation.name,
prompt: automation.prompt ?? "",
+ model: automation.model ?? "",
frequency: "custom",
weekday: 1,
timeOfDay:
@@ -85,6 +89,7 @@ function buildInitialState(automation: Automation): FormState {
return {
name: automation.name,
prompt: automation.prompt ?? "",
+ model: automation.model ?? "",
frequency: parsed.kind,
weekday: parsed.kind === "weekly" ? (parsed.weekday ?? 1) : 1,
timeOfDay: formatTimeOfDay(parsed.hour, parsed.minute),
@@ -100,6 +105,9 @@ export function EditAutomationModal({
}: EditAutomationModalProps) {
const { t } = useTranslation("openhands");
const updateMutation = useUpdateAutomation();
+ const { data: profilesData, isLoading: isLoadingProfiles } = useLlmProfiles();
+ const profiles = profilesData?.profiles ?? [];
+ const modelItems = profiles.map((p) => ({ key: p.name, label: p.name }));
const initial = useMemo(() => buildInitialState(automation), [automation]);
const [form, setForm] = useState<FormState>(initial);
@@ -169,6 +177,11 @@ export function EditAutomationModal({
body.prompt = trimmedPrompt.length === 0 ? null : trimmedPrompt;
}
+ const selectedModel = form.model.trim();
+ if (selectedModel && selectedModel !== (automation.model ?? "")) {
+ body.model = selectedModel;
+ }
+
if (!form.isCustomSchedule && form.frequency !== "custom") {
const parsedTime = parseTimeOfDay(form.timeOfDay);
if (parsedTime) {
@@ -272,6 +285,21 @@ export function EditAutomationModal({
</span>
</label>
+ {(isLoadingProfiles || profiles.length > 0) && (
+ <SettingsDropdownInput
+ testId="edit-automation-model"
+ name="model"
+ label={t(I18nKey.AUTOMATIONS$DETAIL$MODEL)}
+ items={modelItems}
+ selectedKey={form.model || undefined}
+ isLoading={isLoadingProfiles}
+ placeholder={t(I18nKey.COMMON$ACTIVE_PROFILE)}
+ onSelectionChange={(key) =>
+ setForm((f) => ({ ...f, model: key ? String(key) : "" }))
+ }
+ />
+ )}
+
{automation.trigger.type === "event" ? (
<div className="flex flex-col gap-3 rounded-lg bg-[var(--oh-surface-raised)] p-3">
<div className="flex items-center gap-2">