Elise UI

Loading Stacked

A list with one row for each step of the run: tool calls, messages and thinking. Rows turn to done or failed as they finish, so the user sees the whole run, not only the latest event. Press Run below to send fake events.

How the parts fit

Same idea as Loading, with one more layer. The root holds the run. Inside it, <AGUILoadingStackedSteps> is the list. You write the inside of one row, and the list repeats it for every step.

  1. aguiLoadingStackedReducer reads each AG-UI event and keeps a list of steps.
  2. <AGUILoadingStacked> gets the whole state in one state prop.
  3. Row parts (StepIcon, StepText, StepSubagent) go inside Steps and show one row each. The other parts go straight inside the root.
<AGUILoadingStacked>                    // the root: takes the whole state
  <AGUILoadingStackedEarlier />         // "+2 earlier" when rows are hidden
  <AGUILoadingStackedSteps>             // the list: repeats one row per step
    <AGUILoadingStackedStepIcon />      //   spinner, check or "!" for this row
    <AGUILoadingStackedStepSubagent />  //   "researcher ·" on a subagent's rows
    <AGUILoadingStackedStepText />      //   "Calling searchChannels..."
  </AGUILoadingStackedSteps>
  <AGUILoadingStackedSummaryDone />     // one line after a finished run collapses
  <AGUILoadingStackedSummaryFailed />   // one line after a failed run collapses
</AGUILoadingStacked>

Example

<AGUILoadingStacked />
The stacked loader, built from parts. Write one row; it repeats for each step. The parts have no colors: style rows with data-status and data-kind.
import {
  CircleAlert,
  CircleCheck,
  Inbox,
  Search,
  type LucideIcon,
} from "lucide-react";

import {
  AGUILoadingStacked,
  AGUILoadingStackedEarlier,
  AGUILoadingStackedStepIcon,
  AGUILoadingStackedSteps,
  AGUILoadingStackedStepText,
  AGUILoadingStackedSummaryDone,
  AGUILoadingStackedSummaryFailed,
} from "@/core/agui-loading/adapters/react";
import {
  aguiLoadingStackedReducer,
  EventType,
  initialAGUILoadingStackedState,
} from "@/core/agui-loading";

import { useAGUILoadingDocsReplay } from "../../hooks";
import { AGUILoadingDocsCard } from "../agui-loading-docs-card";
import source from "./agui-loading-docs-loading-stacked-example.tsx?raw";

// An icon for each tool, found by the tool's name.
const TOOL_ICONS: Record<string, LucideIcon> = {
  listCommunications: Inbox,
  searchChannels: Search,
};

