Reasoning

A "Thinking…" block above an AI answer that becomes "Thought for 12 seconds" when it is done: the model's working, shown while it arrives and folded away after.

Reasoning

Works with no script: it is a native details. With Alpine and the package's script a re-render keeps the reader's choice: one they opened by hand stays open when it finishes, and one they closed stays closed. See getting started.

Use it

<x-ds::reasoning :status="$run->thinking ? 'running' : 'done'" :duration="$run->thought_seconds">
    {!! $run->reasoning_html !!}
</x-ds::reasoning>

<div class="prose">{!! $run->answer_html !!}</div>

The server says what state it is in; this draws it. Re-render it (a Livewire poll, an event, wire:stream) as the reasoning grows, and once more with status="done" and the duration.

Open while it runs, closed once done, by default. Keep it open after:

<x-ds::reasoning status="done" :duration="64" :collapseWhenDone="false">…</x-ds::reasoning>

Cap a long one, and it follows the newest line while it runs:

<x-ds::reasoning status="running" :maxHeight="8">…</x-ds::reasoning>

Props

PropTypeDefaultWhat it does
statusstringdonerunning or done. From the agent status set: pending draws as running; failed, cancelled and waiting as done.
durationnumber—Seconds it thought: "Thought for 12 seconds", "1 minute 4 seconds". While running, shown short ("4s") beside the label.
labelstringThinking…The words while it runs, in a shimmer.
doneLabelstringThought for :durationThe words once done; :duration is the formatted duration. With no duration, "Reasoning".
openboolfalseOpen on first paint, whatever the status.
openWhileRunningbooltrueOpen while it runs.
collapseWhenDonebooltrueClosed once done.
maxHeightint—At most this many lines tall; the rest scrolls inside. While running the box follows the newest line, unless the reader has scrolled up.
SlotWhat it does
defaultThe reasoning: paragraphs, a list, Markdown you rendered. Drawn muted, behind a rule.

Streaming it with Livewire

<x-ds::reasoning :status="$thinking ? 'running' : 'done'" :duration="$seconds" :maxHeight="8" wire:key="reasoning-{{ $run->id }}">
    <div wire:stream="reasoning">{{ $reasoning }}</div>
</x-ds::reasoning>
foreach ($client->stream($prompt) as $event) {
    if ($event->isThinking()) {
        $this->reasoning .= $event->text;
        $this->stream(to: 'reasoning', content: $event->text);
    }
}
$this->thinking = false; // the response's re-render collapses it

The streamed text is never announced. The change to done is, once: "Thought for 12 seconds".

Following the text, without script

A capped running body is laid out from its bottom (flex-col-reverse), so the browser keeps the newest line in view and, once a reader scrolls up, holds what they are reading. No observer, no scroll handler. Once done it is an ordinary column, so opening it later starts at the top.

Accessibility

  • The summary is the native disclosure button: Tab to it, Enter or Space.
  • A capped body is a named scroll region, a Tab stop, so it scrolls from the keyboard.
  • A visually hidden status region outside the block says "Thought for 12 seconds" when it finishes. The body is not a live region, so a screen reader is not read every streamed word.
  • With the script, it never closes while focus is inside it, and never moves focus.
  • The shimmer, the spinner and the chevron's turn are motion-safe.

Don't

  • Don't put the answer in it. The answer goes after, at full strength.
  • Don't add aria-live to the body. The block says when it is done; the reasoning itself is for reading, not hearing as it streams.
  • Don't force open on every re-render. The reader closing it was a choice; open is for the first paint.

From the package repo: edit this page on GitHub.

Was this page helpful?