Reasoning
The thinking behind an AI answer, behind a disclosure: "Thinking…" has a light passing through it while the model works, the thinking opens on its own and closes into "Thought for 12s" when it ends, and it streams in as muted markdown.
See it as an AI agent does.See this component the way an AI agent does.
Installation
npx shadcn@latest add @keyframery/reasoningThis adds components/keyframery/reasoning.tsx and its primitive to your project, and installs UI SDK, along with agent-content, collapsible, markdown, which it builds on. The motion tokens are added to your global CSS the first time you install a component.
Usage
import { Reasoning, ReasoningContent, ReasoningTrigger } from "@/components/keyframery/reasoning"
export default function Usage() {
return (
<Reasoning duration={4}>
<ReasoningTrigger />
<ReasoningContent>{"The 07:05 lands at 10:20, early enough to drop bags before lunch."}</ReasoningContent>
</Reasoning>
)
}Anatomy
How the parts fit together:
Reasoning
├── ReasoningTrigger
└── ReasoningContentExamples
While it thinks
Set streaming while the model thinks: the trigger reads "Thinking…" with a light passing through it, and the thinking opens on its own. When streaming ends it closes and reads "Thought for 6s", timed for you unless you pass duration. A reader who toggles it keeps their choice.
Your own labels
thinkingLabel and doneLabel on the trigger change its words; doneLabel gets the seconds. Set autoClose={false} to leave the thinking open once it ends.
Controlled
Pass open and onOpenChange to own the state. Streaming starting and ending still asks for a change through onOpenChange, so the automatic open and close keep working.
Motion
| Move | What you see |
|---|---|
| Fade | While it thinks, a soft light passes through "Thinking…"; it stops for reduced motion. |
| Height | The thinking opens to its real height on its own when streaming starts, and closes when it ends unless the reader toggled it. |
| Cascade | The thinking rises in as it opens. |
| Rise | Each new paragraph or list of the thinking rises in as it streams, and the newest line stays in view. |
| Spring | The chevron turns down on a spring. |
Timing and springiness follow the motion style you set. To change how fast this reasoning moves, pass speed:
<Reasoning speed="fast">
…
</Reasoning>"fast" is 0.6×, "slow" 1.4×, and a number sets the multiplier. With reduced motion turned on, nothing moves: changes happen at once or with a short fade.
Theming
Set these CSS variables on the component or a parent. Leave them unset to follow the light and dark theme. The open Customize panel below the preview lets you try these settings.
| Variable | What it changes | Default |
|---|---|---|
--reasoning-ink | Trigger text | text-muted-foreground |
--reasoning-text | Thinking text | text-muted-foreground |
--reasoning-font | Thinking size | text-[13px] |
--reasoning-rule | Rule beside the thinking | border-border |
--reasoning-indent | Thinking indent | ps-3.5 |
--reasoning-max-height | Tallest the thinking gets before it scrolls | max-h-72 |
API reference
Every part takes className and children, along with the props of the element it renders. The parts are rendered by UI SDK, so they also take render, to draw your own element, and a function of their state for className and style.
Reasoning
Renders a <div>, and takes its props too.
Prop
Type
ReasoningTrigger
Renders a <button>, and takes its props too.
Prop
Type
ReasoningContent
Renders a <div>, and takes its props too.
Prop
Type
ReasoningLabel
Renders a <span>, and takes its props too.
Prop
Type
Other parts
These take the props of the element they render, and nothing else:
ReasoningContext
Keyboard
| Key | What it does |
|---|---|
| Tab | Moves focus to the trigger. |
| Enter or Space | Shows or hides the thinking. |
Accessibility
Roles, keyboard and focus are declared on the component's UI SDK primitive, and state is announced through the matching ARIA attributes. More in Accessibility.
Built on UI SDK's core
UI SDK doesn't ship a reasoning, so this one is defined with its core: one definePrimitive in components/keyframery/core/reasoning-core.ts, with no React in it. UI SDK's adapters can render that same definition in Vue, Svelte, Solid and web components. To keep your own styling and take only the motion, import from @/components/keyframery/primitives/reasoning.
Questions
How does the animated Reasoning for UI SDK move?
Fade: While it thinks, a soft light passes through "Thinking…"; it stops for reduced motion. Height: The thinking opens to its real height on its own when streaming starts, and closes when it ends unless the reader toggled it. Cascade: The thinking rises in as it opens. Rise: Each new paragraph or list of the thinking rises in as it streams, and the newest line stays in view. Spring: The chevron turns down on a spring.
Do I need Motion or Framer Motion for the animated Reasoning?
No. Every move is plain CSS, so there is nothing to install besides the component and UI SDK.
UI SDK has no reasoning. How is this one built on UI SDK?
Its behaviour is one definition written with UI SDK's core (definePrimitive), in components/keyframery/core/reasoning-core.ts. Its parts are rendered by UI SDK's adapter, so they take render, state-based class names and data-slot, like every UI SDK component.
What happens to the Reasoning when someone turns on reduced motion?
Nothing moves. State changes happen at once, or with a short fade.
More in AI
All componentsPrompt Composer
The input box of an AI chat. It grows with the message, takes files by the paperclip, a drop or a paste, opens orders, people or commands at the caret after @ and /, and its Send key turns into a spinner and then Stop while the reply comes in.
Tool Call
One agent tool call as a card: the status mark, a title, the tool's name and the time it took, with the input and the output (or the error) in a body that opens. A failed call opens on its own. Agents read the name, status and summaries of the input and output, and open the card through its collapsible.