# Agent Settings

> Edit an agent's name, instructions, tools and model.

Page: https://uicontext.com/docs/components/agent-settings

Group: Agents.

## When to use

Edit an agent's name, instructions, tools and model. Use [New Agent](https://uicontext.com/docs/components/new-agent.md) instead when the agent doesn't exist yet.

## Usage

```ts
import { AgentEditor } from "./ui/uicontext/components/AgentEditor.ts"

const Message = UiSchema.TaggedEnum({
	SavedAgent: { name: Schema.optional(Schema.String), instructions: Schema.optional(Schema.String) },
	ChoseAgentModel: { model: Schema.String },
})

// your app owns the agent's settings; the editor asks for each change
export const SupportBotSettings = (h: Html.H<typeof Message.Type>, agent: { readonly instructions: string; readonly model: string }) =>
	AgentEditor(h, {
		props: {
			id: "support-bot",
			name: "Support bot",
			instructions: { value: agent.instructions },
			model: { value: agent.model, options: [{ value: "fast", label: "Fast" }, { value: "balanced", label: "Balanced" }] },
			can: ["edit"],
		},
		onEmit: (e) =>
			e._tag === "RequestedSave" ? Message.SavedAgent({ name: e.name, instructions: e.instructions })
			: e._tag === "RequestedModel" ? Message.ChoseAgentModel({ model: e.model })
			: undefined,
	})
```

## Examples

Each example is a complete file. Its imports point where the CLI installs the source.

### A team's support bot

Instructions with fields to insert, a model with its cost, tools an admin has turned off, and a change waiting to publish. Save keeps a draft; Publish ships it.

```ts title="src/support-bot.ts" source="www/src/examples/agent-settings/support-bot.ts"
import { UiSchema } from "effect/ui"
import { Html } from "effect/ui/html"
import { Schema } from "effect"
import { AgentEditor } from "./ui/uicontext/components/AgentEditor.ts"

const Message = UiSchema.TaggedEnum({
	Saved: { name: Schema.optional(Schema.String), description: Schema.optional(Schema.String), instructions: Schema.optional(Schema.String) },
	ChoseModel: { model: Schema.String },
	ToggledTool: { tool: Schema.String, on: Schema.Boolean },
	Published: {},
})

const Model = Schema.Struct({
	name: Schema.String,
	description: Schema.String,
	instructions: Schema.String,
	model: Schema.String,
	tools: Schema.Array(Schema.String),
	version: Schema.Number,
	changed: Schema.Boolean,
})

export const SupportBot = Html.component({ name: "SupportBot", model: Model, message: Message }).make({
	init: () => ({
		name: "Support bot",
		description: "Answers billing questions in #help and hands off to a person when unsure",
		instructions:
			"Answer billing questions for {Customer} using the help center. Quote the article you used.\nIf a refund is over $200, hand off to the on-call person in #billing; don't promise anything.",
		model: "balanced",
		tools: ["search", "lookup"],
		version: 6,
		changed: false,
	}),
	update: {
		Saved: ($, s) =>
			$.evolve({
				name: s.name ?? $.model.name,
				description: s.description ?? $.model.description,
				instructions: s.instructions ?? $.model.instructions,
				changed: true,
			}),
		ChoseModel: ($, { model }) => $.evolve({ model, changed: true }),
		ToggledTool: ($, { tool, on }) => $.evolve({ tools: (t) => (on ? [...t, tool] : t.filter((x) => x !== tool)), changed: true }),
		Published: ($) => $.evolve({ changed: false, version: (v) => v + 1 }),
	},
	view: (h, model) =>
		AgentEditor(h, {
			props: {
				id: "support-bot",
				agentId: "agent-editor-support-bot",
				name: model.name,
				description: model.description,
				picture: { emoji: "🛟" },
				instructions: {
					value: model.instructions,
					hint: "Say what it should do in plain words. Insert a field to use the customer's data.",
					maxLength: 4000,
					tokens: [
						{ insert: "{Customer}", label: "Customer" },
						{ insert: "{Plan}", label: "Plan" },
						{ insert: "{Last invoice}", label: "Last invoice" },
					],
				},
				model: {
					value: model.model,
					hint: "Smarter models answer harder questions and cost more per reply.",
					options: [
						{ value: "fast", label: "Fast", note: "1x", description: "Short, factual answers." },
						{ value: "balanced", label: "Balanced", note: "3x", description: "Reads several articles before it answers." },
						{ value: "deep", label: "Deep reasoning", note: "8x", disabled: "Your plan doesn't include it" },
					],
				},
				tools: {
					hint: "What it may do while it answers.",
					items: [
						{ id: "search", label: "Search the help center", on: model.tools.includes("search") },
						{ id: "lookup", label: "Look up a customer's invoices", description: "Read-only.", on: model.tools.includes("lookup") },
						{ id: "refund", label: "Issue refunds", on: false, disabled: "Your admin keeps refunds with people." },
					],
				},
				version: model.changed
					? { state: "changed", label: `v${model.version}`, note: "Replies in progress keep the version they started with." }
					: { state: "published", label: `v${model.version}` },
				can: ["edit", "publish"],
			},
			onEmit: {
				RequestedSave: (s) => Message.Saved(s),
				RequestedModel: ({ model }) => Message.ChoseModel({ model }),
				RequestedTool: ({ tool, on }) => Message.ToggledTool({ tool, on }),
				RequestedChoice: () => undefined,
				RequestedAddKnowledge: () => undefined,
				RequestedRemoveKnowledge: () => undefined,
				RequestedPublish: () => Message.Published(),
				RequestedEdit: () => undefined,
				RequestedDelete: () => undefined,
			},
		}),
})
```