export function AGUILoadingDocsLoadingStackedExample() {
  // -----
  // Step 1: keep track of what the agent is doing.
  //
  // In your app, write:
  //   const [state, dispatch] = useReducer(
  //     aguiLoadingStackedReducer,
  //     initialAGUILoadingStackedState,
  //   );
  // then call dispatch(event) for each AG-UI event you
  // receive. Here the docs send fake events for you
  // when you press "Play".
  // -----
  const { state, play, reset } = useAGUILoadingDocsReplay(
    aguiLoadingStackedReducer,
    initialAGUILoadingStackedState,
  );

  return (
    <AGUILoadingDocsCard
      title="<AGUILoadingStacked />"
      description="The stacked loader, built from parts. Write one row; it repeats for each step. The parts have no colors: style rows with data-status and data-kind."
      status={state.lastEventType ?? state.status}
      plays={[
        { label: "Run", onClick: () => play("two-tool-calls") },
        { label: "Error", onClick: () => play("mid-stream-error") },
      ]}
      onReset={reset}
      source={source}
    >
      {/* Step 2: build the loader from parts. Put them in any order. */}
      <AGUILoadingStacked
        // Required. The state from step 1.
        state={state}
        // Show only the 4 newest rows.
        maxVisible={4}
        // When the agent finishes:
        //   "keep"     the rows stay (default)
        //   "collapse" the rows shrink into one line
        //   "hide"     everything goes away
        // whenDone="collapse"
        // Wait this many milliseconds before "collapse" or "hide".
        // lingerMs={1500}
        className="text-sm text-muted-foreground"
      >
        {/* Shows "+2 earlier" when some rows don't fit. */}
        <AGUILoadingStackedEarlier className="pl-5 text-xs text-foreground/40" />

        {/* -----
            One row. Write it one time; it repeats for each step.
            Each row has two attributes you can style with:
              data-status: active, done or failed
              data-kind:   run, tool, message, reasoning or error
            ----- */}
        <AGUILoadingStackedSteps rowClassName="group/row data-[status=done]:text-foreground/60 data-[status=failed]:text-destructive">
          {/* -----
              The icon. Pick one per event that started the row.
              busyByEvent: while the row works
              doneByEvent / failedByEvent: when it ends
              Rows you don't list show a spinner, a check or "!".
              ----- */}
          <AGUILoadingStackedStepIcon
            className="group-data-[status=done]/row:text-emerald-500"
            busyByEvent={{
              // A function gets the row, so each tool can have its own icon.
              [EventType.TOOL_CALL_START]: (step) => {
                const ToolIcon = TOOL_ICONS[step.toolCallName ?? ""];
                return ToolIcon ? (
                  <ToolIcon className="size-3 animate-pulse" />
                ) : undefined;
              },
            }}
          />

          {/* -----
              The text. Same keys as the icon.
              busyByEvent: phrases that change while the row works
              doneByEvent: the text when the row is finished
              Rows you don't list show the built-in text.
              ----- */}
          <AGUILoadingStackedStepText
            busyByEvent={{
              [EventType.TOOL_CALL_START]: (step) => [
                `Calling ${step.toolCallName}...`,
              ],
              [EventType.TEXT_MESSAGE_START]: ["Writing your answer..."],
            }}
            doneByEvent={{
              [EventType.RUN_STARTED]: "Connected",
              [EventType.TOOL_CALL_START]: (step) =>
                `Checked ${step.toolCallName}`,
              [EventType.TEXT_MESSAGE_START]: "Answer ready",
            }}
          />

          {/* Your own element. This one shows "tool" on tool rows only. */}
          <span className="hidden text-xs text-foreground/40 group-data-[kind=tool]/row:inline">
            tool
          </span>
        </AGUILoadingStackedSteps>

        {/* -----
            The one line after the rows collapse.
            SummaryDone shows when the run finished.
            SummaryFailed shows when the run failed.
            text: your words. A function gets the number of steps.
            children: an icon before the text.
            ----- */}
        <AGUILoadingStackedSummaryDone
          text={(steps) => `Done · ${steps} steps`}
        >
          <CircleCheck className="size-3 text-emerald-500" />
        </AGUILoadingStackedSummaryDone>

        <AGUILoadingStackedSummaryFailed
          text={(steps) => `Stopped after ${steps} steps`}
        >
          <CircleAlert className="size-3 text-destructive" />
        </AGUILoadingStackedSummaryFailed>
      </AGUILoadingStacked>
    </AGUILoadingDocsCard>
  );
}

What makes a row

A row is one piece of work, not one event. A message streams hundreds of events but stays one row. The event that starts a row is its key in every ...ByEvent prop, and default covers the rows you don't list.

data-kindKey in ...ByEventThe row appears when
runEventType.RUN_STARTEDThe agent connects
toolEventType.TOOL_CALL_STARTOne tool call, like searchChannels
messageEventType.TEXT_MESSAGE_STARTThe agent writes its answer
reasoningEventType.REASONING_STARTThe agent thinks
subagentEventType.SUBAGENT_STARTEDA subagent takes over some work
errorEventType.RUN_ERRORThe run failed

Each row also has a status: active while it works, waiting during an approval, then done or failed. That's why the icon and text have four props each, one per status: busyByEvent, waitingByEvent, doneByEvent and failedByEvent.

Subagents and approvals

For agents that hand work to subagents or stop for an approval. The reducer tracks both for you, so the root needs no extra props. Each subagent gets its own row, its steps carry its name, and rows can wait for an approval and pick back up in the next run.

Subagents and approvals
Each subagent gets a row, and its own steps are marked so you can indent them. In tool mode, the tool call becomes the subagent's row. Press Approval, then Approve or Cancel.
import {
  AGUILoadingStacked,
  AGUILoadingStackedStepIcon,
  AGUILoadingStackedSteps,
  AGUILoadingStackedStepSubagent,
  AGUILoadingStackedStepText,
} from "@/core/agui-loading/adapters/react";
import {
  aguiLoadingStackedReducer,
  EventType,
  initialAGUILoadingStackedState,
} from "@/core/agui-loading";

import { useAGUILoadingDocsReplay } from "../../hooks";
import { aguiLoadingDocsAgentPlays } from "../../utils";
import { AGUILoadingDocsCard } from "../agui-loading-docs-card";
import source from "./agui-loading-docs-loading-stacked-agents-example.tsx?raw";

