Elise UI

Loading

One line that tells the user what the agent is doing right now. It follows the latest AG-UI event, so the text reads "Searching..." during a tool call and "Writing..." while the answer streams. Press Run below to send fake events.

How the parts fit

The loader is a root with small parts inside. Each part shows one thing. Use the parts you want, in any order, and put your own elements between them.

  1. aguiLoadingReducer reads each AG-UI event and keeps the state: is the agent running, and what was the last event.
  2. <AGUILoading> gets that state as props and decides when the line is on screen.
  3. The parts inside read from the root and show the icon, text and so on.
<AGUILoading>              // the root: shows or hides the line
  <AGUILoadingIcon />      // icon for the latest event
  <AGUILoadingSubagent />  // "researcher ·" when a subagent works
  <AGUILoadingText />      // "Searching..." for the latest event
  <AGUILoadingEvent />     // "TOOL_CALL_START", for debugging
</AGUILoading>

Example

<AGUILoading />
The same loader, built from parts. Put the parts in any order, leave some out, and add your own elements.
import { useEffect, useState } from "react";
import { CircleAlert, CircleCheck, Wrench } from "lucide-react";

import {
  AGUILoading,
  AGUILoadingEvent,
  AGUILoadingIcon,
  AGUILoadingText,
} from "@/core/agui-loading/adapters/react";
import {
  aguiLoadingReducer,
  EventType,
  initialAGUILoadingState,
} from "@/core/agui-loading";

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

// Your own element: seconds since the agent started.
function ElapsedTime({ running }: { running: boolean }) {
  const [seconds, setSeconds] = useState(0);

  useEffect(() => {
    if (!running) return;
    setSeconds(0);
    const id = setInterval(() => setSeconds((s) => s + 1), 1000);
    return () => clearInterval(id);
  }, [running]);

  return <span className="tabular-nums">{seconds}s</span>;
}

export function AGUILoadingDocsLoadingExample() {
  // -----
  // Step 1: keep track of what the agent is doing.
  //
  // In your app, write:
  //   const [state, dispatch] = useReducer(
  //     aguiLoadingReducer,
  //     initialAGUILoadingState,
  //   );
  // 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(
    aguiLoadingReducer,
    initialAGUILoadingState,
  );
  const running = state.status === "running";

  return (
    <AGUILoadingDocsCard
      title="<AGUILoading />"
      description="The same loader, built from parts. Put the parts in any order, leave some out, and add your own elements."
      status={state.lastEventType ?? state.status}
      plays={[
        { label: "Run", onClick: () => play("happy-path") },
        { label: "Error", onClick: () => play("mid-stream-error") },
      ]}
      onReset={reset}
      source={source}
    >
      {/* Step 2: build the loader from parts. The parts have no colors: add your own classes. */}
      <AGUILoading
        // Required. true while the agent is working.
        active={running}
        // Required. The most recent event.
        eventType={state.lastEventType}
        // What happens when the agent finishes: "linger", "hide" or "keep".
        whenDone="keep"
        // Style each state with data-presence: running, lingering or done.
        className="group text-sm text-muted-foreground data-[presence=done]:opacity-60"
      >
        {/* Icon first. Events you don't list show the fallback spinner. */}
        <AGUILoadingIcon
          byEvent={{
            [EventType.TOOL_CALL_START]: (
              <Wrench className="size-3 animate-pulse" />
            ),
            [EventType.RUN_FINISHED]: (
              <CircleCheck className="size-3 text-emerald-500" />
            ),
            [EventType.RUN_ERROR]: (
              <CircleAlert className="size-3 text-destructive" />
            ),
          }}
        />

        {/* Your own element. CSS hides it when the run is done. */}
        <span className="text-xs text-foreground/40 group-data-[presence=done]:hidden">
          <ElapsedTime running={running} />
        </span>

        {/* Then the text. Add "..." yourself if you want it. */}
        <AGUILoadingText
          animation="slide-up"
          byEvent={{
            [EventType.RUN_STARTED]: ["Waking up..."],
            [EventType.TOOL_CALL_START]: ["Digging through channels..."],
            [EventType.TEXT_MESSAGE_CONTENT]: ["Writing your digest..."],
            [EventType.RUN_FINISHED]: ["Done"],
            [EventType.RUN_ERROR]: ["Something went wrong"],
            default: ["Working on it..."],
          }}
        />

        {/* Optional: the event name, for debugging. Leave it out to hide it. */}
        <AGUILoadingEvent className="font-mono text-xs text-foreground/40" />
      </AGUILoading>
    </AGUILoadingDocsCard>
  );
}