## API reference

### AgentCard (component)

**Props**

| Name | Type | Description |
| --- | --- | --- |
| `id` (required) | `string` | Identifies the agent in the events the card sends |
| `name` (required) | `string` | The agent's name, as the card's heading |
| `description` | `string` | One line: what it does |
| `picture` | `AgentPicture` | An image or an emoji; a colored initial when left out |
| `status` | `{ tone, label }` | "Active", "Draft", "Paused", "Working", "Needs you" |
| `owner` | `string` | "Ada Lovelace", "Shared with Design" |
| `facts` | `string[]` | Short facts, in order: "3 tools", "Last run 2 hr ago" |
| `href` | `string` | Its page; the name links there |
| `primary` | `{ on, label, disabled }` | A "primary agent" star. `disabled` says why it can't be primary |
| `access` | `"request" \| "requested"` | This person can't use it yet: offer to ask, or say it's asked |
| `outcome` | `Outcome \| null` | The app's answer to the request in flight; its request is the action's id |
| `agentId` | `string` | This card's id for agents; defaults to agent-card:\<id> |

**Events**

| Event | Payload | Description |
| --- | --- | --- |
| `RequestedPrimary` | `{ id: string; on: boolean }` | The person starred the agent as primary (`on`) or took the star back |
| `RequestedAccess` | `{ id: string }` | The person asked for access to the agent |

**Agent actions**

| Action | Description |
| --- | --- |
| `ClickedPrimary` | Make it the primary agent, or stop |
| `ClickedRequestAccess` | Ask its owner for access |

### AgentEditor (component)

**Props**

| Name | Type | Description |
| --- | --- | --- |
| `id` (required) | `string` | Identifies the agent in the events the editor sends |
| `name` (required) | `string` | The agent's name, as the first field |
| `description` | `string` | Leave out to hide the field |
| `picture` | `AgentPicture` | An image or an emoji; a colored initial when left out |
| `instructions` (required) | `{ value, label, hint, … }` | What the agent is told to do: the text, its label and hint, and tokens to insert |
| `model` | `{ value, label, hint, … }` | The model it runs on, picked from `options`; leave out to hide the field |
| `choices` | `AgentChoice[]` | More settings, each one of a few options: "Reply in" with Thread or Channel |
| `tools` | `{ label, hint, items }` | The tools it may use, each switched on or off |
| `knowledge` | `{ label, hint, items, … }` | The pages, files and sources it reads from |
| `version` | `AgentVersion` | Draft, published, changed or locked, with a label and a note |
| `can` (required) | `AgentEditorAction[]` | What this person may do; anything absent is hidden or read-only |
| `readOnly` | `Notice` | Why the form is read-only: "You need Can edit to change this agent", with a link to ask |
| `outcome` | `Outcome \| null` | The app's answer to the request in flight; its request is the action's id |
| `deletion` | `{ consequences, confirmName, label }` | What deleting removes, and whether the person types the name to confirm |
| `agentId` | `string` | This editor's id for agents; defaults to agent-editor:\<id> |

**Events**

| Event | Payload | Description |
| --- | --- | --- |
| `RequestedSave` | `{ id: string; name?: string; description?: string; instructions?: string }` | Save: the text fields as the person left them; a field left out didn't change |
| `RequestedModel` | `{ id: string; model: string }` | The person picked another model |
| `RequestedTool` | `{ id: string; tool: string; on: boolean }` | The person switched a tool on or off |
| `RequestedChoice` | `{ id: string; choice: string; value: string }` | The person picked an option for one of `choices` |
| `RequestedAddKnowledge` | `{ id: string }` | Open the app's own picker for a page, file or source |
| `RequestedRemoveKnowledge` | `{ id: string; source: string }` | The person removed a source from knowledge |
| `RequestedPublish` | `{ id: string }` | The person published the draft |
| `RequestedEdit` | `{ id: string }` | The live version is locked: open a draft of it |
| `RequestedDelete` | `{ id: string }` | The person confirmed deleting the agent |

