shadcn.io is an independent project built on shadcn/ui
Components
Free
Agent for Svelte UI SDK
An agent's setup on one card for Svelte on UI SDK: its name and model, the system prompt, and tools that open into their JSON input schemas.
On this page11 sections
Agent is a card that describes an agent before it runs: its name and model, the system prompt it follows, the tools it may call, each opening into its input schema, and the shape of what it returns. Put it on an agent's settings page, in a picker that compares agents, or in the docs for an agent you ship.
To show what an agent did during a run, use Subagent for work it handed off or Tool for a single call.
Installation
Sign in to get your install command
Free with an account. It carries your token, so the CLI installs everything in one go.
<Agent>
<AgentHeadermodel="gpt-4o"name="Research Assistant" />
<AgentContent>
<AgentInstructions>Search the web and cite every source.</AgentInstructions>
<AgentTools>
<AgentTooltool={{
description: "Search the web",
jsonSchema: { properties: { query: { type: "string" } }, type: "object" },
}}
value="search"
/>
</AgentTools>
<AgentOutputschema="interface Result { answer: string }" />
</AgentContent>
</Agent>
AgentHeader needs a name, and every other part is optional: a card shows only the parts you give it.
Accessibility
The tool rows sit in a group named by the label above them, Tools unless you set label. Each row is a <button> named by the tool's description, and aria-expanded tells a screen reader whether its schema is open. The button sits inside an h3, so every tool also lands in the page's heading outline. If the card sits under its own h3, change that level in components/ui/accordion, which every accordion in the app shares. A schema scrolls inside its block, which takes focus so the arrow keys can scroll it. Its copy button appears on focus as well as on hover and announces "Copied". The bot icon is hidden from screen readers.
KeyAction
Space
When focus is on a tool's row, opens or closes its schema.
Enter
When focus is on a tool's row, opens or closes its schema.
Tab
Moves focus to the next focusable element: the next row, or in an open tool its copy button and then its schema.
Shift+Tab
Moves focus to the previous focusable element.
Arrow Down
When focus is on a row, moves it to the next row, and from the last one back to the first.
Arrow Up
When focus is on a row, moves it to the previous row, and from the first one to the last.
Home
When focus is on a row, moves it to the first row.
End
When focus is on a row, moves it to the last row.
Demos
Controlled
A support agent's three tools, with the refund tool open and an Expand all button in the header that turns into Collapse all once every row is open. The open rows live in the demo's own state, passed to AgentTools as value. Control the list this way when a link or a failed call should open one particular tool.
Team
Three cards in a column for a researcher, a writer and a reviewer, each with its model and a count of its tools in an outline Badge at the end of the header. The cards hold only their instructions. Use this layout to compare agents that split one job, where the full tool schemas would bury the differences between them.
AI SDK tools
A trip planner's two tools, a weather lookup and a flight search, written the way the AI SDK's tool() returns them: a description and an inputSchema wrapped as jsonSchema() wraps it. AgentTool unwraps the schema itself. The output schema is JSON, so AgentOutput gets language set to json. Start here when the card documents tools you already hand to a model.
AI SDK
A tool from the AI SDK's tool() is a description and an input schema, which is what AgentTool takes.
A tool definition is data, so the card needs nothing from the AI SDK in Svelte: give AgentTool an object with the tool's description and its JSON Schema, either as jsonSchema or wrapped in inputSchema the way the AI SDK tools demo writes it.
AgentTool reads the jsonSchema field of the wrapper that jsonSchema() and zodSchema() return, and converts nothing itself. A tool whose inputSchema is a bare Zod schema needs one of those first: wrap it in zodSchema() from ai, or pass the result of Zod 4's z.toJSONSchema() as jsonSchema. Show the model id you pass to the provider in AgentHeader's model, and the system prompt in AgentInstructions.
Migrating from AI SDK Elements
AI SDK Elements is for React, so there is nothing to migrate in Svelte. Agent has the same parts and props here, and the demos above are the place to start.
FAQ
How do I list an agent's tools with their input schemas?
Put one AgentTool per tool inside AgentTools, each with the tool object as tool and a unique value. The row's label is the tool's description, or "No description" when it has none, and the row opens into the input schema printed as JSON in a Code Block.
AgentTool reads jsonSchema first and falls back to inputSchema, so an object with either field works. Several rows can be open at once unless you set multiple to false on AgentTools.
Can I pass AI SDK tools to the Agent component?
Yes. The AI SDK's tool() returns the object you give it, a description and an inputSchema, and that is what AgentTool reads. When the schema comes from jsonSchema() or zodSchema(), it is a wrapper whose jsonSchema field holds the JSON Schema, and AgentTool unwraps it.
A bare Zod schema as inputSchema is the exception, because AgentTool doesn't convert it. Wrap it in zodSchema() from ai, or pass the result of Zod 4's z.toJSONSchema() as jsonSchema. The AI SDK section maps a whole tools record to rows.
What is the difference between Agent and Subagent?
Agent describes an agent before it runs: the model, the system prompt, the tools it may call and the shape of its answer. It belongs on a settings page, in a picker or in your docs.
Subagent shows a run that already happened, as one line in the conversation that opens into the calls the subagent made and what it found. A chat that hands work to other agents shows Subagent lines in the thread, and the Agent card wherever people set those agents up.
How do I show an agent's output schema?
Pass the schema as a string to schema on AgentOutput: a TypeScript interface, a JSON Schema, or the source of a Zod schema. A JSON Schema object goes through JSON.stringify first. It's highlighted as TypeScript unless you set language, such as json, and a language the highlighter doesn't know shows as plain text.
The block stops growing at 18rem and scrolls inside, and its copy button copies the whole schema. Leave AgentOutput out when the agent answers in free text.
How do I open an Agent tool from code in Svelte?
Hold the open tools' values in state, pass them to AgentTools as value, and update them in onValueChange, which receives the new array as its first argument. The Controlled demo drives an Expand all button this way.
To open a tool from the first render without holding state, list its value in defaultValue instead. Open the tool a deep link names, or the one whose last call failed, so the reader lands on the schema they came for.
How do I style the parts of an Agent card?
Every part but the tool rows carries a data-slot you can target from CSS: agent, agent-header, agent-name, agent-model, agent-content, agent-instructions, agent-tools and agent-output. A row is UI SDK's accordion item, which keeps its own slot, accordion-item. For lasting changes, edit components/ui/agent, which is your code once installed.
A class passed to a part merges with its own. On AgentTools it lands on the wrapper that holds the label, not on the bordered list, so restyle the list in the agent file. The rows and the schema blocks come from your Accordion and Code Block, so a change to those shows here too.
How do I show a long system prompt in AgentInstructions?
Pass the prompt as one string. On Svelte that string goes in the children prop, as the demos do, not between the tags. AgentInstructions keeps its line breaks and wraps long lines, and the box grows with the text, with no height limit or scroll, so a prompt of several screens makes a tall card.
The text renders as written, so Markdown shows its asterisks and pound signs. For a long prompt, give the box in components/ui/agent a maximum height and let it scroll, or show the prompt elsewhere and keep a one-line summary in the card.
How do I add a button or a badge to the Agent header?
Put it inside AgentHeader as its children. They render after the name and the model badge, pushed to the far end of the row, which is where the Controlled demo puts its Expand all button and the Team demo its count of tools.
When the row runs short, the agent's name and the model badge both shrink and truncate with an ellipsis. A Badge or a Button you add keeps its full width, since both carry shrink-0, so keep what you put there short in a card that can get narrow.
API Reference
Agent
<div>data-slot="agent"
PropType
class?string
Merged with the part's classes.
AgentHeader
<div>data-slot="agent-header"
PropType
namestring
The agent's name.
model?string
The model it runs on, shown as a badge after its name.
class?string
Merged with the part's classes.
AgentContent
<div>data-slot="agent-content"
PropType
class?string
Merged with the part's classes.
AgentInstructions
<div>data-slot="agent-instructions"
PropType
childrenstring
The system prompt.
label?string
The heading above it.
Default
"Instructions"
class?string
Merged with the part's classes.
AgentTools
<div>data-slot="agent-tools"
PropType
value?T[]
The open items' values. Pass it to control the accordion. Two-way with bind:value.
Whether the open item can close when only one may be open. With false, one item always stays open and its trigger reports it can't be pressed.
Default
true
controller?{ /** The open items' values. */ getValue: () → string[]; /** Sets the open items. Only the first counts unless `multiple` is set. Returns false when canceled. */ setValue: (value: string[], options?: AccordionChangeOptions) → boolean; /** Whether an item is open. */ isOpen: (value: string) → boolean; /** Opens an item. With one item open at a time, closes the others. */ open: (value: string, options?: AccordionChangeOptions) → boolean; /** Closes an item, unless it's the one item that must stay open. */ close: (value: string, options?: AccordionChangeOptions) → boolean; /** Opens a closed item, or closes an open one. */ toggle: (value: string, options?: AccordionChangeOptions) → boolean; /** Opens every enabled item. Only when `multiple` is set. */ openAll: (options?: AccordionChangeOptions) → boolean; /** Closes every item that may close. */ closeAll: (options?: AccordionChangeOptions) → boolean; /** Moves focus to an item's trigger, or the first trigger. */ focus: (value?: string) → void; }
Opens and closes items from anywhere. Create one with createAccordionController().
Type
{ /** The open items' values. */ getValue: () → string[]; /** Sets the open items. Only the first counts unless `multiple` is set. Returns false when canceled. */ setValue: (value: string[], options?: AccordionChangeOptions) → boolean; /** Whether an item is open. */ isOpen: (value: string) → boolean; /** Opens an item. With one item open at a time, closes the others. */ open: (value: string, options?: AccordionChangeOptions) → boolean; /** Closes an item, unless it's the one item that must stay open. */ close: (value: string, options?: AccordionChangeOptions) → boolean; /** Opens a closed item, or closes an open one. */ toggle: (value: string, options?: AccordionChangeOptions) → boolean; /** Opens every enabled item. Only when `multiple` is set. */ openAll: (options?: AccordionChangeOptions) → boolean; /** Closes every item that may close. */ closeAll: (options?: AccordionChangeOptions) → boolean; /** Moves focus to an item's trigger, or the first trigger. */ focus: (value?: string) → void; }
debug?boolean
Logs every state change with its reason to the console, in development builds.
disabled?boolean
Stops every item from opening or closing. Triggers stay focusable.
Default
false
hiddenUntilFound?boolean
Keeps closed panels in the page as hidden="until-found", so the browser's find in page can match their text and open them.
Default
false
keepMounted?boolean
Whether closed panels stay in the page, hidden.
Default
false
label?string
The heading above the list.
Default
"Tools"
loopFocus?boolean
Whether the arrow keys wrap from the last trigger to the first.
Default
true
multiple?boolean
Whether several items can be open at once. Otherwise opening one closes the others. Accordion's default: false.
Default
true
orientation?"horizontal" | "vertical"
Which arrow keys move between triggers: Up and Down, or Left and Right.
Type
"horizontal" | "vertical"
Default
"vertical"
render?Snippet<[{ props, state, children }]>
Renders your own element: a snippet that gets the part's props to spread on it, its state, and children, its content.
Type
Snippet<[{ props, state, children }]>
class?string
Merged with the part's classes.
AgentTool
data-slot="agent-tool"
PropType
toolobject
The tool: its description is the row, its input schema the panel.