---
title: "Reasoning"
description: "Stream a reasoning summary, expand its details and replay the response."
---

# Reasoning

Stream a reasoning summary, expand its details and replay the response.

## Usage

Expand the reasoning summary or press Replay. Thinking text streams first, the summary closes automatically unless you changed it, then the answer arrives. Reduced motion disables decorative transitions.

## Example

```contract
use uiFontFamily, ButtonAI as ButtonContent from "@rightui/ui"
use MessageFrame, MessageContent, BubbleFrame from "@rightui/ui"
use TraceFrame, TraceDisclosure from "@rightui/ui"

component Demo
  props
    width: number
    reduced: bool
  inject
    uiFont: string
    rightuiDemoTime: number
    rightuiRunDemo: action
  state started = -10000
  state chosenOpen: option<bool> = some(true)
  derive elapsed = (rightuiDemoTime - started) * 1.15
  derive running = elapsed < 5000
  derive busy = elapsed < 8000
  derive open = match chosenOpen { case some(value) => value, case none => running }
  derive reasoning = "The deploy log has three phases. Install takes 38s and next build takes 52s, both normal for this repo.\n\nImage optimization takes 3m 50s. It reruns on every deploy because its cache key includes the commit hash, so the cache never hits."
  derive answer = "Image optimization is the bottleneck. Key its cache on the lockfile and the image directory instead of the commit hash, and the deploy should take under two minutes."
  action replay
    started = rightuiDemoTime
    chosenOpen = none
    rightuiRunDemo(7000)
  action toggle
    chosenOpen = some(not open)
  view
    column gap="ui.space-16" min-width=0 width="100%" max-width="24rem" min-height=288 padding="ui.space-24 ui.space-0" font-size="ui.text-sm"
      MessageFrame(id="ai-reasoning-user", align="end")
        MessageContent(id="ai-reasoning-question", align="end")
          BubbleFrame(id="ai-reasoning-bubble", align="end", variant="muted")
            text "Why is the checkout deploy so slow?" font-family=uiFontFamily(uiFont) data-rightui-font="body"
      MessageFrame(id="ai-reasoning-assistant", align="start")
        MessageContent(id="ai-reasoning-content", align="start")
          column gap="ui.space-16"
            TraceFrame()
              TraceDisclosure(id="ai-reasoning-0", title=(running ? "Thinking" : "Thought for 5s"), icon="none", status=(running ? "running" : ""), open=open, reduced=reduced, toggle=toggle)
                text (running ? reasoning.slice(0, floor(elapsed / 5000 * reasoning.length)) : reasoning) testId="ai-reasoning-text" white-space="pre-wrap" line-height="ui.leading-relaxed" font-family=uiFontFamily(uiFont) data-rightui-font="body"
            if elapsed >= 5400
              text (busy ? answer.slice(0, floor((elapsed - 5400) / 2600 * answer.length)) : answer) testId="ai-reasoning-answer" line-height="ui.leading-relaxed" font-family=uiFontFamily(uiFont) data-rightui-font="body"
      if not busy
        row margin-top="auto"
          ButtonContent(id="ai-reasoning-replay", label="Replay", variant="outline", size="sm", disabled=false, press=replay)
            text "Replay" font-family=uiFontFamily(uiFont) data-rightui-font="body"

```

## Keyboard

Tab to actions and disclosures; Enter or Space activates them.

## Demo runtime

Timed examples use an injected clock. Add these members to your root component. Replace the scripted state with events from your TypeScript or Rust data source when connecting a model.

```contract
use defaultFontWeights from "@rightui/ui"
  state demoTime = 0
  state demoUntil = 0
  provide
    uiFont = "theme"
    uiWeights = defaultFontWeights()
    rightuiDemoTime = demoTime
    rightuiRunDemo = runDemo
  action runDemo(duration: number)
    demoUntil = max(demoUntil, demoTime + duration)
  action tickDemo
    demoTime = min(demoUntil, demoTime + 32)
  task demoClock when demoTime < demoUntil
    every(32, tickDemo)
```

## Source

File: patterns/ai-elements/reasoning.contract

```contract
use uiFontFamily, ButtonAI as ButtonContent from "@rightui/ui"
use MessageFrame, MessageContent, BubbleFrame from "@rightui/ui"
use TraceFrame, TraceDisclosure from "@rightui/ui"

component Demo
  props
    width: number
    reduced: bool
  inject
    uiFont: string
    rightuiDemoTime: number
    rightuiRunDemo: action
  state started = -10000
  state chosenOpen: option<bool> = some(true)
  derive elapsed = (rightuiDemoTime - started) * 1.15
  derive running = elapsed < 5000
  derive busy = elapsed < 8000
  derive open = match chosenOpen { case some(value) => value, case none => running }
  derive reasoning = "The deploy log has three phases. Install takes 38s and next build takes 52s, both normal for this repo.\n\nImage optimization takes 3m 50s. It reruns on every deploy because its cache key includes the commit hash, so the cache never hits."
  derive answer = "Image optimization is the bottleneck. Key its cache on the lockfile and the image directory instead of the commit hash, and the deploy should take under two minutes."
  action replay
    started = rightuiDemoTime
    chosenOpen = none
    rightuiRunDemo(7000)
  action toggle
    chosenOpen = some(not open)
  view
    column gap="ui.space-16" min-width=0 width="100%" max-width="24rem" min-height=288 padding="ui.space-24 ui.space-0" font-size="ui.text-sm"
      MessageFrame(id="ai-reasoning-user", align="end")
        MessageContent(id="ai-reasoning-question", align="end")
          BubbleFrame(id="ai-reasoning-bubble", align="end", variant="muted")
            text "Why is the checkout deploy so slow?" font-family=uiFontFamily(uiFont) data-rightui-font="body"
      MessageFrame(id="ai-reasoning-assistant", align="start")
        MessageContent(id="ai-reasoning-content", align="start")
          column gap="ui.space-16"
            TraceFrame()
              TraceDisclosure(id="ai-reasoning-0", title=(running ? "Thinking" : "Thought for 5s"), icon="none", status=(running ? "running" : ""), open=open, reduced=reduced, toggle=toggle)
                text (running ? reasoning.slice(0, floor(elapsed / 5000 * reasoning.length)) : reasoning) testId="ai-reasoning-text" white-space="pre-wrap" line-height="ui.leading-relaxed" font-family=uiFontFamily(uiFont) data-rightui-font="body"
            if elapsed >= 5400
              text (busy ? answer.slice(0, floor((elapsed - 5400) / 2600 * answer.length)) : answer) testId="ai-reasoning-answer" line-height="ui.leading-relaxed" font-family=uiFontFamily(uiFont) data-rightui-font="body"
      if not busy
        row margin-top="auto"
          ButtonContent(id="ai-reasoning-replay", label="Replay", variant="outline", size="sm", disabled=false, press=replay)
            text "Replay" font-family=uiFontFamily(uiFont) data-rightui-font="body"

```