**Agent actions**

| Action | Description |
| --- | --- |
| `UpdatedName` | Type the agent's name (saved with SubmittedSave) |
| `UpdatedDescription` | Type the agent's description (saved with SubmittedSave) |
| `UpdatedInstructions` | Replace the instructions text (saved with SubmittedSave) |
| `ChoseToken` | Insert a field token at the caret in the instructions |
| `SubmittedSave` | Save the edited name, description and instructions |
| `ClickedDiscard` | Throw away unsaved text edits |
| `ChoseModel` | Choose the model by its value |
| `ToggledTool` | Turn a tool on or off by its id |
| `ChoseOption` | Choose an option in one of the agent's choices (see page_query) |
| `ClickedAddKnowledge` | Open the picker to add a knowledge source |
| `ClickedRemoveKnowledge` | Remove a knowledge source by its id |
| `ClickedPublish` | Publish the current settings as the live version |
| `ClickedEdit` | Open a draft of the locked live version |
| `ClickedDelete` | Ask to delete the agent (opens the confirmation) |
| `UpdatedConfirmName` | Type the agent's name into the delete confirmation |
| `ConfirmedDelete` (asks first) | Delete the agent. Name it as your target. |

### AgentAvatar (view function)

**Options**

| Name | Type | Description |
| --- | --- | --- |
| `id` (required) | `string` | The agent's id: it picks the initial's color |
| `name` (required) | `string` | The agent's name: its first letter shows without a picture |
| `picture` | `AgentPicture` | An image or an emoji; a colored initial when left out |

## Keyboard and accessibility

- The settings are a labelled form: name, description and instructions are fields, and model, tools and knowledge are fieldsets with legends.
- The primary star is a toggle button (`aria-pressed`), and a disabled control says why.
- Deleting asks first, and can ask you to type the agent's name. Agents can edit, save and publish, and must name the agent they delete.

## Installation

```sh
pnpm dlx shadcn@latest add checkfu/uicontext/agent-settings
```

With npm: `npx shadcn@latest add checkfu/uicontext/agent-settings`. With yarn: `yarn dlx shadcn@latest add checkfu/uicontext/agent-settings`. With bun: `bunx --bun shadcn@latest add checkfu/uicontext/agent-settings`.

It writes these files:

- `src/ui/uicontext/components/AgentEditor.ts`
- `src/ui/uicontext/components/Button.ts`
- `src/ui/uicontext/components/Callout.ts`
- `src/ui/uicontext/components/Dialog.ts`
- `src/ui/uicontext/components/FormControls.ts`
- `src/ui/uicontext/components/IconStroke.ts`
- `src/ui/uicontext/components/ShowText.ts`
- `src/ui/uicontext/components/StatusBadge.ts`
- `src/ui/uicontext/components/Sx.ts`
- `src/ui/uicontext/components/agent/Agent.ts`
- `src/ui/uicontext/components/button.stylex.ts`
- `src/ui/uicontext/components/domain/Format.ts`
- `src/ui/uicontext/components/domain/Notice.ts`
- `src/ui/uicontext/components/domain/Outcome.ts`
- `src/ui/uicontext/components/safeArea.stylex.ts`
- `src/ui/uicontext/components/tokens.stylex.ts`
- `src/ui/uicontext/components/variants.ts`

And installs the npm packages `@stylexjs/stylex`, `effect`.

## Source

- [src/AgentEditor.ts](https://github.com/checkfu/uicontext/blob/main/src/AgentEditor.ts)

## Related

- [Agent Tools](https://uicontext.com/docs/components/agent-tools.md) (`agent-tools`): Lets agents in the browser read the page and act through the same controls people use.
- [Tool Confirmation](https://uicontext.com/docs/components/tool-confirmation.md) (`tool-confirmation`): Asks a person to confirm before an agent's action changes anything.
- [Prompt Template](https://uicontext.com/docs/components/prompt-template.md) (`prompt-template`): Write a prompt with {{variables}} the app fills in: they stand out, unknown ones are flagged, and a preview shows it with samples.
- [Computer](https://uicontext.com/docs/components/computer.md) (`computer`): The machine an agent works on: a live view of its screen, full size or as a thumbnail with Take over, and its browser with tabs and an address bar.
- [Persona Avatar](https://uicontext.com/docs/components/persona-avatar.md) (`persona-avatar`): An agent's face: a shape and a color with eyes that move with what it's doing.
- [Agent List](https://uicontext.com/docs/components/agent-list.md) (`agent-list`): Agents listed like conversations, each with its face, last message time and status.
