Keyframery

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.

Resize preview. Focus the handle and use the left or right arrow keys. Hold Shift for larger steps.— px
Customize1 controls
Animation speed1×

Installation

npx shadcn@latest add @keyframery/reasoning

This 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
└── ReasoningContent

Examples

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

MoveWhat you see
FadeWhile it thinks, a soft light passes through "Thinking…"; it stops for reduced motion.
HeightThe thinking opens to its real height on its own when streaming starts, and closes when it ends unless the reader toggled it.
CascadeThe thinking rises in as it opens.
RiseEach new paragraph or list of the thinking rises in as it streams, and the newest line stays in view.
SpringThe 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.

VariableWhat it changesDefault
--reasoning-inkTrigger texttext-muted-foreground
--reasoning-textThinking texttext-muted-foreground
--reasoning-fontThinking sizetext-[13px]
--reasoning-ruleRule beside the thinkingborder-border
--reasoning-indentThinking indentps-3.5
--reasoning-max-heightTallest the thinking gets before it scrollsmax-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

KeyWhat it does
TabMoves focus to the trigger.
Enter or SpaceShows 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.

All components

On this page