Edit an agent's name, instructions, tools and model.
Support bot
Published · v6
import { UiSchema } from "@effect/ui"import { Html } from "@effect/ui/html"import { Schema } from "effect"import { AgentEditor } from "./ui/uicontext/components/kit/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, }, }),})Installation
pnpm dlx shadcn@latest add checkfu/uicontext/agent-editorUsage
import { AgentEditor } from "./ui/uicontext/components/kit/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 changeexport 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: { RequestedSave: ({ name, instructions }) => Message.SavedAgent({ name, instructions }), RequestedModel: ({ model }) => Message.ChoseAgentModel({ model }), RequestedTool: () => undefined, RequestedChoice: () => undefined, RequestedAddKnowledge: () => undefined, RequestedRemoveKnowledge: () => undefined, RequestedPublish: () => undefined, RequestedEdit: () => undefined, RequestedDelete: () => undefined, }, })API reference
AgentCardComponent
Props
| Name | Type | Description |
|---|---|---|
idrequired | string | Identifies the agent in the events the card sends |
namerequired | 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 |
AgentEditorComponent
Props
| Name | Type | Description |
|---|---|---|
idrequired | string | Identifies the agent in the events the editor sends |
namerequired | 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 |
instructionsrequired | { 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 |
canrequired | 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 |
ConfirmedDeleteasks first | Delete the agent. Name it as your target. |
AgentAvatarView function
Options
| Name | Type | Description |
|---|---|---|
idrequired | string | The agent's id: it picks the initial's color |
namerequired | 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 |
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.