export function AGUILoadingDocsLoadingStackedAgentsExample() {
  // -----
  // Step 1: the same reducer as the basic example.
  // It also gives each subagent its own row, and
  // marks rows that wait for an approval.
  // -----
  const { state, play, playNext, reset } = useAGUILoadingDocsReplay(
    aguiLoadingStackedReducer,
    initialAGUILoadingStackedState,
  );

  return (
    <AGUILoadingDocsCard
      title="Subagents and approvals"
      description="Each subagent gets a row, and its own steps are marked so you can indent them. In tool mode, the tool call becomes the subagent's row. Press Approval, then Approve or Cancel."
      status={state.lastEventType ?? state.status}
      plays={aguiLoadingDocsAgentPlays({ status: state.status, play, playNext })}
      onReset={reset}
      source={source}
    >
      {/* The root stays on screen while the run waits (data-status="waiting"). */}
      <AGUILoadingStacked state={state} className="text-sm text-muted-foreground">
        {/* -----
            Row attributes for agents:
              data-kind="subagent"  a subagent's own row
              data-subagent         set on rows that belong to a subagent
              data-status="waiting" the row waits for an approval
            Here, a subagent's steps are indented.
            ----- */}
        <AGUILoadingStackedSteps rowClassName="group/row data-[subagent]:pl-5 data-[status=done]:text-foreground/60 data-[status=failed]:text-destructive data-[status=waiting]:text-amber-600">
          {/* A waiting row shows a still pause circle. Change it with waitingByEvent. */}
          <AGUILoadingStackedStepIcon className="group-data-[status=done]/row:text-emerald-500" />

          {/* The subagent a row belongs to, e.g. "researcher ·". */}
          <AGUILoadingStackedStepSubagent className="text-foreground/40" />

          {/* -----
              Subagent rows are keyed by SUBAGENT_STARTED.
              waitingByEvent: phrases while the row waits for input
              Rows you don't list show the built-in text, e.g.
              "Delegating to researcher", "Asked researcher".
              ----- */}
          <AGUILoadingStackedStepText
            busyByEvent={{
              [EventType.TOOL_CALL_START]: (step) => [`Calling ${step.toolCallName}...`],
            }}
            waitingByEvent={{
              [EventType.TOOL_CALL_START]: (step) => [`Approve ${step.toolCallName}?`],
            }}
            doneByEvent={{
              [EventType.RUN_STARTED]: "Connected",
              [EventType.TOOL_CALL_START]: (step) => `Checked ${step.toolCallName}`,
            }}
          />
        </AGUILoadingStackedSteps>
      </AGUILoadingStacked>
    </AGUILoadingDocsCard>
  );
}

Parts

Every part also takes the normal props of its HTML element, like className and style. The parts have no colors, so add your own classes. A * marks a required prop.

<AGUILoadingStacked />

The root. It takes the whole state from aguiLoadingStackedReducer and shares it with the parts inside. It shows nothing before the first event.

<AGUILoadingStacked state={state} maxVisible={4} whenDone="collapse">
  {/* parts go here */}
</AGUILoadingStacked>
PropTypeDefaultWhat it does
state*AGUILoadingStackedStaterequiredThe state from aguiLoadingStackedReducer. Pass it as is.
maxVisiblenumberall rowsShow only the newest rows. <AGUILoadingStackedEarlier /> counts the ones it hides.
whenDone
  • "keep"
  • "collapse"
  • "hide"
"keep"What happens when the run ends. "keep" leaves the rows. "collapse" swaps them for one summary line after lingerMs. "hide" removes everything after lingerMs.
lingerMsnumber1200Milliseconds the finished rows stay before they collapse or hide. Only works with "collapse" or "hide".
Data attributeValueWhen
data-statusrunningThe agent works.
waitingThe run waits for input, like an approval.
doneThe run finished.
failedThe run hit an error.
stoppedSomeone cancelled the run.
data-viewstepsThe rows are on screen.
summarywhenDone="collapse" swapped the rows for one summary line.

<AGUILoadingStackedSteps />

The list of rows. You write the inside of one row as its children, and it repeats for every step. Row parts (icon, text, subagent) only work in here. Each row gets the data attributes below, so style rows through rowClassName.

<AGUILoadingStackedSteps rowClassName="data-[status=done]:opacity-60">
  <AGUILoadingStackedStepIcon />
  <AGUILoadingStackedStepText />
</AGUILoadingStackedSteps>
PropTypeDefaultWhat it does
children*ReactNoderequiredThe inside of one row. It repeats for each step.
rowClassNamestring–Classes for every row. Use the row's data attributes to style each state.
animatebooleantrueNew rows slide in and old rows fade out. Set false to turn it off.
Data attributeValueWhen
data-statusactiveThis step is working.
waitingThis step waits for an approval.
doneThis step finished.
failedThis step failed, or the run failed or was cancelled while it worked.
data-kindrunThe agent connects.
toolOne tool call.
messageThe agent writes a message.
reasoningThe agent thinks.
subagentA subagent takes over some work.
errorThe run failed. Added so the error always shows.
data-subagenta subagent run idSet on rows that belong to a subagent. Missing on the main agent's rows.