Choosing text and icons per event

The icon and the text both take a byEvent object. Each key is an AG-UI event name, and the value is what to show for that event. Three more keys cover the rest:

  • waiting while the run waits for an approval.
  • stopped after someone cancels the run.
  • default for every event you didn't list.

Leave an event out and the part uses its built-in text or icon. Not sure which event name to use? Add <AGUILoadingEvent /> and it prints the name as events arrive.

<AGUILoadingText
  byEvent={{
    [EventType.TOOL_CALL_START]: ["Searching..."], // this event
    waiting: ["Needs your approval"],              // the run is waiting
    stopped: ["Cancelled"],                        // the run was cancelled
    default: ["Working on it..."],                 // every other event
  }}
/>

Subagents and approvals

For agents that hand work to subagents or stop for an approval. Pass three more props to the root: subagent, waiting and stopped. The line then names the subagent behind the latest event, and stays on screen while an approval is pending.

Subagents and approvals
The same loader with a subagent's name in front of the text. When the run stops for an approval, it waits on screen until the next run. Press Approval, then Approve or Cancel.
import { CircleCheck } from "lucide-react";

import {
  AGUILoading,
  AGUILoadingIcon,
  AGUILoadingSubagent,
  AGUILoadingText,
} from "@/core/agui-loading/adapters/react";
import {
  aguiLoadingReducer,
  EventType,
  initialAGUILoadingState,
} 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-agents-example.tsx?raw";

