Skip to content

The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]

refactor(ui): migrate agent forms to react-hook-form and shadcn (#37357)

yuneng-jiang250277670029
diff --git a/ui/litellm-dashboard/src/app/(dashboard)/agents/_components/AgentFormKit.tsx b/ui/litellm-dashboard/src/app/(dashboard)/agents/_components/AgentFormKit.tsx
new file mode 100644
index 00000000000..e0152358f8c
--- /dev/null
+++ b/ui/litellm-dashboard/src/app/(dashboard)/agents/_components/AgentFormKit.tsx
@@ -0,0 +1,436 @@
+"use client";
+
+import * as React from "react";
+import { ChevronRight, CircleHelp } from "lucide-react";
+import {
+ Controller,
+ useFormContext,
+ type FieldPath,
+ type RegisterOptions,
+ type ControllerProps,
+ type ControllerRenderProps,
+} from "react-hook-form";
+
+import {
+ Combobox,
+ ComboboxChip,
+ ComboboxChips,
+ ComboboxChipsInput,
+ ComboboxContent,
+ ComboboxEmpty,
+ ComboboxItem,
+ ComboboxList,
+ ComboboxValue,
+ useComboboxAnchor,
+} from "@/components/ui/combobox";
+import { Collapsible, CollapsibleContent, CollapsibleTrigger } from "@/components/ui/collapsible";
+import { Input } from "@/components/ui/input";
+import { Tooltip, TooltipContent, TooltipTrigger } from "@/components/ui/tooltip";
+import { Field, FieldDescription, FieldError, FieldGroup, FieldLabel } from "@/components/shared/form/field";
+
+export interface AgentSkillFormValue {
+ id?: string;
+ name?: string;
+ description?: string;
+ tags?: string[];
+ examples?: string[];
+}
+
+export interface StaticHeaderFormValue {
+ header?: string;
+ value?: string;
+}
+
+export interface McpServerSelection {
+ servers?: string[];
+ accessGroups?: string[];
+ toolsets?: string[];
+}
+
+export type AgentFormFieldValue =
+ | string
+ | number
+ | boolean
+ | string[]
+ | AgentSkillFormValue[]
+ | StaticHeaderFormValue[]
+ | McpServerSelection
+ | Record<string, string[]>
+ | null
+ | undefined;
+
+export interface AgentFormValues {
+ [credentialKey: string]: AgentFormFieldValue;
+ agent_name?: string;
+ name?: string;
+ display_name?: string;
+ description?: string;
+ url?: string;
+ version?: string;
+ protocolVersion?: string;
+ skills?: AgentSkillFormValue[];
+ streaming?: boolean;
+ pushNotifications?: boolean;
+ stateTransitionHistory?: boolean;
+ iconUrl?: string;
+ documentationUrl?: string;
+ supportsAuthenticatedExtendedCard?: boolean;
+ model?: string;
+ make_public?: boolean;
+ cost_per_query?: string | number;
+ input_cost_per_token?: string | number;
+ output_cost_per_token?: string | number;
+ static_headers?: StaticHeaderFormValue[];
+ extra_headers?: string[];
+ tpm_limit?: number | null;
+ rpm_limit?: number | null;
+ session_tpm_limit?: number | null;
+ session_rpm_limit?: number | null;
+ team_id?: string;
+ guardrails?: string[];
+ entitlement_models?: string[];
+ entitlement_agents?: string[];
+ allowed_mcp_servers_and_groups?: McpServerSelection;
+ mcp_tool_permissions?: Record<string, string[]>;
+ defaultInputModes?: string[];
+ defaultOutputModes?: string[];
+ enable_tracing?: boolean;
+}
+
+export type AgentFieldName = FieldPath<AgentFormValues>;
+
+export const labelWithHint = (label: React.ReactNode, hint: string): React.ReactNode => (
+ <>
+ {label}
+ <Tooltip>
+ <TooltipTrigger render={<CircleHelp className="size-3.5 shrink-0 cursor-help text-muted-foreground" />} />
+ <TooltipContent>{hint}</TooltipContent>
+ </Tooltip>
+ </>
+);
+
+export type AgentFieldControlProps = ControllerRenderProps<AgentFormValues, AgentFieldName> & {
+ id: string;
+ "aria-invalid": true | undefined;
+ "aria-describedby": string | undefined;
+};
+
+export interface AgentRequestPayload {
+ [key: string]: unknown;
+ agent_name?: string;
+ agent_card_params?: Record<string, unknown>;
+ litellm_params?: Record<string, unknown>;
+ object_permission?: Record<string, unknown>;
+}
+
+interface AgentFormFieldProps {
+ name: AgentFieldName;
+ label?: React.ReactNode;
+ description?: React.ReactNode;
+ defaultValue?: AgentFormFieldValue;
+ rules?: Omit<RegisterOptions<AgentFormValues, AgentFieldName>, "valueAsNumber" | "valueAsDate" | "setValueAs">;
+ className?: string;
+ children: (control: AgentFieldControlProps) => React.ReactNode;
+}
+
+export const AgentFormField = ({
+ name,
+ label,
+ description,
+ defaultValue,
+ rules,
+ className,
+ children,
+}: AgentFormFieldProps) => {
+ const { control } = useFormContext<AgentFormValues>();
+ const reactId = React.useId();
+ const controlId = `${reactId}-control`;
+ const descriptionId = `${reactId}-description`;
+ const errorId = `${reactId}-error`;
+
+ const renderField: ControllerProps<AgentFormValues, AgentFieldName>["render"] = ({ field, fieldState }) => {
+ const invalid = fieldState.error !== undefined;
+ const describedBy =
+ [description !== undefined ? descriptionId : undefined, invalid ? errorId : undefined]
+ .filter((id): id is string => id !== undefined)
+ .join(" ") || undefined;
+
+ return (
+ <Field data-invalid={invalid || undefined} className={className}>
+ {label !== undefined && <FieldLabel htmlFor={controlId}>{label}</FieldLabel>}
+ {children({
+ ...field,
+ id: controlId,
+ "aria-invalid": invalid || undefined,
+ "aria-describedby": describedBy,
+ })}
+ {description !== undefined && <FieldDescription id={descriptionId}>{description}</FieldDescription>}
+ <FieldError id={errorId} errors={[fieldState.error]} />
+ </Field>
+ );
+ };
+
+ return <Controller control={control} name={name} defaultValue={defaultValue} rules={rules} render={renderField} />;
+};
+
+export interface CollapsiblePanelsState {
+ readonly openPanels: readonly string[];
+ readonly mountedPanels: readonly string[];
+ readonly toggle: (panelKey: string) => void;
+}
+
+export const useCollapsiblePanels = (initiallyOpen: readonly string[]): CollapsiblePanelsState => {
+ const [openPanels, setOpenPanels] = React.useState<readonly string[]>(initiallyOpen);
+ const [mountedPanels, setMountedPanels] = React.useState<readonly string[]>(initiallyOpen);
+
+ const toggle = React.useCallback((panelKey: string) => {
+ setOpenPanels((current) =>
+ current.includes(panelKey) ? current.filter((key) => key !== panelKey) : [...current, panelKey],
+ );
+ setMountedPanels((current) => (current.includes(panelKey) ? current : [...current, panelKey]));
+ }, []);
+
+ return { openPanels, mountedPanels, toggle };
+};
+
+interface AgentFormPanelProps {
+ panelKey: string;
+ title: string;
+ panels: CollapsiblePanelsState;
+ children: React.ReactNode;
+}
+
+export const AgentFormPanel = ({ panelKey, title, panels, children }: AgentFormPanelProps) => (
+ <Collapsible
+ open={panels.openPanels.includes(panelKey)}
+ onOpenChange={() => panels.toggle(panelKey)}
+ className="border-b border-border last:border-b-0"
+ >
+ <CollapsibleTrigger className="group flex w-full items-center gap-2 py-3 text-left text-sm font-medium text-foreground">
+ <ChevronRight className="size-4 shrink-0 text-muted-foreground transition-transform group-data-panel-open:rotate-90" />
+ {title}
+ </CollapsibleTrigger>
+ <CollapsibleContent keepMounted>
+ {panels.mountedPanels.includes(panelKey) && <FieldGroup className="pt-1 pb-5">{children}</FieldGroup>}
+ </CollapsibleContent>
+ </Collapsible>
+);
+
+export const omitFieldValues = (values: AgentFormValues, names: readonly string[]): AgentFormValues =>
+ Object.fromEntries(Object.entries(values).filter(([key]) => !names.includes(key)));
+
+interface AgentNumberInputProps extends Omit<AgentFieldControlProps, "value" | "onChange" | "ref"> {
+ value: AgentFormFieldValue;
+ onChange: (value: number | null) => void;
+ inputRef: AgentFieldControlProps["ref"];
+ min?: number;
+ placeholder?: string;
+ disabled?: boolean;
+ className?: string;
+}
+
+export const AgentNumberInput = ({ value, onChange, onBlur, inputRef, min, ...props }: AgentNumberInputProps) => (
+ <Input
+ {...props}
+ ref={inputRef}
+ type="number"
+ step="any"
+ value={typeof value === "number" ? value : ""}
+ onWheel={(event) => event.currentTarget.blur()}
+ onChange={(event) => {
+ const raw = event.target.valueAsNumber;
+ onChange(Number.isNaN(raw) ? null : raw);
+ }}
+ onBlur={() => {
+ if (min !== undefined && typeof value === "number" && value < min) onChange(min);
+ onBlur();
+ }}
+ />
+);
+
+export interface AgentSelectOption {
+ label: string;
+ value: string;
+}
+
+const matchesQuery = (option: AgentSelectOption, query: string): boolean =>
+ option.label.toLowerCase().includes(query.trim().toLowerCase());
+
+const TAG_SEPARATOR = ",";
+
+interface AgentTagsInputProps {
+ id: string;
+ options?: readonly AgentSelectOption[];
+ value: string[];
+ onValueChange: (value: string[]) => void;
+ placeholder?: string;
+ emptyText?: string;
+ "aria-invalid"?: true | undefined;
+ "aria-describedby"?: string | undefined;
+}
+
+export const AgentTagsInput = ({
+ id,
+ options = [],
+ value,
+ onValueChange,
+ placeholder,
+ emptyText = "No matching options",
+ ...props
+}: AgentTagsInputProps) => {
+ const anchor = useComboboxAnchor();
+ const [query, setQuery] = React.useState("");
+ const pendingRef = React.useRef("");
+
+ const selected = value.map((tag) => options.find((option) => option.value === tag) ?? { label: tag, value: tag });
+ const pending = query.trim();
+ const items =
+ pending.length > 0 && !options.some((option) => option.value === pending)
+ ? [{ label: pending, value: pending }, ...options]
+ : [...options];
+
+ const setPending = (next: string) => {
+ pendingRef.current = next;
+ setQuery(next);
+ };
+
+ const addTags = (tags: readonly string[]) => {
+ const additions = tags
+ .map((tag) => tag.trim())
+ .filter(Boolean)
+ .filter((tag, index, all) => all.indexOf(tag) === index && !value.includes(tag));
+ if (additions.length > 0) onValueChange([...value, ...additions]);
+ };
+
+ const handleInputValueChange = (next: string, details: { reason: string }) => {
+ if (details.reason === "input-clear") {
+ const committed = pendingRef.current;
+ setPending("");
+ addTags([committed]);
+ return;
+ }
+ const parts = next.split(TAG_SEPARATOR);
+ setPending(parts[parts.length - 1] ?? "");
+ addTags(parts.slice(0, -1));
+ };
+
+ const handleKeyDown = (event: React.KeyboardEvent<HTMLInputElement>) => {
+ if (event.key !== "Enter" || event.currentTarget.getAttribute("aria-activedescendant")) return;
+ event.preventDefault();
+ const committed = pendingRef.current;
+ setPending("");
+ addTags([committed]);
+ };
+
+ return (
+ <Combobox
+ multiple
+ items={items}
+ value={selected}
+ onValueChange={(next: AgentSelectOption[]) => {
+ setPending("");
+ onValueChange(next.map((option) => option.value));
+ }}
+ inputValue={query}
+ onInputValueChange={handleInputValueChange}
+ isItemEqualToValue={(option: AgentSelectOption, other: AgentSelectOption) => option.value === other.value}
+ itemToStringLabel={(option: AgentSelectOption) => option.label}
+ filter={matchesQuery}
+ openOnInputClick
+ >
+ <ComboboxChips render={<div ref={anchor} />} className="min-h-8 py-1 text-sm">
+ <ComboboxValue>
+ {(chips: AgentSelectOption[]) => (
+ <>
+ {chips.map((option) => (
+ <ComboboxChip key={option.value} aria-label={option.label}>
+ {option.label}
+ </ComboboxChip>
+ ))}
+ <ComboboxChipsInput
+ id={id}
+ placeholder={placeholder}
+ className="min-w-24"
+ onKeyDown={handleKeyDown}
+ {...props}
+ />
+ </>
+ )}
+ </ComboboxValue>
+ </ComboboxChips>
+ <ComboboxContent anchor={anchor}>
+ <ComboboxEmpty>{emptyText}</ComboboxEmpty>
+ <ComboboxList>
+ {(option: AgentSelectOption) => (
+ <ComboboxItem key={option.value} value={option} title={option.label}>
+ {option.label}
+ </ComboboxItem>
+ )}
+ </ComboboxList>
+ </ComboboxContent>
+ </Combobox>
+ );
+};
+
+interface AgentMultiSelectProps {
+ id: string;
+ options: readonly AgentSelectOption[];
+ value: string[];
+ onValueChange: (value: string[]) => void;
+ placeholder?: string;
+ emptyText?: string;
+ "aria-invalid"?: true | undefined;
+ "aria-describedby"?: string | undefined;
+}
+
+export const AgentMultiSelect = ({
+ id,
+ options,
+ value,
+ onValueChange,
+ placeholder,
+ emptyText = "No matching options",
+ ...props
+}: AgentMultiSelectProps) => {
+ const anchor = useComboboxAnchor();
+ const items = [...options];
+ const selected = value.map((item) => items.find((option) => option.value === item) ?? { label: item, value: item });
+
+ return (
+ <Combobox
+ multiple
+ items={items}
+ value={selected}
+ onValueChange={(next: AgentSelectOption[]) => onValueChange(next.map((option) => option.value))}
+ isItemEqualToValue={(option: AgentSelectOption, other: AgentSelectOption) => option.value === other.value}
+ itemToStringLabel={(option: AgentSelectOption) => option.label}
+ filter={matchesQuery}
+ openOnInputClick
+ >
+ <ComboboxChips render={<div ref={anchor} />} className="min-h-8 py-1 text-sm">
+ <ComboboxValue>
+ {(chips: AgentSelectOption[]) => (
+ <>
+ {chips.map((option) => (
+ <ComboboxChip key={option.value} aria-label={option.label}>
+ {option.label}
+ </ComboboxChip>
+ ))}
+ <ComboboxChipsInput id={id} placeholder={placeholder} className="min-w-24" {...props} />
+ </>
+ )}
+ </ComboboxValue>
+ </ComboboxChips>
+ <ComboboxContent anchor={anchor}>
+ <ComboboxEmpty>{emptyText}</ComboboxEmpty>
+ <ComboboxList>
+ {(option: AgentSelectOption) => (
+ <ComboboxItem key={option.value} value={option} title={option.label}>
+ {option.label}
+ </ComboboxItem>
+ )}
+ </ComboboxList>
+ </ComboboxContent>
+ </Combobox>
+ );
+};
diff --git a/ui/litellm-dashboard/src/app/(dashboard)/agents/_components/add_agent_form.integration.test.tsx b/ui/litellm-dashboard/src/app/(dashboard)/agents/_components/add_agent_form.integration.test.tsx
new file mode 100644
index 00000000000..b411649ea72
--- /dev/null
+++ b/ui/litellm-dashboard/src/app/(dashboard)/agents/_components/add_agent_form.integration.test.tsx
@@ -0,0 +1,354 @@
+import React from "react";
+import { render, screen, waitFor, within } from "@testing-library/react";
+import userEvent, { PointerEventsCheckLevel } from "@testing-library/user-event";
+import { describe, it, expect, vi, beforeEach } from "vitest";
+import AddAgentForm from "./add_agent_form";
+import * as networking from "@/components/networking";
+import type { AgentCreateInfo } from "@/components/networking";
+
+vi.mock("@/components/networking", () => ({
+ createAgentCall: vi.fn(),
+ getAgentCreateMetadata: vi.fn(),
+ getAgentsList: vi.fn(),
+ keyCreateForAgentCall: vi.fn(),
+ keyListCall: vi.fn(),
+ keyUpdateCall: vi.fn(),
+ modelAvailableCall: vi.fn(),
+}));
+
+vi.mock("./agent_card_discovery", () => ({ default: () => <div data-testid="agent-card-discovery" /> }));
+vi.mock("@/components/mcp_server_management/MCPServerSelector", () => ({ default: () => <div /> }));
+vi.mock("@/components/mcp_server_management/MCPToolPermissions", () => ({ default: () => <div /> }));
+vi.mock("@/components/guardrails/GuardrailSelector", () => ({ default: () => <div /> }));
+vi.mock("@/components/common_components/team_dropdown", () => ({ default: () => <div /> }));
+
+const a2aInfo: AgentCreateInfo = {
+ agent_type: "a2a",
+ agent_type_display_name: "A2A Agent",
+ description: "Agent-to-agent protocol",
+ logo_url: "/ui/assets/logos/a2a_agent.png",
+ credential_fields: [],
+ use_a2a_form_fields: true,
+};
+
+const langgraphInfo: AgentCreateInfo = {
+ agent_type: "langgraph",
+ agent_type_display_name: "LangGraph",
+ description: "LangGraph platform",
+ logo_url: "/ui/assets/logos/langgraph.png",
+ use_a2a_form_fields: false,
+ litellm_params_template: { custom_llm_provider: "langgraph" },
+ model_template: "langgraph/{assistant_id}",
+ credential_fields: [
+ { key: "api_base", label: "API Base", field_type: "text", required: true, placeholder: "https://host" },
+ { key: "assistant_id", label: "Assistant ID", field_type: "text", required: true, default_value: "" },
+ { key: "api_key", label: "API Key", field_type: "password", required: false },
+ ],
+};
+
+const renderForm = () =>
+ render(<AddAgentForm visible={true} onClose={vi.fn()} accessToken="tok" onSuccess={vi.fn()} />);
+
+const panel = (name: RegExp) => screen.getByRole("button", { name });
+
+const openAgentTypeMenu = async (user: ReturnType<typeof userEvent.setup>) => {
+ await user.click(screen.getAllByRole("combobox")[0]);
+};
+
+const createdPayload = () => vi.mocked(networking.createAgentCall).mock.calls[0][1] as Record<string, unknown>;
+
+const goToLastStepAndCreate = async (user: ReturnType<typeof userEvent.setup>) => {
+ await user.click(await screen.findByRole("button", { name: /^Next/ }));
+ await user.click(await screen.findByRole("button", { name: /^Next/ }));
+ await user.click(await screen.findByRole("button", { name: /^Next/ }));
+ await user.click(await screen.findByRole("button", { name: /Create Agent/ }));
+ await waitFor(() => expect(networking.createAgentCall).toHaveBeenCalledTimes(1));
+};
+
+const selectAgentType = async (user: ReturnType<typeof userEvent.setup>, label: string) => {
+ await openAgentTypeMenu(user);
+ await user.click(await screen.findByText(label));
+};
+
+describe("AddAgentForm submit payload", () => {
+ beforeEach(() => {
+ vi.mocked(networking.getAgentCreateMetadata).mockReset().mockResolvedValue([a2aInfo, langgraphInfo]);
+ vi.mocked(networking.getAgentsList)
+ .mockReset()
+ .mockResolvedValue({ agents: [{ agent_id: "sub-1", agent_name: "Sub Agent One" }] });
+ vi.mocked(networking.keyListCall).mockReset().mockResolvedValue({ keys: [] });
+ vi.mocked(networking.modelAvailableCall)
+ .mockReset()
+ .mockResolvedValue({ data: [{ id: "gpt-4o" }] });
+ vi.mocked(networking.createAgentCall)
+ .mockReset()
+ .mockResolvedValue({ agent_id: "agent-1", agent_name: "created-agent" } as never);
+ vi.mocked(networking.keyCreateForAgentCall)
+ .mockReset()
+ .mockResolvedValue({ key: "sk-new" } as never);
+ vi.mocked(networking.keyUpdateCall)
+ .mockReset()
+ .mockResolvedValue({} as never);
+ });
+
+ it("sends every a2a field the user filled across all collapsible panels", async () => {
+ const user = userEvent.setup({ pointerEventsCheck: PointerEventsCheckLevel.Never });
+ renderForm();
+
+ await user.type(await screen.findByLabelText("Agent Name"), "support-agent");
+ await user.type(screen.getByLabelText("Display Name"), "Support Agent");
+ await user.type(screen.getByPlaceholderText("Describe what this agent does..."), "answers questions");
+ await user.type(screen.getByLabelText("URL"), "http://localhost:9999/");
+ await user.clear(screen.getByLabelText("Version"));
+ await user.type(screen.getByLabelText("Version"), "2.0.0");
+
+ await user.click(panel(/Skills/));
+ await user.click(screen.getByRole("button", { name: /Add Skill/ }));
+ await user.type(await screen.findByLabelText("Skill ID"), "hello");
+ await user.type(screen.getByLabelText("Skill Name"), "Hello");
+ await user.type(screen.getByPlaceholderText("What this skill does"), "greets");
+ await user.type(screen.getByLabelText("Tags"), "greeting,polite");
+ await user.type(screen.getByLabelText("Examples"), "say hi");
+ await user.click(screen.getByLabelText("Agent Name"));
+
+ await user.click(panel(/Capabilities/));
+ await user.click(await screen.findByRole("switch", { name: "Streaming" }));
+ await user.click(screen.getByRole("switch", { name: "Push Notifications" }));
+
+ await user.click(panel(/Optional Settings/));
+ await user.type(await screen.findByLabelText("Icon URL"), "https://example.com/icon.png");
+
+ await user.click(panel(/Cost Configuration/));
+ await user.type(await screen.findByLabelText("Cost Per Query ($)"), "0.25");
+ await user.type(screen.getByLabelText("Input Cost Per Token ($)"), "0.000002");
+
+ await user.click(panel(/LiteLLM Parameters/));
+ await user.type(await screen.findByLabelText("Model (Optional)"), "gpt-4o");
+ await user.click(screen.getByRole("switch", { name: "Make Public" }));
+
+ await user.click(panel(/Authentication Headers/));
+ await user.click(await screen.findByRole("button", { name: /Add Static Header/ }));
+ await user.type(await screen.findByPlaceholderText("Header name (e.g. Authorization)"), "X-Tenant");
+ await user.type(screen.getByPlaceholderText("Value (e.g. Bearer token123)"), "acme");
+ await user.type(screen.getByLabelText("Forward Client Headers"), "x-api-key,");
+ await user.click(screen.getByLabelText("Agent Name"));
+
+ await goToLastStepAndCreate(user);
+
+ expect(createdPayload()).toEqual({
+ agent_name: "support-agent",
+ agent_card_params: {
+ protocolVersion: "1.0",
+ name: "Support Agent",
+ description: "answers questions",
+ url: "http://localhost:9999/",
+ version: "2.0.0",
+ defaultInputModes: ["text"],
+ defaultOutputModes: ["text"],
+ capabilities: { streaming: true, pushNotifications: true },
+ skills: [
+ {
+ id: "hello",
+ name: "Hello",
+ description: "greets",
+ tags: ["greeting", "polite"],
+ examples: ["say hi"],
+ },
+ ],
+ iconUrl: "https://example.com/icon.png",
+ },
+ litellm_params: {
+ model: "gpt-4o",
+ make_public: true,
+ cost_per_query: 0.25,
+ input_cost_per_token: 0.000002,
+ },
+ static_headers: { "X-Tenant": "acme" },
+ extra_headers: ["x-api-key"],
+ });
+ });
+
+ it("keeps a value typed into a panel the user collapsed again", async () => {
+ const user = userEvent.setup({ pointerEventsCheck: PointerEventsCheckLevel.Never });
+ renderForm();
+
+ await user.type(await screen.findByLabelText("Agent Name"), "collapsed-agent");
+ await user.type(screen.getByLabelText("Display Name"), "Collapsed");
+ await user.type(screen.getByPlaceholderText("Describe what this agent does..."), "d");
+
+ await user.click(panel(/Cost Configuration/));
+ await user.type(await screen.findByLabelText("Cost Per Query ($)"), "0.75");
+ await user.click(panel(/Cost Configuration/));
+
+ await goToLastStepAndCreate(user);
+
+ expect(createdPayload().litellm_params).toEqual({ cost_per_query: 0.75 });
+ });
+
+ it("restores what was typed when a collapsed panel is expanded again", async () => {
+ const user = userEvent.setup({ pointerEventsCheck: PointerEventsCheckLevel.Never });
+ renderForm();
+
+ await user.click(panel(/Cost Configuration/));
+ await user.type(await screen.findByLabelText("Cost Per Query ($)"), "0.75");
+ await user.click(panel(/Cost Configuration/));
+ await user.click(panel(/Cost Configuration/));
+
+ expect(await screen.findByLabelText("Cost Per Query ($)")).toHaveValue(0.75);
+ });
+
+ it("blocks the first step until the required agent name is filled", async () => {
+ const user = userEvent.setup({ pointerEventsCheck: PointerEventsCheckLevel.Never });
+ renderForm();
+
+ await screen.findByLabelText("Agent Name");
+ await user.click(screen.getByRole("button", { name: /^Next/ }));
+
+ expect(await screen.findByText("Please enter a unique agent name")).toBeInTheDocument();
+ expect(screen.getByLabelText("Agent Name")).toBeInTheDocument();
+ });
+
+ it("sends the custom agent shape when the custom type is picked", async () => {
+ const user = userEvent.setup({ pointerEventsCheck: PointerEventsCheckLevel.Never });
+ renderForm();
+
+ await screen.findByLabelText("Agent Name");
+ await openAgentTypeMenu(user);
+ await user.click(await screen.findByText("Custom / Other"));
+
+ await user.type(await screen.findByLabelText("Agent Name"), "my-custom-agent");
+ await user.type(screen.getByPlaceholderText("Describe what this agent does\u2026"), "custom thing");
+
+ await goToLastStepAndCreate(user);
+
+ expect(createdPayload()).toEqual({
+ agent_name: "my-custom-agent",
+ agent_card_params: {
+ protocolVersion: "1.0",
+ name: "my-custom-agent",
+ description: "custom thing",
+ url: "",
+ version: "1.0.0",
+ defaultInputModes: ["text"],
+ defaultOutputModes: ["text"],
+ capabilities: { streaming: false },
+ skills: [],
+ },
+ });
+ });
+
+ it("sends credential fields and the model template for a dynamic agent type", async () => {
+ const user = userEvent.setup({ pointerEventsCheck: PointerEventsCheckLevel.Never });
+ renderForm();
+
+ await screen.findByLabelText("Agent Name");
+ await selectAgentType(user, "LangGraph");
+
+ await user.type(await screen.findByLabelText("Agent Name"), "lg-agent");
+ await user.type(screen.getByPlaceholderText("Describe what this agent does..."), "graph agent");
+ await user.type(screen.getByLabelText("API Base"), "https://lg.example.com");
+ await user.type(screen.getByLabelText("Assistant ID"), "asst_1");
+ await user.type(screen.getByLabelText("API Key"), "secret-value");
+
+ await goToLastStepAndCreate(user);
+
+ expect(createdPayload()).toEqual({
+ agent_name: "lg-agent",
+ agent_card_params: {
+ protocolVersion: "1.0",
+ name: "lg-agent",
+ description: "graph agent",
+ url: "https://lg.example.com",
+ version: "1.0.0",
+ defaultInputModes: ["text"],
+ defaultOutputModes: ["text"],
+ capabilities: { streaming: true },
+ skills: [
+ {
+ id: "chat",
+ name: "Chat",
+ description: "General chat capability",
+ tags: ["chat", "conversation"],
+ },
+ ],
+ },
+ litellm_params: {
+ custom_llm_provider: "langgraph",
+ api_base: "https://lg.example.com",
+ assistant_id: "asst_1",
+ api_key: "secret-value",
+ model: "langgraph/asst_1",
+ },
+ });
+ });
+
+ it("resets to the agent type that was selected before the switch", async () => {
+ const user = userEvent.setup({ pointerEventsCheck: PointerEventsCheckLevel.Never });
+ renderForm();
+
+ await screen.findByLabelText("Agent Name");
+ expect(screen.getByLabelText("Version")).toHaveValue("1.0.0");
+
+ await openAgentTypeMenu(user);
+ await user.click(await screen.findByText("Custom / Other"));
+ await screen.findByPlaceholderText("e.g. my-custom-agent");
+
+ await selectAgentType(user, "A2A Agent");
+
+ expect(await screen.findByLabelText("Version")).toHaveValue("");
+ });
+
+ it("sends entitlements and rate limits gathered on the later steps", async () => {
+ const user = userEvent.setup({ pointerEventsCheck: PointerEventsCheckLevel.Never });
+ renderForm();
+
+ await user.type(await screen.findByLabelText("Agent Name"), "entitled-agent");
+ await user.type(screen.getByLabelText("Display Name"), "Entitled");
+ await user.type(screen.getByPlaceholderText("Describe what this agent does..."), "d");
+ await user.click(screen.getByRole("button", { name: /^Next/ }));
+
+ await user.type(await screen.findByLabelText("Allowed Models"), "gpt-4o,");
+ await user.keyboard("{Escape}");
+ await user.click(screen.getByLabelText("Allowed Agents (Sub-Agents)"));
+ await user.click(await screen.findByTitle("Sub Agent One"));
+ await user.keyboard("{Escape}");
+ await user.click(screen.getByText(/Configure which models, agents, and MCP tools/));
+ await user.click(screen.getByRole("button", { name: /^Next/ }));
+
+ await user.click((await screen.findAllByRole("switch"))[1]);
+ await user.type(screen.getByLabelText("TPM Limit"), "1000");
+ await user.type(screen.getByLabelText("Session RPM Limit"), "20");
+ await user.click(screen.getByRole("button", { name: /^Next/ }));
+
+ await user.click(await screen.findByRole("button", { name: /Create Agent/ }));
+ await waitFor(() => expect(networking.createAgentCall).toHaveBeenCalledTimes(1));
+
+ const payload = createdPayload();
+ expect(payload.tpm_limit).toBe(1000);
+ expect(payload.session_rpm_limit).toBe(20);
+ expect(payload.object_permission).toEqual({ models: ["gpt-4o"], agents: ["sub-1"] });
+ expect(payload.litellm_params).toEqual({ require_trace_id_on_calls_by_agent: true });
+ });
+
+ it("creates a key named after the agent once the agent is created", async () => {
+ const user = userEvent.setup({ pointerEventsCheck: PointerEventsCheckLevel.Never });
+ renderForm();
+
+ await user.type(await screen.findByLabelText("Agent Name"), "keyed-agent");
+ await user.type(screen.getByLabelText("Display Name"), "Keyed");
+ await user.type(screen.getByPlaceholderText("Describe what this agent does..."), "d");
+
+ await goToLastStepAndCreate(user);
+
+ expect(networking.keyCreateForAgentCall).toHaveBeenCalledWith(
+ "tok",
+ "agent-1",
+ "keyed-agent-key",
+ [],
+ undefined,
+ null,
+ );
+ expect(await screen.findByText("Agent Created!")).toBeInTheDocument();
+ expect(within(screen.getByText("Agent Created!").parentElement!).getByText("created-agent")).toBeInTheDocument();
+ });
+});
diff --git a/ui/litellm-dashboard/src/app/(dashboard)/agents/_components/add_agent_form.tsx b/ui/litellm-dashboard/src/app/(dashboard)/agents/_components/add_agent_form.tsx
index 7bd6b68a26d..da98eb8a352 100644
--- a/ui/litellm-dashboard/src/app/(dashboard)/agents/_components/add_agent_form.tsx
+++ b/ui/litellm-dashboard/src/app/(dashboard)/agents/_components/add_agent_form.tsx
@@ -1,10 +1,20 @@
import React, { useState, useEffect } from "react";
-import { Modal, Form, Select, Input, Steps, Radio, Tag, Divider, Switch, InputNumber } from "antd";
+import { Form, Modal, Select, Steps, Tag } from "antd";
+import { FormProvider, useForm, useWatch } from "react-hook-form";
import { toast } from "@/lib/toast";
import { Logo } from "@/components/molecules/logo/Logo";
import { Button } from "@tremor/react";
-import { CheckCircleFilled, KeyOutlined, RobotOutlined, AppstoreOutlined, InfoCircleOutlined } from "@ant-design/icons";
+import { CheckCircleFilled, KeyOutlined, RobotOutlined, AppstoreOutlined } from "@ant-design/icons";
import CreatedKeyDisplay from "@/components/shared/CreatedKeyDisplay";
+import { Button as ShadButton } from "@/components/ui/button";
+import { Input } from "@/components/ui/input";
+import { RadioGroup, RadioGroupItem } from "@/components/ui/radio-group";
+import { Separator } from "@/components/ui/separator";
+import { Switch } from "@/components/ui/switch";
+import { Textarea } from "@/components/ui/textarea";
+import { TooltipProvider } from "@/components/ui/tooltip";
+import { Field, FieldGroup, FieldLabel } from "@/components/shared/form/field";
+import { SearchSelect } from "@/components/shared/SearchSelect";
import {
createAgentCall,
getAgentCreateMetadata,
@@ -23,7 +33,19 @@ import AgentFormFields from "./agent_form_fields";
import AgentCardDiscovery, { DiscoveredAgentCardSelection } from "./agent_card_discovery";
import { buildDiscoveryRequest, overlayDiscoveredCardParams } from "./agent_discovery_utils";
import DynamicAgentFormFields, { buildDynamicAgentData } from "./dynamic_agent_form_fields";
-import { getDefaultFormValues, buildAgentDataFromForm } from "./agent_config";
+import { PasswordInput } from "@/components/shared/PasswordInput";
+import { AGENT_FORM_CONFIG, getDefaultFormValues, buildAgentDataFromForm } from "./agent_config";
+import {
+ AgentFormField,
+ AgentFormValues,
+ AgentMultiSelect,
+ AgentNumberInput,
+ AgentRequestPayload,
+ AgentTagsInput,
+ McpServerSelection,
+ labelWithHint,
+ useCollapsiblePanels,
+} from "./AgentFormKit";
import MCPServerSelector from "@/components/mcp_server_management/MCPServerSelector";
import MCPToolPermissions from "@/components/mcp_server_management/MCPToolPermissions";
import GuardrailSelector from "@/components/guardrails/GuardrailSelector";
@@ -32,6 +54,17 @@ const { Step } = Steps;
const CUSTOM_AGENT_TYPE = "custom";
+const SHARED_INITIAL_VALUES: AgentFormValues = {
+ allowed_mcp_servers_and_groups: { servers: [], accessGroups: [] },
+ mcp_tool_permissions: {},
+ entitlement_models: [],
+ entitlement_agents: [],
+ guardrails: [],
+};
+
+const buildInitialValues = (agentType: string): AgentFormValues =>
+ agentType === "a2a" ? { ...getDefaultFormValues(), ...SHARED_INITIAL_VALUES } : { ...SHARED_INITIAL_VALUES };
+
interface AddAgentFormProps {
visible: boolean;
onClose: () => void;
@@ -42,7 +75,8 @@ interface AddAgentFormProps {
const AddAgentForm: React.FC<AddAgentFormProps> = ({ visible, onClose, accessToken, onSuccess, teams }) => {
const { userId, userRole } = useAuthorized();
- const [form] = Form.useForm();
+ const form = useForm<AgentFormValues>({ defaultValues: buildInitialValues("a2a") });
+ const panels = useCollapsiblePanels([AGENT_FORM_CONFIG.basic.key]);
const [currentStep, setCurrentStep] = useState(0);
const [isSubmitting, setIsSubmitting] = useState(false);
const [agentType, setAgentType] = useState<string>("a2a");
@@ -52,7 +86,7 @@ const AddAgentForm: React.FC<AddAgentFormProps> = ({ visible, onClose, accessTok
const [keyAssignOption, setKeyAssignOption] = useState<"create_new" | "existing_key" | "skip">("create_new");
const [newKeyName, setNewKeyName] = useState<string>("");
const [newKeyModels, setNewKeyModels] = useState<string[]>([]);
- const [existingKeys, setExistingKeys] = useState<any[]>([]);
+ const [existingKeys, setExistingKeys] = useState<{ token: string; key_alias?: string }[]>([]);
const [selectedExistingKey, setSelectedExistingKey] = useState<string | null>(null);
const [loadingKeys, setLoadingKeys] = useState(false);
const [availableModels, setAvailableModels] = useState<string[]>([]);
@@ -71,14 +105,10 @@ const AddAgentForm: React.FC<AddAgentFormProps> = ({ visible, onClose, accessTok
const [maxIterations, setMaxIterations] = useState<number | null>(null);
const [maxBudgetPerSession, setMaxBudgetPerSession] = useState<number | null>(null);
- // Latest upstream card selection from auto-discovery (skills, capabilities,
- // name, description). Dynamic agent forms don't render Form.Items for those
- // fields, so we overlay this onto agent_card_params at submit.
const [appliedDiscoveredSelection, setAppliedDiscoveredSelection] = useState<DiscoveredAgentCardSelection | null>(
null,
);
- // Fetch agent type metadata on mount
useEffect(() => {
const fetchMetadata = async () => {
try {
@@ -142,7 +172,12 @@ const AddAgentForm: React.FC<AddAgentFormProps> = ({ visible, onClose, accessTok
.then((response) => {
if (cancelled) return;
const agents = response?.agents ?? [];
- setAvailableAgents(agents.map((a: any) => ({ agent_id: a.agent_id, agent_name: a.agent_name })));
+ setAvailableAgents(
+ agents.map((a: { agent_id: string; agent_name: string }) => ({
+ agent_id: a.agent_id,
+ agent_name: a.agent_name,
+ })),
+ );
})
.catch((error) => {
if (!cancelled) console.error("Error fetching agents:", error);
@@ -159,7 +194,9 @@ const AddAgentForm: React.FC<AddAgentFormProps> = ({ visible, onClose, accessTok
// Watch every form field so we can recompute the discovery plan whenever
// the user types into a relevant credential field below.
- const watchedFormValues = Form.useWatch([], form);
+ const watchedFormValues = useWatch({ control: form.control });
+ const mcpSelection = useWatch({ control: form.control, name: "allowed_mcp_servers_and_groups" });
+ const mcpToolPermissions = useWatch({ control: form.control, name: "mcp_tool_permissions" });
// Build the discovery plan for the proxy. Different agent runtimes publish
// their cards at different URL shapes:
@@ -177,25 +214,22 @@ const AddAgentForm: React.FC<AddAgentFormProps> = ({ visible, onClose, accessTok
);
const handleNext = async () => {
- try {
- if (currentStep === 0) {
- await form.validateFields();
- const agentName = form.getFieldValue("agent_name");
- if (agentName && !newKeyName) {
- setNewKeyName(`${agentName}-key`);
- }
+ if (currentStep === 0) {
+ const isValid = await form.trigger();
+ if (!isValid) return;
+ const agentName = form.getValues("agent_name");
+ if (agentName && !newKeyName) {
+ setNewKeyName(`${agentName}-key`);
}
- setCurrentStep((s) => s + 1);
- } catch {
- // validation failed — stay on current step
}
+ setCurrentStep((s) => s + 1);
};
const handleBack = () => {
setCurrentStep((s) => Math.max(0, s - 1));
};
- const buildAgentData = (values: any) => {
+ const buildAgentData = (values: AgentFormValues): AgentRequestPayload | null => {
if (agentType === CUSTOM_AGENT_TYPE) {
return {
agent_name: values.agent_name,
@@ -213,29 +247,34 @@ const AddAgentForm: React.FC<AddAgentFormProps> = ({ visible, onClose, accessTok
};
}
- let agentData: Record<string, any>;
if (agentType === "a2a") {
- agentData = buildAgentDataFromForm(values);
- } else if (selectedAgentTypeInfo?.use_a2a_form_fields) {
- agentData = buildAgentDataFromForm(values);
- if (selectedAgentTypeInfo.litellm_params_template) {
- agentData.litellm_params = {
- ...agentData.litellm_params,
- ...selectedAgentTypeInfo.litellm_params_template,
- };
- }
- for (const field of selectedAgentTypeInfo.credential_fields) {
- const value = values[field.key];
- if (value && field.include_in_litellm_params !== false) {
- agentData.litellm_params[field.key] = value;
- }
- }
- } else if (selectedAgentTypeInfo) {
- agentData = buildDynamicAgentData(values, selectedAgentTypeInfo);
- } else {
- return null;
+ return overlayDiscoveredCardParams(buildAgentDataFromForm(values), appliedDiscoveredSelection?.selected_card);
}
+ if (!selectedAgentTypeInfo) return null;
+
+ if (!selectedAgentTypeInfo.use_a2a_form_fields) {
+ return overlayDiscoveredCardParams(
+ buildDynamicAgentData(values, selectedAgentTypeInfo),
+ appliedDiscoveredSelection?.selected_card,
+ );
+ }
+
+ const agentData: AgentRequestPayload = buildAgentDataFromForm(values);
+ if (selectedAgentTypeInfo.litellm_params_template) {
+ agentData.litellm_params = {
+ ...agentData.litellm_params,
+ ...selectedAgentTypeInfo.litellm_params_template,
+ };
+ }
+ const credentialParams = Object.fromEntries(
+ selectedAgentTypeInfo.credential_fields
+ .filter((field) => values[field.key] && field.include_in_litellm_params !== false)
+ .map((field) => [field.key, values[field.key]]),
+ );
+ if (Object.keys(credentialParams).length > 0) {
+ agentData.litellm_params = { ...agentData.litellm_params, ...credentialParams };
+ }
return overlayDiscoveredCardParams(agentData, appliedDiscoveredSelection?.selected_card);
};
@@ -247,8 +286,12 @@ const AddAgentForm: React.FC<AddAgentFormProps> = ({ visible, onClose, accessTok
setIsSubmitting(true);
try {
- await form.validateFields();
- const values = { ...form.getFieldsValue(true) };
+ const isValid = await form.trigger();
+ if (!isValid) {
+ setIsSubmitting(false);
+ return;
+ }
+ const values = form.getValues();
const agentData = buildAgentData(values);
if (!agentData) {
toast.error("Failed to build agent data");
@@ -257,52 +300,35 @@ const AddAgentForm: React.FC<AddAgentFormProps> = ({ visible, onClose, accessTok
}
// Build object_permission from MCP Tools step (allowed_mcp_servers_and_groups, mcp_tool_permissions)
- const mcpServersAndGroups = values.allowed_mcp_servers_and_groups;
- const mcpToolPermissions = values.mcp_tool_permissions || {};
- const entitlementModels = values.entitlement_models || [];
- const entitlementAgents = values.entitlement_agents || [];
- const hasObjectPermission =
- mcpServersAndGroups?.servers?.length > 0 ||
- mcpServersAndGroups?.accessGroups?.length > 0 ||
- Object.keys(mcpToolPermissions).length > 0 ||
- entitlementModels.length > 0 ||
- entitlementAgents.length > 0;
- if (hasObjectPermission) {
- agentData.object_permission = {};
- if (mcpServersAndGroups?.servers?.length > 0) {
- agentData.object_permission.mcp_servers = mcpServersAndGroups.servers;
- }
- if (mcpServersAndGroups?.accessGroups?.length > 0) {
- agentData.object_permission.mcp_access_groups = mcpServersAndGroups.accessGroups;
- }
- if (Object.keys(mcpToolPermissions).length > 0) {
- agentData.object_permission.mcp_tool_permissions = mcpToolPermissions;
- }
- if (entitlementModels.length > 0) {
- agentData.object_permission.models = entitlementModels;
- }
- if (entitlementAgents.length > 0) {
- agentData.object_permission.agents = entitlementAgents;
- }
+ const mcpServersAndGroups = values.allowed_mcp_servers_and_groups ?? {};
+ const toolPermissions = values.mcp_tool_permissions ?? {};
+ const entitlementModels = values.entitlement_models ?? [];
+ const entitlementAgents = values.entitlement_agents ?? [];
+ const objectPermission: Record<string, unknown> = {
+ ...(mcpServersAndGroups.servers?.length ? { mcp_servers: mcpServersAndGroups.servers } : {}),
+ ...(mcpServersAndGroups.accessGroups?.length ? { mcp_access_groups: mcpServersAndGroups.accessGroups } : {}),
+ ...(Object.keys(toolPermissions).length ? { mcp_tool_permissions: toolPermissions } : {}),
+ ...(entitlementModels.length ? { models: entitlementModels } : {}),
+ ...(entitlementAgents.length ? { agents: entitlementAgents } : {}),
+ };
+ if (Object.keys(objectPermission).length > 0) {
+ agentData.object_permission = objectPermission;
}
// Wire trace-id flags and budget controls into agent litellm_params (before create call)
if (requireTraceIdInbound || requireTraceIdOutbound) {
- if (!agentData.litellm_params) agentData.litellm_params = {};
- if (requireTraceIdInbound) {
- agentData.litellm_params.require_trace_id_on_calls_to_agent = true;
- }
- if (requireTraceIdOutbound) {
- agentData.litellm_params.require_trace_id_on_calls_by_agent = true;
- if (maxIterations) agentData.litellm_params.max_iterations = maxIterations;
- if (maxBudgetPerSession) agentData.litellm_params.max_budget_per_session = maxBudgetPerSession;
- }
+ agentData.litellm_params = {
+ ...agentData.litellm_params,
+ ...(requireTraceIdInbound ? { require_trace_id_on_calls_to_agent: true } : {}),
+ ...(requireTraceIdOutbound ? { require_trace_id_on_calls_by_agent: true } : {}),
+ ...(requireTraceIdOutbound && maxIterations ? { max_iterations: maxIterations } : {}),
+ ...(requireTraceIdOutbound && maxBudgetPerSession ? { max_budget_per_session: maxBudgetPerSession } : {}),
+ };
}
- const selectedGuardrails = values.guardrails || [];
+ const selectedGuardrails = values.guardrails ?? [];
if (selectedGuardrails.length > 0) {
- if (!agentData.litellm_params) agentData.litellm_params = {};
- agentData.litellm_params.guardrails = selectedGuardrails;
+ agentData.litellm_params = { ...agentData.litellm_params, guardrails: selectedGuardrails };
}
const selectedTeamId = values.team_id || null;
@@ -351,7 +377,7 @@ const AddAgentForm: React.FC<AddAgentFormProps> = ({ visible, onClose, accessTok
};
const handleClose = () => {
- form.resetFields();
+ form.reset(buildInitialValues(agentType));
setAgentType("a2a");
setCurrentStep(0);
setKeyAssignOption("create_new");
@@ -371,130 +397,127 @@ const AddAgentForm: React.FC<AddAgentFormProps> = ({ visible, onClose, accessTok
const renderEntitlementsStep = () => (
<div className="space-y-4">
- <p className="text-sm text-gray-600">
+ <p className="text-sm text-muted-foreground">
Configure which models, agents, and MCP tools this agent is allowed to use. Leave fields empty to allow all
(subject to key/team permissions).
</p>
- <Form.Item
- label={<span className="text-sm font-medium text-gray-700">Allowed Models</span>}
- name="entitlement_models"
- tooltip="Restrict which models this agent can call. Leave empty to allow all."
- >
- <Select
- mode="tags"
- style={{ width: "100%" }}
- placeholder={loadingModels ? "Loading models..." : "Select models (leave empty for all)"}
- tokenSeparators={[","]}
- loading={loadingModels}
- showSearch
- options={availableModels.map((m) => ({
- label: getModelDisplayName(m),
- value: m,
- }))}
- />
- </Form.Item>
+ <FieldGroup>
+ <AgentFormField
+ name="entitlement_models"
+ label={labelWithHint(
+ "Allowed Models",
+ "Restrict which models this agent can call. Leave empty to allow all.",
+ )}
+ >
+ {({ id, value, onChange }) => (
+ <AgentTagsInput
+ id={id}
+ value={Array.isArray(value) ? (value as string[]) : []}
+ onValueChange={onChange}
+ placeholder={loadingModels ? "Loading models..." : "Select models (leave empty for all)"}
+ options={availableModels.map((m) => ({ label: getModelDisplayName(m), value: m }))}
+ />
+ )}
+ </AgentFormField>
- <Form.Item
- label={<span className="text-sm font-medium text-gray-700">Allowed Agents (Sub-Agents)</span>}
- name="entitlement_agents"
- tooltip="Restrict which other agents this agent can invoke as sub-agents. Leave empty to allow all."
- >
- <Select
- mode="multiple"
- style={{ width: "100%" }}
- placeholder={loadingAgents ? "Loading agents..." : "Select agents (leave empty for all)"}
- loading={loadingAgents}
- showSearch
- filterOption={(input, option) =>
- ((option?.label as string) ?? "").toLowerCase().includes(input.toLowerCase())
- }
- options={availableAgents.map((a) => ({
- label: a.agent_name,
- value: a.agent_id,
- }))}
- />
- </Form.Item>
+ <AgentFormField
+ name="entitlement_agents"
+ label={labelWithHint(
+ "Allowed Agents (Sub-Agents)",
+ "Restrict which other agents this agent can invoke as sub-agents. Leave empty to allow all.",
+ )}
+ >
+ {({ id, value, onChange }) => (
+ <AgentMultiSelect
+ id={id}
+ value={Array.isArray(value) ? (value as string[]) : []}
+ onValueChange={onChange}
+ placeholder={loadingAgents ? "Loading agents..." : "Select agents (leave empty for all)"}
+ options={availableAgents.map((a) => ({ label: a.agent_name, value: a.agent_id }))}
+ />
+ )}
+ </AgentFormField>
- <Divider className="my-2" />
+ <Separator className="my-2" />
- <Form.Item
- label={
- <span>
- Allowed MCP Servers{" "}
- <InfoCircleOutlined
- title="Select which MCP servers or access groups this agent can access"
- style={{ marginLeft: "4px" }}
+ <AgentFormField
+ name="allowed_mcp_servers_and_groups"
+ label={labelWithHint(
+ "Allowed MCP Servers",
+ "Select which MCP servers or access groups this agent can access",
+ )}
+ >
+ {({ value, onChange }) => (
+ <MCPServerSelector
+ onChange={onChange}
+ value={{
+ servers: (value as McpServerSelection | undefined)?.servers ?? [],
+ accessGroups: (value as McpServerSelection | undefined)?.accessGroups ?? [],
+ }}
+ accessToken={accessToken ?? ""}
+ placeholder="Select MCP servers or access groups (optional)"
/>
- </span>
- }
- name="allowed_mcp_servers_and_groups"
- initialValue={{ servers: [], accessGroups: [] }}
- >
- <MCPServerSelector
- onChange={(val: { servers?: string[]; accessGroups?: string[] }) =>
- form.setFieldValue("allowed_mcp_servers_and_groups", val)
- }
- value={form.getFieldValue("allowed_mcp_servers_and_groups") || { servers: [], accessGroups: [] }}
+ )}
+ </AgentFormField>
+ </FieldGroup>
+
+ <div className="mt-4">
+ <MCPToolPermissions
accessToken={accessToken ?? ""}
- placeholder="Select MCP servers or access groups (optional)"
+ selectedServers={mcpSelection?.servers ?? []}
+ toolPermissions={mcpToolPermissions ?? {}}
+ onChange={(toolPerms: Record<string, string[]>) => form.setValue("mcp_tool_permissions", toolPerms)}
/>
- </Form.Item>
- <Form.Item name="mcp_tool_permissions" initialValue={{}} hidden>
- <Input type="hidden" />
- </Form.Item>
- <Form.Item
- noStyle
- shouldUpdate={(prev, curr) =>
- prev.allowed_mcp_servers_and_groups !== curr.allowed_mcp_servers_and_groups ||
- prev.mcp_tool_permissions !== curr.mcp_tool_permissions
- }
- >
- {() => (
- <div className="mt-4">
- <MCPToolPermissions
- accessToken={accessToken ?? ""}
- selectedServers={form.getFieldValue("allowed_mcp_servers_and_groups")?.servers ?? []}
- toolPermissions={form.getFieldValue("mcp_tool_permissions") ?? {}}
- onChange={(toolPerms: Record<string, string[]>) =>
- form.setFieldsValue({ mcp_tool_permissions: toolPerms })
- }
- />
- </div>
- )}
- </Form.Item>
+ </div>
</div>
);
+ const rateLimitField = (name: keyof AgentFormValues & string, label: string, placeholder: string) => (
+ <AgentFormField name={name} label={label} className="gap-1">
+ {({ value, onChange, ref, ...control }) => (
+ <AgentNumberInput
+ {...control}
+ value={value}
+ onChange={onChange}
+ inputRef={ref}
+ min={0}
+ placeholder={placeholder}
+ disabled={!requireTraceIdOutbound}
+ />
+ )}
+ </AgentFormField>
+ );
+
const renderObservabilityStep = () => (
<div className="space-y-6">
<div>
- <h4 className="text-sm font-medium text-gray-700 mb-3">Tracing</h4>
+ <h4 className="mb-3 text-sm font-medium text-foreground">Tracing</h4>
<div className="space-y-4">
<div className="flex items-center justify-between">
<div>
- <span className="text-sm font-medium text-gray-700">
+ <span className="text-sm font-medium text-foreground">
Require x-litellm-trace-id on calls TO this agent
</span>
- <p className="text-xs text-gray-500 mt-1">
+ <p className="mt-1 text-xs text-muted-foreground">
Only accept this agent being invoked with a trace-id (e.g. when used as a sub-agent).
</p>
</div>
- <Switch checked={requireTraceIdInbound} onChange={setRequireTraceIdInbound} />
+ <Switch checked={requireTraceIdInbound} onCheckedChange={setRequireTraceIdInbound} />
</div>
<div className="flex items-center justify-between">
<div>
- <span className="text-sm font-medium text-gray-700">
+ <span className="text-sm font-medium text-foreground">
Require x-litellm-trace-id on calls BY this agent
</span>
- <p className="text-xs text-gray-500 mt-1">
+ <p className="mt-1 text-xs text-muted-foreground">
Requires LLM/MCP calls made by this agent to include x-litellm-trace-id for session tracking.
</p>
</div>
<Switch
checked={requireTraceIdOutbound}
- onChange={(checked) => {
+ onCheckedChange={(checked) => {
setRequireTraceIdOutbound(checked);
if (!checked) {
setMaxIterations(null);
@@ -506,96 +529,99 @@ const AddAgentForm: React.FC<AddAgentFormProps> = ({ visible, onClose, accessTok
</div>
</div>
- <Divider className="my-0" />
+ <Separator />
<div>
- <h4 className="text-sm font-medium text-gray-700 mb-3">Budgets &amp; Rate Limits</h4>
+ <h4 className="mb-3 text-sm font-medium text-foreground">Budgets &amp; Rate Limits</h4>
<div className="space-y-4">
{!requireTraceIdOutbound && (
- <div className="p-3 bg-yellow-50 border border-yellow-200 rounded-lg text-sm text-yellow-800">
+ <div className="rounded-lg border border-yellow-200 bg-yellow-50 p-3 text-sm text-yellow-800 dark:border-yellow-800 dark:bg-yellow-950 dark:text-yellow-300">
Enable &quot;Require x-litellm-trace-id on calls BY this agent&quot; in Tracing to configure budgets and
rate limits.
</div>
)}
- <div className="text-sm font-medium text-gray-700">Session Budgets</div>
+ <div className="text-sm font-medium text-foreground">Session Budgets</div>
<div className="grid grid-cols-2 gap-4">
- <div>
- <label className="text-sm text-gray-600 block mb-1">Max Iterations</label>
- <InputNumber
- className="w-full"
- min={1}
+ <Field className="gap-1">
+ <FieldLabel htmlFor="agent-max-iterations">Max Iterations</FieldLabel>
+ <Input
+ id="agent-max-iterations"
+ type="number"
+ step="any"
placeholder="e.g. 25"
disabled={!requireTraceIdOutbound}
- value={maxIterations}
- onChange={(val) => setMaxIterations(val)}
+ value={maxIterations ?? ""}
+ onChange={(event) =>
+ setMaxIterations(Number.isNaN(event.target.valueAsNumber) ? null : event.target.valueAsNumber)
+ }
+ onBlur={() => setMaxIterations((current) => (current !== null && current < 1 ? 1 : current))}
/>
- <p className="text-xs text-gray-400 mt-1">Hard cap on LLM calls per session</p>
- </div>
- <div>
- <label className="text-sm text-gray-600 block mb-1">Max Budget Per Session ($)</label>
- <InputNumber
- className="w-full"
- min={0.01}
- step={0.5}
+ <p className="mt-1 text-xs text-muted-foreground">Hard cap on LLM calls per session</p>
+ </Field>
+ <Field className="gap-1">
+ <FieldLabel htmlFor="agent-max-budget-per-session">Max Budget Per Session ($)</FieldLabel>
+ <Input
+ id="agent-max-budget-per-session"
+ type="number"
+ step="any"
placeholder="e.g. 5.00"
disabled={!requireTraceIdOutbound}
- value={maxBudgetPerSession}
- onChange={(val) => setMaxBudgetPerSession(val)}
+ value={maxBudgetPerSession ?? ""}
+ onChange={(event) =>
+ setMaxBudgetPerSession(Number.isNaN(event.target.valueAsNumber) ? null : event.target.valueAsNumber)
+ }
+ onBlur={() =>
+ setMaxBudgetPerSession((current) => (current !== null && current < 0.01 ? 0.01 : current))
+ }
/>
- <p className="text-xs text-gray-400 mt-1">Max spend per trace before returning 429</p>
- </div>
+ <p className="mt-1 text-xs text-muted-foreground">Max spend per trace before returning 429</p>
+ </Field>
</div>
- <Divider className="my-2" />
+ <Separator className="my-2" />
- <div className="text-sm font-medium text-gray-700">Agent Rate Limits</div>
- <p className="text-xs text-gray-500">Global rate limits applied across all callers of this agent.</p>
+ <div className="text-sm font-medium text-foreground">Agent Rate Limits</div>
+ <p className="text-xs text-muted-foreground">Global rate limits applied across all callers of this agent.</p>
<div className="grid grid-cols-2 gap-4">
- <Form.Item label="TPM Limit" name="tpm_limit" className="mb-0">
- <InputNumber className="w-full" min={0} placeholder="e.g. 100000" disabled={!requireTraceIdOutbound} />
- </Form.Item>
- <Form.Item label="RPM Limit" name="rpm_limit" className="mb-0">
- <InputNumber className="w-full" min={0} placeholder="e.g. 100" disabled={!requireTraceIdOutbound} />
- </Form.Item>
+ {rateLimitField("tpm_limit", "TPM Limit", "e.g. 100000")}
+ {rateLimitField("rpm_limit", "RPM Limit", "e.g. 100")}
</div>
- <div className="text-sm font-medium text-gray-700 mt-4">Per-Session Rate Limits</div>
- <p className="text-xs text-gray-500">
+ <div className="mt-4 text-sm font-medium text-foreground">Per-Session Rate Limits</div>
+ <p className="text-xs text-muted-foreground">
Rate limits per session (x-litellm-trace-id). Each session gets its own counters.
</p>
<div className="grid grid-cols-2 gap-4">
- <Form.Item label="Session TPM Limit" name="session_tpm_limit" className="mb-0">
- <InputNumber className="w-full" min={0} placeholder="e.g. 10000" disabled={!requireTraceIdOutbound} />
- </Form.Item>
- <Form.Item label="Session RPM Limit" name="session_rpm_limit" className="mb-0">
- <InputNumber className="w-full" min={0} placeholder="e.g. 20" disabled={!requireTraceIdOutbound} />
- </Form.Item>
+ {rateLimitField("session_tpm_limit", "Session TPM Limit", "e.g. 10000")}
+ {rateLimitField("session_rpm_limit", "Session RPM Limit", "e.g. 20")}
</div>
</div>
</div>
- <Divider className="my-0" />
+ <Separator />
<div>
- <h4 className="text-sm font-medium text-gray-700 mb-3">Guardrails</h4>
- <p className="text-xs text-gray-500 mb-3">
+ <h4 className="mb-3 text-sm font-medium text-foreground">Guardrails</h4>
+ <p className="mb-3 text-xs text-muted-foreground">
Apply guardrails to this agent. Selected guardrails will run on all calls made by this agent.
</p>
- <Form.Item name="guardrails" initialValue={[]}>
- <GuardrailSelector
- accessToken={accessToken ?? ""}
- value={form.getFieldValue("guardrails") ?? []}
- onChange={(selected: string[]) => form.setFieldsValue({ guardrails: selected })}
- />
- </Form.Item>
+ <AgentFormField name="guardrails">
+ {({ value, onChange }) => (
+ <GuardrailSelector
+ accessToken={accessToken ?? ""}
+ value={Array.isArray(value) ? (value as string[]) : []}
+ onChange={onChange}
+ />
+ )}
+ </AgentFormField>
</div>
</div>
);
const handleAgentTypeChange = (value: string) => {
setAgentType(value);
- form.resetFields();
+ form.reset(buildInitialValues(agentType));
// Discovery selections are tied to a specific agent type's URL shape;
// switching types invalidates them.
setAppliedDiscoveredSelection(null);
@@ -604,12 +630,6 @@ const AddAgentForm: React.FC<AddAgentFormProps> = ({ visible, onClose, accessTok
// Apply a discovered agent card to the form so the rest of Step 1 (skills,
// capabilities, name, description, URL) reflects what the user picked. The
// proxy re-applies its own merge at registration; we only seed defaults here.
- //
- // AntD's `setFieldsValue` silently ignores keys whose Form.Item isn't
- // registered, so this is safe across all agent types — A2A forms pick up
- // every field below; LangGraph and other dynamic forms only pick up the
- // shared ones (`agent_name`, `description`, plus any credential field whose
- // key looks URL-ish).
const handleApplyDiscoveredCard = (selection: DiscoveredAgentCardSelection | null) => {
setAppliedDiscoveredSelection(selection);
if (!selection) return;
@@ -622,10 +642,14 @@ const AddAgentForm: React.FC<AddAgentFormProps> = ({ visible, onClose, accessTok
examples: s.examples ?? [],
}));
- const currentAgentName = form.getFieldValue("agent_name");
+ const currentAgentName = form.getValues("agent_name");
const seededAgentName = currentAgentName || selected_card.name || selected_card.provider?.organization || "";
- const fieldsToSet: Record<string, any> = {
+ const urlCredentialKeys = (selectedAgentTypeInfo?.credential_fields ?? [])
+ .map((f) => f.key)
+ .filter((key) => /(^|_)(url|api_base|endpoint)$/i.test(key));
+
+ const fieldsToSet: AgentFormValues = {
agent_name: seededAgentName,
name: selected_card.name,
description: selected_card.description,
@@ -636,20 +660,13 @@ const AddAgentForm: React.FC<AddAgentFormProps> = ({ visible, onClose, accessTok
skills,
iconUrl: selected_card.iconUrl,
documentationUrl: selected_card.documentationUrl,
+ ...Object.fromEntries(urlCredentialKeys.map((key) => [key, upstream_url])),
};
- // For dynamic agent types (e.g. LangGraph), the URL lives in a
- // type-specific credential field. Match on common naming variants so the
- // user doesn't have to re-paste the URL they already typed above.
- const urlCredentialKeys = (selectedAgentTypeInfo?.credential_fields ?? [])
- .map((f) => f.key)
- .filter((key) => /(^|_)(url|api_base|endpoint)$/i.test(key));
- for (const key of urlCredentialKeys) {
- fieldsToSet[key] = upstream_url;
+ for (const [key, value] of Object.entries(fieldsToSet)) {
+ form.setValue(key, value);
}
- form.setFieldsValue(fieldsToSet);
-
if (!newKeyName && seededAgentName) {
setNewKeyName(`${seededAgentName}-key`);
}
@@ -663,7 +680,7 @@ const AddAgentForm: React.FC<AddAgentFormProps> = ({ visible, onClose, accessTok
const renderConfigureStep = () => (
<>
<Form.Item
- label={<span className="text-sm font-medium text-gray-700">Agent Type</span>}
+ label={<span className="text-sm font-medium text-foreground">Agent Type</span>}
required
tooltip="Select the type of agent you want to create"
>
@@ -676,25 +693,29 @@ const AddAgentForm: React.FC<AddAgentFormProps> = ({ visible, onClose, accessTok
dropdownRender={(menu) => (
<>
{menu}
- <Divider style={{ margin: "4px 0" }} />
+ <Separator className="my-1" />
<div className="px-2 py-1">
- <div className="text-xs text-gray-400 font-medium mb-1 uppercase tracking-wide px-2">Not listed?</div>
+ <div className="mb-1 px-2 text-xs font-medium tracking-wide text-muted-foreground uppercase">
+ Not listed?
+ </div>
<div
- className={`flex items-center gap-3 px-2 py-2 rounded cursor-pointer transition-colors ${
- agentType === CUSTOM_AGENT_TYPE ? "bg-amber-50" : "hover:bg-amber-50"
+ className={`flex cursor-pointer items-center gap-3 rounded px-2 py-2 transition-colors ${
+ agentType === CUSTOM_AGENT_TYPE
+ ? "bg-amber-50 dark:bg-amber-950"
+ : "hover:bg-amber-50 dark:hover:bg-amber-950"
}`}
onClick={() => handleAgentTypeChange(CUSTOM_AGENT_TYPE)}
>
- <AppstoreOutlined className="text-amber-600 text-lg" />
+ <AppstoreOutlined className="text-lg text-amber-600 dark:text-amber-400" />
<div className="flex-1">
<div className="flex items-center gap-2">
- <span className="font-medium text-amber-700">Custom / Other</span>
+ <span className="font-medium text-amber-700 dark:text-amber-400">Custom / Other</span>
<Tag color="orange" style={{ fontSize: 10, padding: "0 4px" }}>
GENERIC
</Tag>
</div>
- <div className="text-xs text-amber-600">
- For agents that don&apos;t follow a standard protocol — just needs a virtual key
+ <div className="text-xs text-amber-600 dark:text-amber-400">
+ For agents that don&apos;t follow a standard protocol, just needs a virtual key
</div>
</div>
</div>
@@ -708,16 +729,16 @@ const AddAgentForm: React.FC<AddAgentFormProps> = ({ visible, onClose, accessTok
value={info.agent_type}
label={
<div className="flex items-center gap-2">
- <Logo src={info.logo_url} label={info.agent_type_display_name} className="w-4 h-4 object-contain" />
+ <Logo src={info.logo_url} label={info.agent_type_display_name} className="h-4 w-4 object-contain" />
<span>{info.agent_type_display_name}</span>
</div>
}
>
<div className="flex items-center gap-3 py-1">
- <Logo src={info.logo_url} label={info.agent_type_display_name} className="w-5 h-5 object-contain" />
+ <Logo src={info.logo_url} label={info.agent_type_display_name} className="h-5 w-5 object-contain" />
<div>
<div className="font-medium">{info.agent_type_display_name}</div>
- {info.description && <div className="text-xs text-gray-500">{info.description}</div>}
+ {info.description && <div className="text-xs text-muted-foreground">{info.description}</div>}
</div>
</div>
</Select.Option>
@@ -727,49 +748,77 @@ const AddAgentForm: React.FC<AddAgentFormProps> = ({ visible, onClose, accessTok
<div className="mt-4">
{agentType === CUSTOM_AGENT_TYPE ? (
- <div className="space-y-4">
- <Form.Item
- label="Agent Name"
- name="agent_name"
- rules={[{ required: true, message: "Please enter an agent name" }]}
- >
- <Input placeholder="e.g. my-custom-agent" />
- </Form.Item>
- <Form.Item label="Description" name="description">
- <Input.TextArea placeholder="Describe what this agent does…" rows={3} />
- </Form.Item>
- </div>
+ <FieldGroup>
+ <AgentFormField name="agent_name" label="Agent Name" rules={{ required: "Please enter an agent name" }}>
+ {({ value, onChange, ref, ...control }) => (
+ <Input
+ {...control}
+ ref={ref}
+ placeholder="e.g. my-custom-agent"
+ value={typeof value === "string" ? value : ""}
+ onChange={onChange}
+ />
+ )}
+ </AgentFormField>
+ <AgentFormField name="description" label="Description">
+ {({ value, onChange, ref, ...control }) => (
+ <Textarea
+ {...control}
+ ref={ref}
+ rows={3}
+ placeholder="Describe what this agent does…"
+ value={typeof value === "string" ? value : ""}
+ onChange={onChange}
+ />
+ )}
+ </AgentFormField>
+ </FieldGroup>
) : agentType === "a2a" ? (
- <AgentFormFields showAgentName={true} />
+ <AgentFormFields showAgentName={true} panels={panels} />
) : selectedAgentTypeInfo?.use_a2a_form_fields ? (
<>
- <AgentFormFields showAgentName={true} />
+ <AgentFormFields showAgentName={true} panels={panels} />
{selectedAgentTypeInfo.credential_fields.length > 0 && (
- <div className="mt-4 p-4 border border-gray-200 rounded-lg">
- <h4 className="text-sm font-medium text-gray-700 mb-3">
+ <div className="mt-4 rounded-lg border border-border p-4">
+ <h4 className="mb-3 text-sm font-medium text-foreground">
{selectedAgentTypeInfo.agent_type_display_name} Settings
</h4>
- {selectedAgentTypeInfo.credential_fields.map((field) => (
- <Form.Item
- key={field.key}
- label={field.label}
- name={field.key}
- rules={field.required ? [{ required: true, message: `Please enter ${field.label}` }] : undefined}
- tooltip={field.tooltip}
- initialValue={field.default_value}
- >
- {field.field_type === "password" ? (
- <Input.Password placeholder={field.placeholder || ""} />
- ) : (
- <Input placeholder={field.placeholder || ""} />
- )}
- </Form.Item>
- ))}
+ <FieldGroup>
+ {selectedAgentTypeInfo.credential_fields.map((field) => (
+ <AgentFormField
+ key={field.key}
+ name={field.key}
+ label={field.tooltip ? labelWithHint(field.label, field.tooltip) : field.label}
+ defaultValue={field.default_value ?? undefined}
+ rules={field.required ? { required: `Please enter ${field.label}` } : undefined}
+ >
+ {({ value, onChange, ref, ...control }) =>
+ field.field_type === "password" ? (
+ <PasswordInput
+ {...control}
+ value={typeof value === "string" ? value : ""}
+ onChange={onChange}
+ ref={ref}
+ placeholder={field.placeholder || ""}
+ />
+ ) : (
+ <Input
+ {...control}
+ ref={ref}
+ placeholder={field.placeholder || ""}
+ value={typeof value === "string" ? value : ""}
+ onChange={onChange}
+ />
+ )
+ }
+ </AgentFormField>
+ ))}
+ </FieldGroup>
</div>
)}
</>
) : selectedAgentTypeInfo ? (
- <DynamicAgentFormFields agentTypeInfo={selectedAgentTypeInfo} />
+ <DynamicAgentFormFields agentTypeInfo={selectedAgentTypeInfo} panels={panels} />
) : null}
{/* Discovery sits at the bottom so its URL can be derived from the
@@ -791,59 +840,64 @@ const AddAgentForm: React.FC<AddAgentFormProps> = ({ visible, onClose, accessTok
);
const renderAssignKeyStep = () => {
- const agentName = form.getFieldValue("agent_name") || "your-agent";
+ const agentName = form.getValues("agent_name") || "your-agent";
return (
<div>
{/* Agent name chip */}
- <div className="flex justify-center mb-6">
+ <div className="mb-6 flex justify-center">
<Tag icon={<RobotOutlined />} color="purple" className="px-3 py-1 text-sm">
{agentName}
</Tag>
</div>
- <Form.Item
- label={<span className="text-sm font-medium text-gray-700">Assign to Team</span>}
+ <AgentFormField
name="team_id"
- tooltip="Optionally assign this agent to a team. The agent and its key will belong to the selected team."
+ label={labelWithHint(
+ "Assign to Team",
+ "Optionally assign this agent to a team. The agent and its key will belong to the selected team.",
+ )}
>
- <TeamDropdown />
- </Form.Item>
+ {({ value, onChange }) => (
+ <TeamDropdown value={typeof value === "string" ? value : undefined} onChange={onChange} />
+ )}
+ </AgentFormField>
- <Divider className="my-4" />
+ <Separator className="my-4" />
- <div className="space-y-3">
+ <RadioGroup
+ value={keyAssignOption}
+ onValueChange={(value) => setKeyAssignOption(value as "create_new" | "existing_key" | "skip")}
+ className="space-y-3"
+ >
{/* Option: Create new key */}
<div
- className={`p-4 border-2 rounded-lg cursor-pointer transition-colors ${
+ className={`cursor-pointer rounded-lg border-2 p-4 transition-colors ${
keyAssignOption === "create_new"
- ? "border-indigo-600 bg-indigo-50"
- : "border-gray-200 bg-white hover:border-gray-300"
+ ? "border-indigo-600 bg-indigo-50 dark:border-indigo-400 dark:bg-indigo-950"
+ : "border-border bg-background hover:border-muted-foreground/40"
}`}
onClick={() => setKeyAssignOption("create_new")}
>
<div className="flex items-start justify-between">
- <div className="flex items-start gap-3 flex-1">
- <Radio
- value="create_new"
- checked={keyAssignOption === "create_new"}
- onChange={() => setKeyAssignOption("create_new")}
- />
+ <div className="flex flex-1 items-start gap-3">
+ <RadioGroupItem value="create_new" aria-label="Create a new key for this agent" />
<div className="flex-1">
<div className="flex items-center gap-2">
- <KeyOutlined className="text-indigo-600" />
- <span className="font-medium text-gray-900">Create a new key for this agent</span>
+ <KeyOutlined className="text-indigo-600 dark:text-indigo-400" />
+ <span className="font-medium text-foreground">Create a new key for this agent</span>
</div>
- <p className="text-sm text-gray-500 mt-1">A dedicated key scoped to this agent.</p>
+ <p className="mt-1 text-sm text-muted-foreground">A dedicated key scoped to this agent.</p>
{keyAssignOption === "create_new" && (
<div className="mt-3 space-y-3" onClick={(e) => e.stopPropagation()}>
- <div>
- <label className="text-sm text-gray-600 block mb-1">Key Name</label>
+ <Field className="gap-1">
+ <FieldLabel htmlFor="agent-new-key-name">Key Name</FieldLabel>
<Input
+ id="agent-new-key-name"
value={newKeyName}
onChange={(e) => setNewKeyName(e.target.value)}
placeholder="e.g. my-agent-key"
/>
- </div>
+ </Field>
</div>
)}
</div>
@@ -854,37 +908,28 @@ const AddAgentForm: React.FC<AddAgentFormProps> = ({ visible, onClose, accessTok
{/* Option: Assign existing key */}
<div
- className={`p-4 border-2 rounded-lg cursor-pointer transition-colors ${
+ className={`cursor-pointer rounded-lg border-2 p-4 transition-colors ${
keyAssignOption === "existing_key"
- ? "border-indigo-600 bg-indigo-50"
- : "border-gray-200 bg-white hover:border-gray-300"
+ ? "border-indigo-600 bg-indigo-50 dark:border-indigo-400 dark:bg-indigo-950"
+ : "border-border bg-background hover:border-muted-foreground/40"
}`}
onClick={() => setKeyAssignOption("existing_key")}
>
<div className="flex items-start gap-3">
- <Radio
- value="existing_key"
- checked={keyAssignOption === "existing_key"}
- onChange={() => setKeyAssignOption("existing_key")}
- />
+ <RadioGroupItem value="existing_key" aria-label="Assign an existing key" />
<div className="flex-1">
<div className="flex items-center gap-2">
- <KeyOutlined className="text-gray-500" />
- <span className="font-medium text-gray-900">Assign an existing key</span>
+ <KeyOutlined className="text-muted-foreground" />
+ <span className="font-medium text-foreground">Assign an existing key</span>
</div>
- <p className="text-sm text-gray-500 mt-1">Re-assign a key you already have to this agent.</p>
+ <p className="mt-1 text-sm text-muted-foreground">Re-assign a key you already have to this agent.</p>
{keyAssignOption === "existing_key" && (
<div className="mt-3" onClick={(e) => e.stopPropagation()}>
- <Select
- showSearch
- style={{ width: "100%" }}
- placeholder="Search by key name…"
- loading={loadingKeys}
- value={selectedExistingKey}
- onChange={(value) => setSelectedExistingKey(value)}
- filterOption={(input, option) =>
- ((option?.label as string) ?? "").toLowerCase().includes(input.toLowerCase())
- }
+ <SearchSelect
+ inputId="agent-existing-key"
+ placeholder={loadingKeys ? "Loading keys…" : "Search by key name…"}
+ value={selectedExistingKey ?? ""}
+ onValueChange={(value) => setSelectedExistingKey(value || null)}
options={existingKeys.map((k) => ({
label: k.key_alias || k.token?.slice(0, 12) + "…",
value: k.token,
@@ -895,12 +940,12 @@ const AddAgentForm: React.FC<AddAgentFormProps> = ({ visible, onClose, accessTok
</div>
</div>
</div>
- </div>
+ </RadioGroup>
- <div className="text-center mt-4">
+ <div className="mt-4 text-center">
<button
type="button"
- className="text-sm text-gray-500 underline hover:text-gray-700"
+ className="text-sm text-muted-foreground underline hover:text-foreground"
onClick={() => setKeyAssignOption("skip")}
>
Skip for now — I&apos;ll assign a key later
@@ -911,26 +956,28 @@ const AddAgentForm: React.FC<AddAgentFormProps> = ({ visible, onClose, accessTok
};
const renderReadyStep = () => (
- <div className="text-center py-6">
- <CheckCircleFilled className="text-5xl text-green-500 mb-4" style={{ fontSize: 48 }} />
- <h3 className="text-xl font-semibold text-gray-900 mb-2">Agent Created!</h3>
- <div className="flex justify-center mb-4">
+ <div className="py-6 text-center">
+ <CheckCircleFilled className="mb-4 text-5xl text-green-500" style={{ fontSize: 48 }} />
+ <h3 className="mb-2 text-xl font-semibold text-foreground">Agent Created!</h3>
+ <div className="mb-4 flex justify-center">
<Tag icon={<RobotOutlined />} color="purple" className="px-3 py-1 text-sm">
{createdAgentName}
</Tag>
</div>
{createdKeyValue && (
- <div className="mt-4 text-left max-w-md mx-auto">
+ <div className="mx-auto mt-4 max-w-md text-left">
<CreatedKeyDisplay apiKey={createdKeyValue} />
</div>
)}
{assignedKeyAlias && (
- <p className="text-sm text-gray-600 mt-2">
+ <p className="mt-2 text-sm text-muted-foreground">
Key <span className="font-medium">{assignedKeyAlias}</span> has been assigned to this agent.
</p>
)}
{!createdKeyValue && !assignedKeyAlias && keyAssignOption === "skip" && (
- <p className="text-sm text-gray-500 mt-2">No key assigned. You can create one from the Virtual Keys page.</p>
+ <p className="mt-2 text-sm text-muted-foreground">
+ No key assigned. You can create one from the Virtual Keys page.
+ </p>
)}
</div>
);
@@ -938,11 +985,11 @@ const AddAgentForm: React.FC<AddAgentFormProps> = ({ visible, onClose, accessTok
return (
<Modal
title={
- <div className="flex items-center space-x-3 pb-4 border-b border-gray-100">
+ <div className="flex items-center space-x-3 border-b border-border pb-4">
{selectedLogo && currentStep < 1 && (
- <Logo src={selectedLogo} label="Agent" className="w-6 h-6 object-contain" />
+ <Logo src={selectedLogo} label="Agent" className="h-6 w-6 object-contain" />
)}
- <h2 className="text-xl font-semibold text-gray-900">Add New Agent</h2>
+ <h2 className="text-xl font-semibold text-foreground">Add New Agent</h2>
</div>
}
open={visible}
@@ -955,93 +1002,59 @@ const AddAgentForm: React.FC<AddAgentFormProps> = ({ visible, onClose, accessTok
header: { padding: "24px 24px 0 24px", border: "none" },
}}
>
- <div className="mt-4">
- {/* Step indicator */}
- <Steps current={currentStep} size="small" className="mb-8">
- <Step title="Configure" />
- <Step title="Entitlements" />
- <Step title="Governance" />
- <Step title="Agent Management" />
- <Step title="Ready" />
- </Steps>
-
- <Form
- form={form}
- layout="vertical"
- initialValues={
- agentType === "a2a"
- ? {
- ...getDefaultFormValues(),
- allowed_mcp_servers_and_groups: { servers: [], accessGroups: [] },
- mcp_tool_permissions: {},
- entitlement_models: [],
- entitlement_agents: [],
- guardrails: [],
- }
- : {
- allowed_mcp_servers_and_groups: { servers: [], accessGroups: [] },
- mcp_tool_permissions: {},
- entitlement_models: [],
- entitlement_agents: [],
- guardrails: [],
- }
- }
- className="space-y-4"
- >
- {currentStep === 0 && renderConfigureStep()}
- {currentStep === 1 && renderEntitlementsStep()}
- {currentStep === 2 && renderObservabilityStep()}
- {currentStep === 3 && renderAssignKeyStep()}
- {currentStep === 4 && renderReadyStep()}
- </Form>
-
- {/* Footer navigation */}
- <div className="flex items-center justify-between pt-6 border-t border-gray-100 mt-6">
- <div>
- {currentStep > 0 && currentStep < 4 && (
- <button
- type="button"
- onClick={handleBack}
- className="text-sm text-gray-600 border border-gray-300 rounded-sm px-4 py-2 hover:bg-gray-50"
- >
- ← Back
- </button>
- )}
- </div>
- <div className="flex gap-3">
- {currentStep < 4 && (
- <Button variant="secondary" onClick={handleClose}>
- Cancel
- </Button>
- )}
- {currentStep === 0 && (
- <Button variant="primary" onClick={handleNext}>
- Next →
- </Button>
- )}
- {currentStep === 1 && (
- <Button variant="primary" onClick={handleNext}>
- Next →
- </Button>
- )}
- {currentStep === 2 && (
- <Button variant="primary" onClick={handleNext}>
- Next →
- </Button>
- )}
- {currentStep === 3 && (
- <Button variant="primary" loading={isSubmitting} onClick={handleCreateAgent}>
- {isSubmitting ? "Creating..." : "Create Agent →"}
- </Button>
- )}
- {currentStep === 4 && (
- <Button variant="primary" onClick={handleClose}>
- Done
- </Button>
- )}
+ <TooltipProvider>
+ <div className="mt-4">
+ <Steps current={currentStep} size="small" className="mb-8">
+ <Step title="Configure" />
+ <Step title="Entitlements" />
+ <Step title="Governance" />
+ <Step title="Agent Management" />
+ <Step title="Ready" />
+ </Steps>
+
+ <FormProvider {...form}>
+ <form onSubmit={(event) => event.preventDefault()} className="space-y-4">
+ {currentStep === 0 && renderConfigureStep()}
+ {currentStep === 1 && renderEntitlementsStep()}
+ {currentStep === 2 && renderObservabilityStep()}
+ {currentStep === 3 && renderAssignKeyStep()}
+ {currentStep === 4 && renderReadyStep()}
+ </form>
+ </FormProvider>
+
+ <div className="mt-6 flex items-center justify-between border-t border-border pt-6">
+ <div>
+ {currentStep > 0 && currentStep < 4 && (
+ <ShadButton type="button" variant="outline" onClick={handleBack}>
+ ← Back
+ </ShadButton>
+ )}
+ </div>
+ <div className="flex gap-3">
+ {currentStep < 4 && (
+ <Button variant="secondary" onClick={handleClose}>
+ Cancel
+ </Button>
+ )}
+ {currentStep < 3 && (
+ <Button variant="primary" onClick={handleNext}>
+ Next →
+ </Button>
+ )}
+ {currentStep === 3 && (
+ <Button variant="primary" loading={isSubmitting} onClick={handleCreateAgent}>
+ {isSubmitting ? "Creating..." : "Create Agent →"}
+ </Button>
+ )}
+ {currentStep === 4 && (
+ <Button variant="primary" onClick={handleClose}>
+ Done
+ </Button>
+ )}
+ </div>
</div>
</div>
- </div>
+ </TooltipProvider>
</Modal>
);
};
diff --git a/ui/litellm-dashboard/src/app/(dashboard)/agents/_components/agent_form_fields.tsx b/ui/litellm-dashboard/src/app/(dashboard)/agents/_components/agent_form_fields.tsx
index ff103218346..243da085cb7 100644
--- a/ui/litellm-dashboard/src/app/(dashboard)/agents/_components/agent_form_fields.tsx
+++ b/ui/litellm-dashboard/src/app/(dashboard)/agents/_components/agent_form_fields.tsx
@@ -1,266 +1,400 @@
import React from "react";
-import { Form, Input, Switch, Collapse, Select, Space, Tooltip } from "antd";
-import { Button as AntButton } from "antd";
-import { PlusOutlined, MinusCircleOutlined, InfoCircleOutlined } from "@ant-design/icons";
+import { useFieldArray, useFormContext } from "react-hook-form";
+import { Plus, Trash2 } from "lucide-react";
+import { Button } from "@/components/ui/button";
+import { Input } from "@/components/ui/input";
+import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select";
+import { Switch } from "@/components/ui/switch";
+import { Textarea } from "@/components/ui/textarea";
+import { Field, FieldGroup, FieldTitle } from "@/components/shared/form/field";
import { AGENT_FORM_CONFIG, SKILL_FIELD_CONFIG } from "./agent_config";
+import CostConfigFields, { COST_FIELD_NAMES } from "./cost_config_fields";
+import {
+ AgentFormField,
+ AgentFormPanel,
+ AgentFormValues,
+ AgentTagsInput,
+ CollapsiblePanelsState,
+ labelWithHint,
+} from "./AgentFormKit";
-import CostConfigFields from "./cost_config_fields";
+const AUTH_HEADERS_PANEL_KEY = "auth_headers";
-const { Panel } = Collapse;
+const namesOf = (fields: readonly { name: string }[]): readonly string[] => fields.map((field) => field.name);
+
+export const A2A_PANEL_FIELD_NAMES: Readonly<Record<string, readonly string[]>> = {
+ [AGENT_FORM_CONFIG.basic.key]: namesOf(AGENT_FORM_CONFIG.basic.fields),
+ [AGENT_FORM_CONFIG.skills.key]: ["skills"],
+ [AGENT_FORM_CONFIG.capabilities.key]: namesOf(AGENT_FORM_CONFIG.capabilities.fields),
+ [AGENT_FORM_CONFIG.optional.key]: namesOf(AGENT_FORM_CONFIG.optional.fields),
+ [AGENT_FORM_CONFIG.cost.key]: COST_FIELD_NAMES,
+ [AGENT_FORM_CONFIG.litellm.key]: namesOf(AGENT_FORM_CONFIG.litellm.fields),
+ [AUTH_HEADERS_PANEL_KEY]: ["static_headers", "extra_headers"],
+};
+
+export const unmountedA2AFieldNames = (mountedPanels: readonly string[]): readonly string[] =>
+ Object.entries(A2A_PANEL_FIELD_NAMES)
+ .filter(([panelKey]) => !mountedPanels.includes(panelKey))
+ .flatMap(([, fieldNames]) => fieldNames);
interface AgentFormFieldsProps {
+ panels: CollapsiblePanelsState;
showAgentName?: boolean;
visiblePanels?: string[];
}
-/**
- * Reusable form fields component for agent forms
- * Uses shared configuration from agent_config.ts
- */
-const AgentFormFields: React.FC<AgentFormFieldsProps> = ({ showAgentName = true, visiblePanels }) => {
+const SkillsFieldArray = () => {
+ const { control } = useFormContext<AgentFormValues>();
+ const { fields, append, remove } = useFieldArray({ control, name: "skills" });
+
+ return (
+ <>
+ {fields.map((item, index) => (
+ <div key={item.id} className="rounded-md border border-border p-4">
+ <FieldGroup>
+ <AgentFormField
+ name={`skills.${index}.id`}
+ label={SKILL_FIELD_CONFIG.id.label}
+ rules={SKILL_FIELD_CONFIG.id.required ? { required: "Required" } : undefined}
+ >
+ {({ value, onChange, ref, ...control }) => (
+ <Input
+ {...control}
+ ref={ref}
+ placeholder={SKILL_FIELD_CONFIG.id.placeholder}
+ value={typeof value === "string" ? value : ""}
+ onChange={onChange}
+ />
+ )}
+ </AgentFormField>
+
+ <AgentFormField
+ name={`skills.${index}.name`}
+ label={SKILL_FIELD_CONFIG.name.label}
+ rules={SKILL_FIELD_CONFIG.name.required ? { required: "Required" } : undefined}
+ >
+ {({ value, onChange, ref, ...control }) => (
+ <Input
+ {...control}
+ ref={ref}
+ placeholder={SKILL_FIELD_CONFIG.name.placeholder}
+ value={typeof value === "string" ? value : ""}
+ onChange={onChange}
+ />
+ )}
+ </AgentFormField>
+
+ <AgentFormField
+ name={`skills.${index}.description`}
+ label={SKILL_FIELD_CONFIG.description.label}
+ rules={SKILL_FIELD_CONFIG.description.required ? { required: "Required" } : undefined}
+ >
+ {({ value, onChange, ref, ...control }) => (
+ <Textarea
+ {...control}
+ ref={ref}
+ rows={SKILL_FIELD_CONFIG.description.rows}
+ placeholder={SKILL_FIELD_CONFIG.description.placeholder}
+ value={typeof value === "string" ? value : ""}
+ onChange={onChange}
+ />
+ )}
+ </AgentFormField>
+
+ <AgentFormField
+ name={`skills.${index}.tags`}
+ label={SKILL_FIELD_CONFIG.tags.label}
+ rules={SKILL_FIELD_CONFIG.tags.required ? { required: "Required" } : undefined}
+ >
+ {({ id, value, onChange }) => (
+ <AgentTagsInput
+ id={id}
+ value={Array.isArray(value) ? (value as string[]) : []}
+ onValueChange={onChange}
+ placeholder={SKILL_FIELD_CONFIG.tags.placeholder}
+ />
+ )}
+ </AgentFormField>
+
+ <AgentFormField name={`skills.${index}.examples`} label={SKILL_FIELD_CONFIG.examples.label}>
+ {({ id, value, onChange }) => (
+ <AgentTagsInput
+ id={id}
+ value={Array.isArray(value) ? (value as string[]) : []}
+ onValueChange={onChange}
+ placeholder={SKILL_FIELD_CONFIG.examples.placeholder}
+ />
+ )}
+ </AgentFormField>
+ </FieldGroup>
+
+ <Button
+ type="button"
+ variant="ghost"
+ className="mt-4 text-destructive hover:text-destructive"
+ onClick={() => remove(index)}
+ >
+ <Trash2 />
+ Remove Skill
+ </Button>
+ </div>
+ ))}
+ <Button type="button" variant="outline" className="w-full border-dashed" onClick={() => append({})}>
+ <Plus />
+ Add Skill
+ </Button>
+ </>
+ );
+};
+
+const StaticHeadersFieldArray = () => {
+ const { control } = useFormContext<AgentFormValues>();
+ const { fields, append, remove } = useFieldArray({ control, name: "static_headers" });
+
+ return (
+ <>
+ {fields.map((item, index) => (
+ <div key={item.id} className="flex items-start gap-2">
+ <AgentFormField name={`static_headers.${index}.header`} rules={{ required: "Header name required" }}>
+ {({ value, onChange, ref, ...control }) => (
+ <Input
+ {...control}
+ ref={ref}
+ className="w-55"
+ placeholder="Header name (e.g. Authorization)"
+ value={typeof value === "string" ? value : ""}
+ onChange={onChange}
+ />
+ )}
+ </AgentFormField>
+ <AgentFormField name={`static_headers.${index}.value`} rules={{ required: "Value required" }}>
+ {({ value, onChange, ref, ...control }) => (
+ <Input
+ {...control}
+ ref={ref}
+ className="w-65"
+ placeholder="Value (e.g. Bearer token123)"
+ value={typeof value === "string" ? value : ""}
+ onChange={onChange}
+ />
+ )}
+ </AgentFormField>
+ <Button
+ type="button"
+ variant="ghost"
+ size="icon"
+ aria-label="Remove static header"
+ className="text-destructive hover:text-destructive"
+ onClick={() => remove(index)}
+ >
+ <Trash2 />
+ </Button>
+ </div>
+ ))}
+ <Button type="button" variant="outline" className="w-full border-dashed" onClick={() => append({})}>
+ <Plus />
+ Add Static Header
+ </Button>
+ </>
+ );
+};
+
+const AgentFormFields: React.FC<AgentFormFieldsProps> = ({ panels, showAgentName = true, visiblePanels }) => {
const shouldShow = (key: string) => !visiblePanels || visiblePanels.includes(key);
+
return (
<>
{showAgentName && (
- <Form.Item
- label="Agent Name"
- name="agent_name"
- rules={[{ required: true, message: "Please enter a unique agent name" }]}
- tooltip="Unique identifier for the agent"
- >
- <Input placeholder="e.g., customer-support-agent" />
- </Form.Item>
+ <FieldGroup className="mb-4">
+ <AgentFormField
+ name="agent_name"
+ label={labelWithHint("Agent Name", "Unique identifier for the agent")}
+ rules={{ required: "Please enter a unique agent name" }}
+ >
+ {({ value, onChange, ref, ...control }) => (
+ <Input
+ {...control}
+ ref={ref}
+ placeholder="e.g., customer-support-agent"
+ value={typeof value === "string" ? value : ""}
+ onChange={onChange}
+ />
+ )}
+ </AgentFormField>
+ </FieldGroup>
)}
- <Collapse defaultActiveKey={["basic"]} style={{ marginBottom: 16 }}>
- {/* Basic Information */}
+ <div className="mb-4 rounded-md border border-border px-4">
{shouldShow(AGENT_FORM_CONFIG.basic.key) && (
- <Panel header={`${AGENT_FORM_CONFIG.basic.title} (Required)`} key={AGENT_FORM_CONFIG.basic.key}>
+ <AgentFormPanel
+ panelKey={AGENT_FORM_CONFIG.basic.key}
+ title={`${AGENT_FORM_CONFIG.basic.title} (Required)`}
+ panels={panels}
+ >
{AGENT_FORM_CONFIG.basic.fields.map((field) => (
- <Form.Item
+ <AgentFormField
key={field.name}
- label={field.label}
name={field.name}
- rules={
- field.required
- ? [{ required: true, message: `Please enter ${field.label.toLowerCase()}` }]
- : undefined
- }
- tooltip={field.tooltip}
- extra={field.helpText}
+ label={field.tooltip ? labelWithHint(field.label, field.tooltip) : field.label}
+ description={field.helpText}
+ rules={field.required ? { required: `Please enter ${field.label.toLowerCase()}` } : undefined}
>
- {field.type === "textarea" ? (
- <Input.TextArea rows={field.rows} placeholder={field.placeholder} />
- ) : field.type === "select" ? (
- <Select placeholder={field.placeholder}>
- {(field.options ?? []).map((opt) => (
- <Select.Option key={opt} value={opt}>
- {opt}
- </Select.Option>
- ))}
- </Select>
- ) : (
- <Input placeholder={field.placeholder} />
- )}
- </Form.Item>
+ {({ value, onChange, ref, ...control }) => {
+ const text = typeof value === "string" ? value : "";
+ if (field.type === "textarea") {
+ return (
+ <Textarea
+ {...control}
+ ref={ref}
+ rows={field.rows}
+ placeholder={field.placeholder}
+ value={text}
+ onChange={onChange}
+ />
+ );
+ }
+ if (field.type === "select") {
+ return (
+ <Select value={text || null} onValueChange={onChange}>
+ <SelectTrigger {...control} className="w-full">
+ <SelectValue placeholder={field.placeholder} />
+ </SelectTrigger>
+ <SelectContent>
+ {(field.options ?? []).map((option) => (
+ <SelectItem key={option} value={option} title={option}>
+ {option}
+ </SelectItem>
+ ))}
+ </SelectContent>
+ </Select>
+ );
+ }
+ return (
+ <Input {...control} ref={ref} placeholder={field.placeholder} value={text} onChange={onChange} />
+ );
+ }}
+ </AgentFormField>
))}
- </Panel>
+ </AgentFormPanel>
)}
- {/* Skills */}
{shouldShow(AGENT_FORM_CONFIG.skills.key) && (
- <Panel header={`${AGENT_FORM_CONFIG.skills.title}`} key={AGENT_FORM_CONFIG.skills.key}>
- <Form.List name="skills">
- {(fields, { add, remove }) => (
- <>
- {fields.map((field) => (
- <div
- key={field.key}
- style={{ marginBottom: 16, padding: 16, border: "1px solid #d9d9d9", borderRadius: 4 }}
- >
- <Form.Item
- {...field}
- label={SKILL_FIELD_CONFIG.id.label}
- name={[field.name, "id"]}
- rules={[{ required: SKILL_FIELD_CONFIG.id.required, message: "Required" }]}
- >
- <Input placeholder={SKILL_FIELD_CONFIG.id.placeholder} />
- </Form.Item>
-
- <Form.Item
- {...field}
- label={SKILL_FIELD_CONFIG.name.label}
- name={[field.name, "name"]}
- rules={[{ required: SKILL_FIELD_CONFIG.name.required, message: "Required" }]}
- >
- <Input placeholder={SKILL_FIELD_CONFIG.name.placeholder} />
- </Form.Item>
-
- <Form.Item
- {...field}
- label={SKILL_FIELD_CONFIG.description.label}
- name={[field.name, "description"]}
- rules={[{ required: SKILL_FIELD_CONFIG.description.required, message: "Required" }]}
- >
- <Input.TextArea
- rows={SKILL_FIELD_CONFIG.description.rows}
- placeholder={SKILL_FIELD_CONFIG.description.placeholder}
- />
- </Form.Item>
-
- <Form.Item
- {...field}
- label={SKILL_FIELD_CONFIG.tags.label}
- name={[field.name, "tags"]}
- rules={[{ required: SKILL_FIELD_CONFIG.tags.required, message: "Required" }]}
- >
- <Select
- mode="tags"
- style={{ width: "100%" }}
- tokenSeparators={[","]}
- placeholder={SKILL_FIELD_CONFIG.tags.placeholder}
- />
- </Form.Item>
-
- <Form.Item {...field} label={SKILL_FIELD_CONFIG.examples.label} name={[field.name, "examples"]}>
- <Select
- mode="tags"
- style={{ width: "100%" }}
- tokenSeparators={[","]}
- placeholder={SKILL_FIELD_CONFIG.examples.placeholder}
- />
- </Form.Item>
-
- <AntButton type="link" danger onClick={() => remove(field.name)} icon={<MinusCircleOutlined />}>
- Remove Skill
- </AntButton>
- </div>
- ))}
- <AntButton type="dashed" onClick={() => add()} icon={<PlusOutlined />} style={{ width: "100%" }}>
- Add Skill
- </AntButton>
- </>
- )}
- </Form.List>
- </Panel>
+ <AgentFormPanel
+ panelKey={AGENT_FORM_CONFIG.skills.key}
+ title={AGENT_FORM_CONFIG.skills.title}
+ panels={panels}
+ >
+ <SkillsFieldArray />
+ </AgentFormPanel>
)}
- {/* Capabilities */}
{shouldShow(AGENT_FORM_CONFIG.capabilities.key) && (
- <Panel header={AGENT_FORM_CONFIG.capabilities.title} key={AGENT_FORM_CONFIG.capabilities.key}>
+ <AgentFormPanel
+ panelKey={AGENT_FORM_CONFIG.capabilities.key}
+ title={AGENT_FORM_CONFIG.capabilities.title}
+ panels={panels}
+ >
{AGENT_FORM_CONFIG.capabilities.fields.map((field) => (
- <Form.Item key={field.name} label={field.label} name={field.name} valuePropName="checked">
- <Switch />
- </Form.Item>
+ <AgentFormField key={field.name} name={field.name} label={field.label}>
+ {({ value, onChange, ref, ...control }) => (
+ <Switch {...control} inputRef={ref} checked={value === true} onCheckedChange={onChange} />
+ )}
+ </AgentFormField>
))}
- </Panel>
+ </AgentFormPanel>
)}
- {/* Optional Settings */}
{shouldShow(AGENT_FORM_CONFIG.optional.key) && (
- <Panel header={AGENT_FORM_CONFIG.optional.title} key={AGENT_FORM_CONFIG.optional.key}>
+ <AgentFormPanel
+ panelKey={AGENT_FORM_CONFIG.optional.key}
+ title={AGENT_FORM_CONFIG.optional.title}
+ panels={panels}
+ >
{AGENT_FORM_CONFIG.optional.fields.map((field) => (
- <Form.Item
- key={field.name}
- label={field.label}
- name={field.name}
- valuePropName={field.type === "switch" ? "checked" : undefined}
- >
- {field.type === "switch" ? <Switch /> : <Input placeholder={field.placeholder} />}
- </Form.Item>
+ <AgentFormField key={field.name} name={field.name} label={field.label}>
+ {({ value, onChange, ref, ...control }) =>
+ field.type === "switch" ? (
+ <Switch {...control} inputRef={ref} checked={value === true} onCheckedChange={onChange} />
+ ) : (
+ <Input
+ {...control}
+ ref={ref}
+ placeholder={field.placeholder}
+ value={typeof value === "string" ? value : ""}
+ onChange={onChange}
+ />
+ )
+ }
+ </AgentFormField>
))}
- </Panel>
+ </AgentFormPanel>
)}
- {/* Cost Configuration */}
{shouldShow(AGENT_FORM_CONFIG.cost.key) && (
- <Panel header={AGENT_FORM_CONFIG.cost.title} key={AGENT_FORM_CONFIG.cost.key}>
+ <AgentFormPanel panelKey={AGENT_FORM_CONFIG.cost.key} title={AGENT_FORM_CONFIG.cost.title} panels={panels}>
<CostConfigFields />
- </Panel>
+ </AgentFormPanel>
)}
- {/* LiteLLM Parameters */}
{shouldShow(AGENT_FORM_CONFIG.litellm.key) && (
- <Panel header={AGENT_FORM_CONFIG.litellm.title} key={AGENT_FORM_CONFIG.litellm.key}>
+ <AgentFormPanel
+ panelKey={AGENT_FORM_CONFIG.litellm.key}
+ title={AGENT_FORM_CONFIG.litellm.title}
+ panels={panels}
+ >
{AGENT_FORM_CONFIG.litellm.fields.map((field) => (
- <Form.Item
- key={field.name}
- label={field.label}
- name={field.name}
- valuePropName={field.type === "switch" ? "checked" : undefined}
- >
- {field.type === "switch" ? <Switch /> : <Input placeholder={field.placeholder} />}
- </Form.Item>
+ <AgentFormField key={field.name} name={field.name} label={field.label}>
+ {({ value, onChange, ref, ...control }) =>
+ field.type === "switch" ? (
+ <Switch {...control} inputRef={ref} checked={value === true} onCheckedChange={onChange} />
+ ) : (
+ <Input
+ {...control}
+ ref={ref}
+ placeholder={field.placeholder}
+ value={typeof value === "string" ? value : ""}
+ onChange={onChange}
+ />
+ )
+ }
+ </AgentFormField>
))}
- </Panel>
+ </AgentFormPanel>
)}
- {/* Authentication Headers */}
- {shouldShow("auth_headers") && (
- <Panel header="Authentication Headers" key="auth_headers">
- {/* Static Headers */}
- <Form.Item
- label={
- <span>
- Static Headers{" "}
- <Tooltip title="Headers always sent to the backend agent, regardless of the client request. Admin-configured, static wins on conflict.">
- <InfoCircleOutlined style={{ color: "#8c8c8c" }} />
- </Tooltip>
- </span>
- }
- >
- <Form.List name="static_headers">
- {(fields, { add, remove }) => (
- <>
- {fields.map(({ key, name, ...restField }) => (
- <Space key={key} style={{ display: "flex", marginBottom: 8 }} align="baseline">
- <Form.Item
- {...restField}
- name={[name, "header"]}
- rules={[{ required: true, message: "Header name required" }]}
- >
- <Input placeholder="Header name (e.g. Authorization)" style={{ width: 220 }} />
- </Form.Item>
- <Form.Item
- {...restField}
- name={[name, "value"]}
- rules={[{ required: true, message: "Value required" }]}
- >
- <Input placeholder="Value (e.g. Bearer token123)" style={{ width: 260 }} />
- </Form.Item>
- <MinusCircleOutlined onClick={() => remove(name)} style={{ color: "#ff4d4f" }} />
- </Space>
- ))}
- <AntButton type="dashed" onClick={() => add()} icon={<PlusOutlined />} style={{ width: "100%" }}>
- Add Static Header
- </AntButton>
- </>
+ {shouldShow(AUTH_HEADERS_PANEL_KEY) && (
+ <AgentFormPanel panelKey={AUTH_HEADERS_PANEL_KEY} title="Authentication Headers" panels={panels}>
+ <Field>
+ <FieldTitle>
+ {labelWithHint(
+ "Static Headers",
+ "Headers always sent to the backend agent, regardless of the client request. Admin-configured, static wins on conflict.",
)}
- </Form.List>
- </Form.Item>
+ </FieldTitle>
+ <div className="flex flex-col gap-2">
+ <StaticHeadersFieldArray />
+ </div>
+ </Field>
- {/* Extra Headers (dynamic forwarding) */}
- <Form.Item
- label={
- <span>
- Forward Client Headers{" "}
- <Tooltip title="Header names to extract from the client's request and forward to the agent. Type a name and press Enter.">
- <InfoCircleOutlined style={{ color: "#8c8c8c" }} />
- </Tooltip>
- </span>
- }
+ <AgentFormField
name="extra_headers"
+ label={labelWithHint(
+ "Forward Client Headers",
+ "Header names to extract from the client's request and forward to the agent. Type a name and press Enter.",
+ )}
>
- <Select
- mode="tags"
- style={{ width: "100%" }}
- placeholder="e.g. x-api-key, Authorization"
- tokenSeparators={[","]}
- />
- </Form.Item>
- </Panel>
+ {({ id, value, onChange }) => (
+ <AgentTagsInput
+ id={id}
+ value={Array.isArray(value) ? (value as string[]) : []}
+ onValueChange={onChange}
+ placeholder="e.g. x-api-key, Authorization"
+ />
+ )}
+ </AgentFormField>
+ </AgentFormPanel>
)}
- </Collapse>
+ </div>
</>
);
};
diff --git a/ui/litellm-dashboard/src/app/(dashboard)/agents/_components/agent_info.integration.test.tsx b/ui/litellm-dashboard/src/app/(dashboard)/agents/_components/agent_info.integration.test.tsx
new file mode 100644
index 00000000000..d0968eacf01
--- /dev/null
+++ b/ui/litellm-dashboard/src/app/(dashboard)/agents/_components/agent_info.integration.test.tsx
@@ -0,0 +1,262 @@
+import React from "react";
+import { render, screen, waitFor } from "@testing-library/react";
+import userEvent, { PointerEventsCheckLevel } from "@testing-library/user-event";
+import { describe, it, expect, vi, beforeEach } from "vitest";
+import AgentInfoView from "./agent_info";
+import * as networking from "@/components/networking";
+import type { AgentCreateInfo } from "@/components/networking";
+
+vi.mock("@/components/networking", () => ({
+ getAgentInfo: vi.fn(),
+ patchAgentCall: vi.fn(),
+ getAgentCreateMetadata: vi.fn(),
+}));
+
+vi.mock("@/app/(dashboard)/hooks/keys/useKeys", () => ({
+ useKeys: () => ({ data: { keys: [] }, isLoading: false, refetch: vi.fn() }),
+}));
+
+vi.mock("./agent_card_discovery", () => ({ default: () => <div data-testid="agent-card-discovery" /> }));
+
+const A2A_AGENT = {
+ agent_id: "agent-1",
+ agent_name: "my-agent",
+ agent_card_params: {
+ protocolVersion: "1.0",
+ name: "My Agent",
+ description: "does things",
+ url: "http://localhost:9999/",
+ version: "2.3.4",
+ defaultInputModes: ["text"],
+ defaultOutputModes: ["text"],
+ capabilities: { streaming: true, pushNotifications: true },
+ skills: [{ id: "chat", name: "Chat", description: "chat skill", tags: ["a"], examples: ["ex1"] }],
+ iconUrl: "https://example.com/icon.png",
+ documentationUrl: "https://example.com/docs",
+ },
+ litellm_params: { model: "gpt-4o", make_public: true, cost_per_query: 0.5 },
+ tpm_limit: 111,
+ rpm_limit: 222,
+ session_tpm_limit: 333,
+ session_rpm_limit: 444,
+ static_headers: { Authorization: "Bearer x" },
+ extra_headers: ["x-api-key"],
+};
+
+const LANGGRAPH_AGENT = {
+ agent_id: "agent-2",
+ agent_name: "lg-agent",
+ agent_card_params: { name: "LG", description: "graph agent", url: "", version: "1.0.0", skills: [] },
+ litellm_params: {
+ custom_llm_provider: "langgraph",
+ model: "langgraph/asst_1",
+ api_base: "https://lg.example.com",
+ cost_per_query: 0.25,
+ },
+};
+
+const langgraphInfo: AgentCreateInfo = {
+ agent_type: "langgraph",
+ agent_type_display_name: "LangGraph",
+ description: "LangGraph platform",
+ logo_url: "/l.png",
+ use_a2a_form_fields: false,
+ litellm_params_template: { custom_llm_provider: "langgraph" },
+ model_template: "langgraph/{assistant_id}",
+ credential_fields: [
+ { key: "api_base", label: "API Base", field_type: "text", required: true },
+ {
+ key: "assistant_id",
+ label: "Assistant ID",
+ field_type: "text",
+ required: false,
+ include_in_litellm_params: false,
+ },
+ ],
+};
+
+const setup = () => userEvent.setup({ pointerEventsCheck: PointerEventsCheckLevel.Never });
+
+const renderView = () => render(<AgentInfoView agentId="agent-1" onClose={vi.fn()} accessToken="tok" isAdmin={true} />);
+
+const openEditor = async (user: ReturnType<typeof setup>) => {
+ await user.click(await screen.findByRole("tab", { name: "Settings" }));
+ await user.click(await screen.findByRole("button", { name: "Edit Settings" }));
+ await screen.findByLabelText("Agent Name");
+};
+
+const patchedPayload = () => vi.mocked(networking.patchAgentCall).mock.calls[0][2] as Record<string, unknown>;
+
+const save = async (user: ReturnType<typeof setup>) => {
+ await user.click(screen.getByRole("button", { name: "Save Changes" }));
+ await waitFor(() => expect(networking.patchAgentCall).toHaveBeenCalledTimes(1));
+};
+
+describe("AgentInfoView update payload", () => {
+ beforeEach(() => {
+ vi.mocked(networking.getAgentCreateMetadata).mockReset().mockResolvedValue([langgraphInfo]);
+ vi.mocked(networking.getAgentInfo)
+ .mockReset()
+ .mockResolvedValue(A2A_AGENT as never);
+ vi.mocked(networking.patchAgentCall)
+ .mockReset()
+ .mockResolvedValue({} as never);
+ });
+
+ it("sends only the fields whose panel has been opened, dropping the rest", async () => {
+ const user = setup();
+ renderView();
+ await openEditor(user);
+
+ await save(user);
+
+ expect(patchedPayload()).toEqual({
+ agent_name: "my-agent",
+ agent_card_params: {
+ protocolVersion: "1.0",
+ name: "My Agent",
+ description: "does things",
+ url: "http://localhost:9999/",
+ version: "2.3.4",
+ defaultInputModes: ["text"],
+ defaultOutputModes: ["text"],
+ capabilities: { streaming: false },
+ skills: [],
+ },
+ tpm_limit: 111,
+ rpm_limit: 222,
+ session_tpm_limit: 333,
+ session_rpm_limit: 444,
+ });
+ });
+
+ it("sends the loaded values of every panel the user opens", async () => {
+ const user = setup();
+ renderView();
+ await openEditor(user);
+
+ await user.click(screen.getByRole("button", { name: /Skills/ }));
+ await user.click(screen.getByRole("button", { name: /Capabilities/ }));
+ await user.click(screen.getByRole("button", { name: /Optional Settings/ }));
+ await user.click(screen.getByRole("button", { name: /Cost Configuration/ }));
+ await user.click(screen.getByRole("button", { name: /LiteLLM Parameters/ }));
+ await user.click(screen.getByRole("button", { name: /Authentication Headers/ }));
+ await screen.findByLabelText("Forward Client Headers");
+
+ await save(user);
+
+ expect(patchedPayload()).toEqual({
+ agent_name: "my-agent",
+ agent_card_params: {
+ protocolVersion: "1.0",
+ name: "My Agent",
+ description: "does things",
+ url: "http://localhost:9999/",
+ version: "2.3.4",
+ defaultInputModes: ["text"],
+ defaultOutputModes: ["text"],
+ capabilities: { streaming: true, pushNotifications: true, stateTransitionHistory: undefined },
+ skills: [{ id: "chat", name: "Chat", description: "chat skill", tags: ["a"], examples: ["ex1"] }],
+ iconUrl: "https://example.com/icon.png",
+ documentationUrl: "https://example.com/docs",
+ },
+ litellm_params: { model: "gpt-4o", make_public: true, cost_per_query: 0.5 },
+ static_headers: { Authorization: "Bearer x" },
+ extra_headers: ["x-api-key"],
+ tpm_limit: 111,
+ rpm_limit: 222,
+ session_tpm_limit: 333,
+ session_rpm_limit: 444,
+ });
+ });
+
+ it("clamps a rate limit typed below its minimum up to that minimum", async () => {
+ const user = setup();
+ renderView();
+ await openEditor(user);
+
+ await user.clear(screen.getByLabelText("TPM Limit"));
+ await user.type(screen.getByLabelText("TPM Limit"), "-5");
+ await save(user);
+
+ expect(patchedPayload().tpm_limit).toBe(0);
+ });
+
+ it("drops a rate limit the user cleared", async () => {
+ const user = setup();
+ renderView();
+ await openEditor(user);
+
+ await user.clear(screen.getByLabelText("RPM Limit"));
+ await save(user);
+
+ expect(patchedPayload()).not.toHaveProperty("rpm_limit");
+ });
+
+ it("submits when Enter is pressed in a text field", async () => {
+ const user = setup();
+ renderView();
+ await openEditor(user);
+
+ await user.type(screen.getByLabelText("Agent Name"), "{Enter}");
+
+ await waitFor(() => expect(networking.patchAgentCall).toHaveBeenCalledTimes(1));
+ });
+
+ it("blocks the save while a required field is empty", async () => {
+ const user = setup();
+ renderView();
+ await openEditor(user);
+
+ await user.clear(screen.getByLabelText("Agent Name"));
+ await user.click(screen.getByRole("button", { name: "Save Changes" }));
+
+ expect(await screen.findByText("Please enter a unique agent name")).toBeInTheDocument();
+ expect(networking.patchAgentCall).not.toHaveBeenCalled();
+ });
+
+ it("sends credential fields and the rebuilt model for a dynamic agent type", async () => {
+ vi.mocked(networking.getAgentInfo).mockResolvedValue(LANGGRAPH_AGENT as never);
+ const user = setup();
+ renderView();
+ await openEditor(user);
+
+ await user.clear(screen.getByLabelText("API Base"));
+ await user.type(screen.getByLabelText("API Base"), "https://other.example.com");
+
+ await save(user);
+
+ expect(patchedPayload()).toEqual({
+ agent_name: "lg-agent",
+ agent_card_params: {
+ protocolVersion: "1.0",
+ name: "lg-agent",
+ description: "graph agent",
+ url: "https://other.example.com",
+ version: "1.0.0",
+ defaultInputModes: ["text"],
+ defaultOutputModes: ["text"],
+ capabilities: { streaming: true },
+ skills: [{ id: "chat", name: "Chat", description: "General chat capability", tags: ["chat", "conversation"] }],
+ },
+ litellm_params: {
+ custom_llm_provider: "langgraph",
+ api_base: "https://other.example.com",
+ model: "langgraph/asst_1",
+ },
+ });
+ });
+
+ it("reloads the agent and leaves edit mode when the edit is cancelled", async () => {
+ const user = setup();
+ renderView();
+ await openEditor(user);
+ expect(networking.getAgentInfo).toHaveBeenCalledTimes(1);
+
+ await user.click(screen.getByRole("button", { name: "Cancel" }));
+
+ expect(await screen.findByRole("button", { name: "Edit Settings" })).toBeInTheDocument();
+ expect(networking.getAgentInfo).toHaveBeenCalledTimes(2);
+ expect(networking.patchAgentCall).not.toHaveBeenCalled();
+ });
+});
diff --git a/ui/litellm-dashboard/src/app/(dashboard)/agents/_components/agent_info.tsx b/ui/litellm-dashboard/src/app/(dashboard)/agents/_components/agent_info.tsx
index f97a370a96a..88b4c3238fc 100644
--- a/ui/litellm-dashboard/src/app/(dashboard)/agents/_components/agent_info.tsx
+++ b/ui/litellm-dashboard/src/app/(dashboard)/agents/_components/agent_info.tsx
@@ -1,6 +1,13 @@
import React, { useState, useEffect, useMemo } from "react";
import { Card, Title, Text, Button as TremorButton, Tab, TabGroup, TabList, TabPanel, TabPanels } from "@tremor/react";
-import { Form, Input, InputNumber, Button as AntButton, Spin, Descriptions, Divider } from "antd";
+import { Spin, Descriptions } from "antd";
+import { FormProvider, useForm, useWatch } from "react-hook-form";
+import { Button } from "@/components/ui/button";
+import { Input } from "@/components/ui/input";
+import { Separator } from "@/components/ui/separator";
+import { TooltipProvider } from "@/components/ui/tooltip";
+import { UiLoadingSpinner } from "@/components/ui/ui-loading-spinner";
+import { Field, FieldGroup, FieldLabel } from "@/components/shared/form/field";
import { toast } from "@/lib/toast";
import { ArrowLeftIcon } from "@heroicons/react/outline";
import { getAgentInfo, patchAgentCall, getAgentCreateMetadata, AgentCreateInfo } from "@/components/networking";
@@ -9,9 +16,17 @@ import { KeyResponse } from "@/components/key_team_helpers/key_list";
import { useKeys } from "@/app/(dashboard)/hooks/keys/useKeys";
import KeyInfoView from "@/components/templates/key_info_view";
import AgentVirtualKeys from "./agent_virtual_keys";
-import AgentFormFields from "./agent_form_fields";
-import DynamicAgentFormFields, { buildDynamicAgentData } from "./dynamic_agent_form_fields";
-import { buildAgentDataFromForm, parseAgentForForm } from "./agent_config";
+import AgentFormFields, { unmountedA2AFieldNames } from "./agent_form_fields";
+import DynamicAgentFormFields, { buildDynamicAgentData, unmountedDynamicFieldNames } from "./dynamic_agent_form_fields";
+import { AGENT_FORM_CONFIG, buildAgentDataFromForm, parseAgentForForm } from "./agent_config";
+import {
+ AgentFormField,
+ AgentFormValues,
+ AgentNumberInput,
+ AgentRequestPayload,
+ omitFieldValues,
+ useCollapsiblePanels,
+} from "./AgentFormKit";
import AgentCostView from "./agent_cost_view";
import { detectAgentType, parseDynamicAgentForForm } from "./agent_type_utils";
import AgentCardDiscovery, { DiscoveredAgentCardSelection } from "./agent_card_discovery";
@@ -32,7 +47,8 @@ const AgentInfoView: React.FC<AgentInfoViewProps> = ({ agentId, onClose, accessT
const [isLoading, setIsLoading] = useState(true);
const [isEditing, setIsEditing] = useState(false);
const [isSaving, setIsSaving] = useState(false);
- const [form] = Form.useForm();
+ const form = useForm<AgentFormValues>({ defaultValues: {} });
+ const panels = useCollapsiblePanels([AGENT_FORM_CONFIG.basic.key]);
const [agentTypeMetadata, setAgentTypeMetadata] = useState<AgentCreateInfo[]>([]);
const [detectedAgentType, setDetectedAgentType] = useState<string>("a2a");
const [appliedDiscoveredSelection, setAppliedDiscoveredSelection] = useState<DiscoveredAgentCardSelection | null>(
@@ -69,13 +85,13 @@ const AgentInfoView: React.FC<AgentInfoViewProps> = ({ agentId, onClose, accessT
// Parse form values based on agent type
if (agentType === "a2a") {
- form.setFieldsValue(parseAgentForForm(data));
+ form.reset(parseAgentForForm(data));
} else {
const typeInfo = agentTypeMetadata.find((t) => t.agent_type === agentType);
if (typeInfo) {
- form.setFieldsValue(parseDynamicAgentForForm(data, typeInfo));
+ form.reset(parseDynamicAgentForForm(data, typeInfo));
} else {
- form.setFieldsValue(parseAgentForForm(data));
+ form.reset(parseAgentForForm(data));
}
}
} catch (error) {
@@ -93,14 +109,14 @@ const AgentInfoView: React.FC<AgentInfoViewProps> = ({ agentId, onClose, accessT
if (agentType !== "a2a") {
const typeInfo = agentTypeMetadata.find((t) => t.agent_type === agentType);
if (typeInfo) {
- form.setFieldsValue(parseDynamicAgentForForm(agent, typeInfo));
+ form.reset(parseDynamicAgentForForm(agent, typeInfo));
}
}
}
}, [agentTypeMetadata, agent]);
const selectedAgentTypeInfo = agentTypeMetadata.find((t) => t.agent_type === detectedAgentType);
- const watchedFormValues = Form.useWatch([], form);
+ const watchedFormValues = useWatch({ control: form.control });
const discoveryRequest = useMemo(
() => buildDiscoveryRequest(detectedAgentType, watchedFormValues || {}, selectedAgentTypeInfo),
@@ -119,7 +135,11 @@ const AgentInfoView: React.FC<AgentInfoViewProps> = ({ agentId, onClose, accessT
examples: s.examples ?? [],
}));
- const fieldsToSet: Record<string, any> = {
+ const urlCredentialKeys = (selectedAgentTypeInfo?.credential_fields ?? [])
+ .map((f) => f.key)
+ .filter((key) => /(^|_)(url|api_base|endpoint)$/i.test(key));
+
+ const fieldsToSet: AgentFormValues = {
name: selected_card.name,
description: selected_card.description,
url: selection.upstream_url,
@@ -127,37 +147,35 @@ const AgentInfoView: React.FC<AgentInfoViewProps> = ({ agentId, onClose, accessT
skills,
iconUrl: selected_card.iconUrl,
documentationUrl: selected_card.documentationUrl,
+ ...Object.fromEntries(urlCredentialKeys.map((key) => [key, selection.upstream_url])),
};
- const urlCredentialKeys = (selectedAgentTypeInfo?.credential_fields ?? [])
- .map((f) => f.key)
- .filter((key) => /(^|_)(url|api_base|endpoint)$/i.test(key));
- for (const key of urlCredentialKeys) {
- fieldsToSet[key] = selection.upstream_url;
+ for (const [key, value] of Object.entries(fieldsToSet)) {
+ form.setValue(key, value);
}
-
- form.setFieldsValue(fieldsToSet);
};
- const handleUpdate = async (values: any) => {
+ const usesDynamicFields = detectedAgentType !== "a2a" && selectedAgentTypeInfo !== undefined;
+
+ const handleUpdate = async (submitted: AgentFormValues) => {
if (!accessToken || !agent) return;
setIsSaving(true);
try {
- let updateData: any;
+ const values = omitFieldValues(
+ submitted,
+ usesDynamicFields
+ ? unmountedDynamicFieldNames(panels.mountedPanels)
+ : unmountedA2AFieldNames(panels.mountedPanels),
+ );
- if (detectedAgentType === "a2a") {
- updateData = buildAgentDataFromForm(values, agent);
- } else if (selectedAgentTypeInfo) {
- updateData = buildDynamicAgentData(values, selectedAgentTypeInfo);
- updateData.agent_name = values.agent_name;
- } else {
- updateData = buildAgentDataFromForm(values, agent);
- }
+ const built: AgentRequestPayload = usesDynamicFields
+ ? { ...buildDynamicAgentData(values, selectedAgentTypeInfo), agent_name: values.agent_name }
+ : buildAgentDataFromForm(values, agent);
- if (appliedDiscoveredSelection) {
- updateData = overlayDiscoveredCardParams(updateData, appliedDiscoveredSelection.selected_card);
- }
+ const updateData = appliedDiscoveredSelection
+ ? overlayDiscoveredCardParams(built, appliedDiscoveredSelection.selected_card)
+ : built;
await patchAgentCall(accessToken, agentId, updateData);
toast.success("Agent updated successfully");
@@ -199,6 +217,21 @@ const AgentInfoView: React.FC<AgentInfoViewProps> = ({ agentId, onClose, accessT
return date.toLocaleString();
};
+ const rateLimitField = (name: keyof AgentFormValues & string, label: string) => (
+ <AgentFormField name={name} label={label}>
+ {({ value, onChange, ref, ...control }) => (
+ <AgentNumberInput
+ {...control}
+ value={value}
+ onChange={onChange}
+ inputRef={ref}
+ min={0}
+ placeholder="Unlimited"
+ />
+ )}
+ </AgentFormField>
+ );
+
if (selectedKey) {
return (
<KeyInfoView
@@ -369,62 +402,64 @@ const AgentInfoView: React.FC<AgentInfoViewProps> = ({ agentId, onClose, accessT
</div>
{isEditing ? (
- <Form form={form} layout="vertical" onFinish={handleUpdate}>
- <Form.Item label="Agent ID">
- <Input value={agent.agent_id} disabled />
- </Form.Item>
-
- {detectedAgentType === "a2a" ? (
- <AgentFormFields showAgentName={true} />
- ) : selectedAgentTypeInfo ? (
- <DynamicAgentFormFields agentTypeInfo={selectedAgentTypeInfo} />
- ) : (
- <AgentFormFields showAgentName={true} />
- )}
+ <TooltipProvider>
+ <FormProvider {...form}>
+ <form onSubmit={form.handleSubmit(handleUpdate)}>
+ <FieldGroup className="mb-4">
+ <Field>
+ <FieldLabel htmlFor="agent-id">Agent ID</FieldLabel>
+ <Input id="agent-id" value={agent.agent_id} disabled readOnly />
+ </Field>
+ </FieldGroup>
+
+ {usesDynamicFields && selectedAgentTypeInfo ? (
+ <DynamicAgentFormFields agentTypeInfo={selectedAgentTypeInfo} panels={panels} />
+ ) : (
+ <AgentFormFields showAgentName={true} panels={panels} />
+ )}
- {discoveryRequest && (
- <div className="mt-4">
- <AgentCardDiscovery
- accessToken={accessToken}
- onApply={handleApplyDiscoveredCard}
- discoveryRequest={discoveryRequest}
- savedAgentCard={agent.agent_card_params ?? null}
- />
- </div>
- )}
+ {discoveryRequest && (
+ <div className="mt-4">
+ <AgentCardDiscovery
+ accessToken={accessToken}
+ onApply={handleApplyDiscoveredCard}
+ discoveryRequest={discoveryRequest}
+ savedAgentCard={agent.agent_card_params ?? null}
+ />
+ </div>
+ )}
+
+ <Separator className="my-6" />
+ <Title className="mb-4">Rate Limits</Title>
+ <div className="grid grid-cols-2 gap-4">
+ {rateLimitField("tpm_limit", "TPM Limit")}
+ {rateLimitField("rpm_limit", "RPM Limit")}
+ </div>
+ <div className="mt-4 grid grid-cols-2 gap-4">
+ {rateLimitField("session_tpm_limit", "Session TPM Limit")}
+ {rateLimitField("session_rpm_limit", "Session RPM Limit")}
+ </div>
- <Divider />
- <Title className="mb-4">Rate Limits</Title>
- <div className="grid grid-cols-2 gap-4">
- <Form.Item label="TPM Limit" name="tpm_limit">
- <InputNumber className="w-full" min={0} placeholder="Unlimited" />
- </Form.Item>
- <Form.Item label="RPM Limit" name="rpm_limit">
- <InputNumber className="w-full" min={0} placeholder="Unlimited" />
- </Form.Item>
- </div>
- <div className="grid grid-cols-2 gap-4">
- <Form.Item label="Session TPM Limit" name="session_tpm_limit">
- <InputNumber className="w-full" min={0} placeholder="Unlimited" />
- </Form.Item>
- <Form.Item label="Session RPM Limit" name="session_rpm_limit">
- <InputNumber className="w-full" min={0} placeholder="Unlimited" />
- </Form.Item>
- </div>
-
- <div className="flex justify-end gap-2 mt-6">
- <AntButton
- onClick={() => {
- setAppliedDiscoveredSelection(null);
- setIsEditing(false);
- fetchAgentInfo();
- }}
- >
- Cancel
- </AntButton>
- <TremorButton loading={isSaving}>Save Changes</TremorButton>
- </div>
- </Form>
+ <div className="mt-6 flex justify-end gap-2">
+ <Button
+ type="button"
+ variant="outline"
+ onClick={() => {
+ setAppliedDiscoveredSelection(null);
+ setIsEditing(false);
+ fetchAgentInfo();
+ }}
+ >
+ Cancel
+ </Button>
+ <Button type="submit" disabled={isSaving}>
+ {isSaving && <UiLoadingSpinner />}
+ Save Changes
+ </Button>
+ </div>
+ </form>
+ </FormProvider>
+ </TooltipProvider>
) : (
<Text>Click &quot;Edit Settings&quot; to modify agent configuration.</Text>
)}
diff --git a/ui/litellm-dashboard/src/app/(dashboard)/agents/_components/cost_config_fields.tsx b/ui/litellm-dashboard/src/app/(dashboard)/agents/_components/cost_config_fields.tsx
index 6f31aac6530..192a23ba578 100644
--- a/ui/litellm-dashboard/src/app/(dashboard)/agents/_components/cost_config_fields.tsx
+++ b/ui/litellm-dashboard/src/app/(dashboard)/agents/_components/cost_config_fields.tsx
@@ -1,17 +1,32 @@
import React from "react";
-import { Form, Input } from "antd";
+import { Input } from "@/components/ui/input";
import { AGENT_FORM_CONFIG } from "./agent_config";
+import { AgentFormField, labelWithHint } from "./AgentFormKit";
-const CostConfigFields: React.FC = () => {
- return (
- <>
- {AGENT_FORM_CONFIG.cost.fields.map((field) => (
- <Form.Item key={field.name} label={field.label} name={field.name} tooltip={field.tooltip}>
- <Input placeholder={field.placeholder} type="number" step="0.000001" />
- </Form.Item>
- ))}
- </>
- );
-};
+export const COST_FIELD_NAMES: readonly string[] = AGENT_FORM_CONFIG.cost.fields.map((field) => field.name);
+
+const CostConfigFields: React.FC = () => (
+ <>
+ {AGENT_FORM_CONFIG.cost.fields.map((field) => (
+ <AgentFormField
+ key={field.name}
+ name={field.name}
+ label={field.tooltip ? labelWithHint(field.label, field.tooltip) : field.label}
+ >
+ {({ value, onChange, ref, ...control }) => (
+ <Input
+ {...control}
+ ref={ref}
+ type="number"
+ step="0.000001"
+ placeholder={field.placeholder}
+ value={typeof value === "string" || typeof value === "number" ? value : ""}
+ onChange={onChange}
+ />
+ )}
+ </AgentFormField>
+ ))}
+ </>
+);
export default CostConfigFields;
diff --git a/ui/litellm-dashboard/src/app/(dashboard)/agents/_components/dynamic_agent_form_fields.tsx b/ui/litellm-dashboard/src/app/(dashboard)/agents/_components/dynamic_agent_form_fields.tsx
index 435e628bfc0..85d066f4233 100644
--- a/ui/litellm-dashboard/src/app/(dashboard)/agents/_components/dynamic_agent_form_fields.tsx
+++ b/ui/litellm-dashboard/src/app/(dashboard)/agents/_components/dynamic_agent_form_fields.tsx
@@ -1,83 +1,135 @@
import React from "react";
-import { Form, Input, Select, Collapse } from "antd";
+import { Input } from "@/components/ui/input";
+import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select";
+import { Textarea } from "@/components/ui/textarea";
+import { FieldGroup } from "@/components/shared/form/field";
import { AgentCreateInfo, AgentCredentialFieldMetadata } from "@/components/networking";
+import { PasswordInput } from "@/components/shared/PasswordInput";
import { AGENT_FORM_CONFIG } from "./agent_config";
-import CostConfigFields from "./cost_config_fields";
-
-const { Panel } = Collapse;
+import CostConfigFields, { COST_FIELD_NAMES } from "./cost_config_fields";
+import {
+ AgentFormField,
+ AgentFormPanel,
+ AgentRequestPayload,
+ AgentFormValues,
+ CollapsiblePanelsState,
+ labelWithHint,
+} from "./AgentFormKit";
interface DynamicAgentFormFieldsProps {
agentTypeInfo: AgentCreateInfo;
+ panels: CollapsiblePanelsState;
}
-/**
- * Form fields for dynamic agent types (e.g., LangGraph).
- * Renders common fields (agent name, display name, description) plus
- * credential fields defined by the agent type metadata.
- */
-const DynamicAgentFormFields: React.FC<DynamicAgentFormFieldsProps> = ({ agentTypeInfo }) => {
- return (
- <>
- <Form.Item
- label="Agent Name"
+export const unmountedDynamicFieldNames = (mountedPanels: readonly string[]): readonly string[] =>
+ mountedPanels.includes(AGENT_FORM_CONFIG.cost.key) ? [] : COST_FIELD_NAMES;
+
+const CredentialField = ({ field }: { field: AgentCredentialFieldMetadata }) => (
+ <AgentFormField
+ name={field.key}
+ label={field.tooltip ? labelWithHint(field.label, field.tooltip) : field.label}
+ defaultValue={field.default_value ?? undefined}
+ rules={field.required ? { required: `Please enter ${field.label}` } : undefined}
+ >
+ {({ value, onChange, ref, ...control }) => {
+ const text = typeof value === "string" ? value : "";
+ if (field.field_type === "password") {
+ return (
+ <PasswordInput
+ {...control}
+ value={typeof value === "string" ? value : ""}
+ onChange={onChange}
+ ref={ref}
+ placeholder={field.placeholder || ""}
+ />
+ );
+ }
+ if (field.field_type === "textarea") {
+ return (
+ <Textarea
+ {...control}
+ ref={ref}
+ rows={3}
+ placeholder={field.placeholder || ""}
+ value={text}
+ onChange={onChange}
+ />
+ );
+ }
+ if (field.field_type === "select" && field.options) {
+ return (
+ <Select value={text || null} onValueChange={onChange}>
+ <SelectTrigger {...control} className="w-full">
+ <SelectValue placeholder={field.placeholder || ""} />
+ </SelectTrigger>
+ <SelectContent>
+ {field.options.map((option) => (
+ <SelectItem key={option} value={option} title={option}>
+ {option}
+ </SelectItem>
+ ))}
+ </SelectContent>
+ </Select>
+ );
+ }
+ return <Input {...control} ref={ref} placeholder={field.placeholder || ""} value={text} onChange={onChange} />;
+ }}
+ </AgentFormField>
+);
+
+const DynamicAgentFormFields: React.FC<DynamicAgentFormFieldsProps> = ({ agentTypeInfo, panels }) => (
+ <>
+ <FieldGroup className="mb-4">
+ <AgentFormField
name="agent_name"
- rules={[{ required: true, message: "Please enter a unique agent name" }]}
- tooltip="Unique identifier for the agent"
+ label={labelWithHint("Agent Name", "Unique identifier for the agent")}
+ rules={{ required: "Please enter a unique agent name" }}
>
- <Input placeholder="e.g., my-langgraph-agent" />
- </Form.Item>
+ {({ value, onChange, ref, ...control }) => (
+ <Input
+ {...control}
+ ref={ref}
+ placeholder="e.g., my-langgraph-agent"
+ value={typeof value === "string" ? value : ""}
+ onChange={onChange}
+ />
+ )}
+ </AgentFormField>
- <Form.Item label="Description" name="description" tooltip="Brief description of what this agent does">
- <Input.TextArea rows={2} placeholder="Describe what this agent does..." />
- </Form.Item>
+ <AgentFormField
+ name="description"
+ label={labelWithHint("Description", "Brief description of what this agent does")}
+ >
+ {({ value, onChange, ref, ...control }) => (
+ <Textarea
+ {...control}
+ ref={ref}
+ rows={2}
+ placeholder="Describe what this agent does..."
+ value={typeof value === "string" ? value : ""}
+ onChange={onChange}
+ />
+ )}
+ </AgentFormField>
- {agentTypeInfo.credential_fields.map((field: AgentCredentialFieldMetadata) => (
- <Form.Item
- key={field.key}
- label={field.label}
- name={field.key}
- rules={field.required ? [{ required: true, message: `Please enter ${field.label}` }] : undefined}
- tooltip={field.tooltip}
- initialValue={field.default_value}
- >
- {field.field_type === "password" ? (
- <Input.Password placeholder={field.placeholder || ""} />
- ) : field.field_type === "textarea" ? (
- <Input.TextArea rows={3} placeholder={field.placeholder || ""} />
- ) : field.field_type === "select" && field.options ? (
- <Select placeholder={field.placeholder || ""}>
- {field.options.map((opt) => (
- <Select.Option key={opt} value={opt}>
- {opt}
- </Select.Option>
- ))}
- </Select>
- ) : (
- <Input placeholder={field.placeholder || ""} />
- )}
- </Form.Item>
+ {agentTypeInfo.credential_fields.map((field) => (
+ <CredentialField key={field.key} field={field} />
))}
+ </FieldGroup>
- <Collapse style={{ marginBottom: 16 }}>
- <Panel header={AGENT_FORM_CONFIG.cost.title} key={AGENT_FORM_CONFIG.cost.key}>
- <CostConfigFields />
- </Panel>
- </Collapse>
- </>
- );
-};
+ <div className="mb-4 rounded-md border border-border px-4">
+ <AgentFormPanel panelKey={AGENT_FORM_CONFIG.cost.key} title={AGENT_FORM_CONFIG.cost.title} panels={panels}>
+ <CostConfigFields />
+ </AgentFormPanel>
+ </div>
+ </>
+);
-/**
- * Builds agent data from form values for dynamic agent types.
- * Uses configuration from agentTypeInfo to determine which fields to include.
- */
-export const buildDynamicAgentData = (values: any, agentTypeInfo: AgentCreateInfo) => {
- // Build litellm_params from template
- const litellmParams: Record<string, any> = {
+export const buildDynamicAgentData = (values: AgentFormValues, agentTypeInfo: AgentCreateInfo): AgentRequestPayload => {
+ const litellmParams: Record<string, unknown> = {
...(agentTypeInfo.litellm_params_template || {}),
};
- // Add credential fields marked with include_in_litellm_params
for (const field of agentTypeInfo.credential_fields) {
const value = values[field.key];
if (value && field.include_in_litellm_params !== false) {
@@ -85,31 +137,25 @@ export const buildDynamicAgentData = (values: any, agentTypeInfo: AgentCreateInf
}
}
- // Add cost configuration
if (values.cost_per_query) {
- litellmParams.cost_per_query = parseFloat(values.cost_per_query);
+ litellmParams.cost_per_query = parseFloat(String(values.cost_per_query));
}
if (values.input_cost_per_token) {
- litellmParams.input_cost_per_token = parseFloat(values.input_cost_per_token);
+ litellmParams.input_cost_per_token = parseFloat(String(values.input_cost_per_token));
}
if (values.output_cost_per_token) {
- litellmParams.output_cost_per_token = parseFloat(values.output_cost_per_token);
+ litellmParams.output_cost_per_token = parseFloat(String(values.output_cost_per_token));
}
- // Apply model_template if defined (e.g., "bedrock/agentcore/{agent_runtime_arn}")
if (agentTypeInfo.model_template) {
- let model = agentTypeInfo.model_template;
- // Replace {field_key} placeholders with actual values
- for (const field of agentTypeInfo.credential_fields) {
+ litellmParams.model = agentTypeInfo.credential_fields.reduce((model, field) => {
const placeholder = `{${field.key}}`;
- if (model.includes(placeholder) && values[field.key]) {
- model = model.replace(placeholder, values[field.key]);
- }
- }
- litellmParams.model = model;
+ const value = values[field.key];
+ return model.includes(placeholder) && value ? model.replace(placeholder, String(value)) : model;
+ }, agentTypeInfo.model_template);
}
- const agentData: Record<string, any> = {
+ const agentData: AgentRequestPayload = {
agent_name: values.agent_name,
agent_card_params: {
protocolVersion: "1.0",