<AGUILoadingStackedStepIcon />

The icon for one row. It changes as the row changes: a spinner while it works, a check when done, a "!" circle when it fails, a pause circle while it waits.

<AGUILoadingStackedStepIcon
  busyByEvent={{
    [EventType.TOOL_CALL_START]: <Wrench className="size-3" />,
  }}
  doneFallback={<CircleCheck className="size-3 text-emerald-500" />}
/>
PropTypeDefaultWhat it does
busyByEvent{ [event]: ReactNode }–Icon while the row works. Keys are the event that started the row (RUN_STARTED, TOOL_CALL_START, TEXT_MESSAGE_START, REASONING_START, SUBAGENT_STARTED, RUN_ERROR) or "default". A value can be a function that gets the row, e.g. (step) => ...
doneByEvent{ [event]: ReactNode }–Icon when the row is finished. Same keys as busyByEvent.
failedByEvent{ [event]: ReactNode }–Icon when the row failed. Same keys.
waitingByEvent{ [event]: ReactNode }–Icon while the row waits for input. Same keys.
busyFallbackReactNodespinnerIcon for working rows that busyByEvent doesn't list.
doneFallbackReactNodecheckIcon for finished rows that doneByEvent doesn't list.
failedFallbackReactNode"!" circleIcon for failed rows that failedByEvent doesn't list.
waitingFallbackReactNodepause circleIcon for waiting rows that waitingByEvent doesn't list.

<AGUILoadingStackedStepText />

The text for one row. While the row works, its phrases take turns. When the row ends, it shows one done or failed line, like "Checked searchChannels".

<AGUILoadingStackedStepText
  busyByEvent={{
    [EventType.TOOL_CALL_START]: (step) => [`Calling ${step.toolCallName}...`],
  }}
  doneByEvent={{
    [EventType.TOOL_CALL_START]: (step) => `Checked ${step.toolCallName}`,
  }}
/>
PropTypeDefaultWhat it does
busyByEvent{ [event]: string[] }–Phrases that take turns while the row works. Keys are the event that started the row (RUN_STARTED, TOOL_CALL_START, TEXT_MESSAGE_START, REASONING_START, SUBAGENT_STARTED, RUN_ERROR) or "default". A value can be a function that gets the row, e.g. (step) => ...
doneByEvent{ [event]: string }–One line when the row is finished. Same keys as busyByEvent.
failedByEvent{ [event]: string }–One line when the row failed. Same keys.
waitingByEvent{ [event]: string[] }–Phrases that take turns while the row waits for input. Same keys.
animation
  • "slide-up"
  • "slide-down"
  • "slide-left"
  • "slide-right"
  • "typing"
  • "shuffle"
"slide-up"How one phrase changes into the next.
rotateEverynumber1800Milliseconds each phrase stays before the next one. The default is 3200 for typing and 2000 for shuffle.

<AGUILoadingStackedStepSubagent />

The name of the subagent this row's work belongs to, followed by a separator. It shows nothing on the main agent's rows, or on the row that starts the subagent.

PropTypeDefaultWhat it does
separatorReactNode"·"Shown after the name. Pass null for none.

<AGUILoadingStackedEarlier />

Shows "+2 earlier" when maxVisible hides older rows. It shows nothing when every row fits. Put it above <AGUILoadingStackedSteps />.

No props of its own.

<AGUILoadingStackedSummaryDone />

The one line that replaces the rows after a finished run collapses. Only shows with whenDone="collapse". Default text: "Finished · 4 steps". Put an icon in its children and it shows before the text.

<AGUILoadingStackedSummaryDone text={(steps) => `Done in ${steps} steps`}>
  <CircleCheck className="size-3" />
</AGUILoadingStackedSummaryDone>
PropTypeDefaultWhat it does
text
  • string
  • (steps: number) => string
"Finished · N steps"Your own text. A function gets the number of steps.
childrenReactNode–Shown before the text. Usually an icon.

<AGUILoadingStackedSummaryFailed />

Same as SummaryDone, but for a run that failed or was stopped. Default text: "Stopped · 4 steps". Use both summaries so each ending has its own line.

PropTypeDefaultWhat it does
text
  • string
  • (steps: number) => string
"Stopped · N steps"Your own text. A function gets the number of steps.
childrenReactNode–Shown before the text. Usually an icon.