export function AGUILoadingDocsLoadingAgentsExample() {
  // -----
  // Step 1: the same reducer as the basic example.
  // It also tracks subagents and approvals for you:
  //   state.subagentName  the subagent behind the latest event
  //   state.status        "waiting" while an approval is pending,
  //                       "stopped" when the run was cancelled
  // -----
  const { state, play, playNext, reset } = useAGUILoadingDocsReplay(
    aguiLoadingReducer,
    initialAGUILoadingState,
  );

  return (
    <AGUILoadingDocsCard
      title="Subagents and approvals"
      description="The same loader with a subagent's name in front of the text. When the run stops for an approval, it waits on screen until the next run. Press Approval, then Approve or Cancel."
      status={state.lastEventType ?? state.status}
      plays={aguiLoadingDocsAgentPlays({ status: state.status, play, playNext })}
      onReset={reset}
      source={source}
    >
      {/* Step 2: pass three more props to the root. */}
      <AGUILoading
        active={state.status === "running"}
        eventType={state.lastEventType}
        // true while the run waits for input, e.g. an approval.
        // The loader stays on screen until the next run, whatever whenDone says.
        waiting={state.status === "waiting"}
        // true when the run was cancelled. Shows the "stopped" text.
        stopped={state.status === "stopped"}
        // The subagent behind the latest event, for <AGUILoadingSubagent />.
        subagent={state.subagentName}
        whenDone="keep"
        // data-presence is "waiting" while it waits.
        className="text-sm text-muted-foreground data-[presence=done]:opacity-60 data-[presence=waiting]:text-amber-600"
      >
        {/* While it waits, the icon is a still pause circle. Change it with the "waiting" key. */}
        <AGUILoadingIcon
          byEvent={{
            [EventType.RUN_FINISHED]: <CircleCheck className="size-3 text-emerald-500" />,
          }}
        />

        {/* The subagent's name, e.g. "researcher ·". Nothing while the parent works. */}
        <AGUILoadingSubagent className="font-medium text-foreground/80" />

        <AGUILoadingText
          byEvent={{
            [EventType.SUBAGENT_STARTED]: ["Handing off..."],
            [EventType.SUBAGENT_FINISHED]: ["Gathering results..."],
            [EventType.TOOL_CALL_START]: ["Using a tool..."],
            [EventType.TEXT_MESSAGE_START]: ["Writing..."],
            [EventType.RUN_FINISHED]: ["Done"],
            // "waiting" and "stopped" are keys too, like "default".
            waiting: ["Waiting for your approval...", "Standing by..."],
            stopped: ["Stopped"],
            default: ["Working on it..."],
          }}
        />
      </AGUILoading>
    </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.

<AGUILoading />

The root. It decides when the loader is on screen and tells the parts inside it which event came last. It draws nothing by itself, so put at least one part inside.

<AGUILoading active={state.status === "running"} eventType={state.lastEventType}>
  {/* parts go here */}
</AGUILoading>
PropTypeDefaultWhat it does
active*booleanrequiredtrue while the agent works. Pass state.status === "running".
eventType*
  • string
  • null
requiredThe latest AG-UI event, e.g. TOOL_CALL_START. The icon and text use it to pick what to show. Pass state.lastEventType.
whenDone
  • "linger"
  • "hide"
  • "keep"
"linger"What happens when the run ends. "linger" shows the last text for lingerMs, then hides. "hide" hides at once. "keep" leaves the last text until the next run.
lingerMsnumber1200Milliseconds the last text stays. Only works with whenDone="linger".
waitingbooleanfalsetrue while the run waits for input, like an approval. Pass state.status === "waiting". The loader stays on screen and shows the "waiting" text and icon.
stoppedbooleanfalsetrue when someone cancelled the run. Pass state.status === "stopped". The parts show the "stopped" text and icon.
subagent
  • string
  • null
nullName of the subagent that sent the latest event. Pass state.subagentName. Only <AGUILoadingSubagent /> reads it.
Data attributeValueWhen
data-presencerunningThe agent works.
waitingThe run waits for input, like an approval. It stays until the next run, whatever whenDone says.
lingeringThe run ended (finished, failed or cancelled) and whenDone="linger". After lingerMs the loader removes itself.
doneThe run ended and whenDone="keep". The last text stays until the next run.

<AGUILoadingIcon />

A small icon for the latest event. With no byEvent it shows a spinner. The spinner stops when the run ends, and a pause circle replaces it while the run waits.

<AGUILoadingIcon
  byEvent={{
    [EventType.TOOL_CALL_START]: <Wrench className="size-3" />,
    [EventType.RUN_FINISHED]: <CircleCheck className="size-3" />,
  }}
/>
PropTypeDefaultWhat it does
byEvent{ [event]: ReactNode }–An icon per event. Keys can also be "waiting", "stopped" or "default". Use null to show no icon for that event.
fallbackReactNodespinnerThe icon for events that byEvent doesn't list.
waitingFallbackReactNodepause circleThe icon while the run waits, if byEvent has no "waiting" key.

<AGUILoadingText />

Short text for the latest event, like "Searching...". If you give one event several phrases, they take turns. Screen readers hear the first phrase once, not every change.

<AGUILoadingText
  animation="typing"
  byEvent={{
    [EventType.RUN_STARTED]: ["Waking up..."],
    [EventType.TOOL_CALL_START]: ["Searching...", "Still searching..."],
    default: ["Working on it..."],
  }}
/>
PropTypeDefaultWhat it does
byEvent{ [event]: string[] }–Phrases per event. Keys can also be "waiting", "stopped" or "default". Events you leave out use the built-in text.
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.

<AGUILoadingSubagent />

The name of the subagent behind the latest event, followed by a separator, like "researcher ·". It shows nothing while the main agent works. Needs the subagent prop on the root.

<AGUILoading subagent={state.subagentName} /* ... */>
  <AGUILoadingSubagent className="font-medium" />
  <AGUILoadingText />
</AGUILoading>
PropTypeDefaultWhat it does
separatorReactNode"·"Shown after the name. Pass null for none.

<AGUILoadingEvent />

The raw name of the latest event, e.g. TOOL_CALL_START. Handy while you build, so you can see which key to put in byEvent. Screen readers skip it.

No props of its own.