# Agent status

A run's live state in a pill, queued, running, waiting on you, done, failed or stopped, that fills as it goes and closes into its result.

Tier: free. Type: component. Category: ai. Tags: agent, run, motion.

## Install

```bash
npx shadcn@latest add https://pixilui.com/r/agent-status.json
```

One-time setup: add the registry to `components.json`:

```json
{
  "registries": {
    "@pixilui": "https://pixilui.com/r/{name}.json"
  }
}
```

Files: `components/pixilui/agent-status.tsx`.

## Preview

Live preview: https://pixilui.com/components/agent-status

Knobs:

- `state`: `live run`, `queued`, `running`, `waiting`, `done`, `failed`, `stopped`
- `size`: `md`, `sm`, `lg`
- `variant`: `badge`, `inline`

Signature: Turn a run Done and the badge never jumps: the spinner slows from its own angle, the ring fills inward into the check, and one glint crosses the pill.

Styles: `lively` (default), `quiet`, set with `data-style` on <html>. The item reads the style through the foundation; it needs no prop. Standalone files: lively https://pixilui.com/r/standalone/agent-status.tsx, quiet https://pixilui.com/r/standalone/agent-status.quiet.tsx.

## Code

`components/pixilui/agent-status.tsx`

```tsx
"use client";

/*
  Agent status, locked 27 Nov 2026 with every change through 28 Nov (design/explorations/components/locked/agent-status).
  Its look and motion are foundation.css section 8 (.pixilui-agent-status); this component writes the locked markup and
  plays a change the way the locked script does:

  Color     the pill's tint, its words and the mark go first, 150ms.
  Words     one quiet swap: the old words fade out with a 2px blur (exit time, in curve); the new words rise 2px as
            their blur melts, 60ms later (move time, swap curve). The width follows over 260ms: growing on the out curve
            (it opens before the longer words land), narrowing on the in-out curve (it waits for the old words to go).
  Ring      leaving the spinner, the arc keeps its angle and slows to a stop while it grows into the ring; entering it,
            the first half turn speeds up from rest. Done and failed fill the ring inward, then the result draws.
  Finish    done sends one glint across the pill; failed shakes once. Running repeats the glint every 2.4s with a light
            band through the words, the first sweep 600ms in.
  Rest      one-shot motion plays only after a real change (data-changed), never on first render.
  Reduced   no loops, results drawn, words swapped at once.
*/

import { forwardRef, useCallback, useEffect, useLayoutEffect, useRef, useState, type ComponentPropsWithoutRef, type CSSProperties } from "react";
import { cn } from "./lib/utils";
import { prefersReducedMotion } from "./lib/motion/reduced-motion";
import { safeAnimate } from "./lib/motion/animate";

export type AgentStatusState = "queued" | "running" | "waiting" | "done" | "failed" | "stopped";
export type AgentStatusSize = "sm" | "md" | "lg";
export type AgentStatusVariant = "badge" | "inline";

/** A chat's status, by the Vercel AI SDK's names (our own type: nothing here imports the SDK). */
export type AgentChatStatus = "submitted" | "streaming" | "ready" | "error";
/** A tool call's state, by the Vercel AI SDK's names. */
export type AgentToolState = "input-streaming" | "input-available" | "output-available" | "output-error";

/** The run state for a chat's status: submitted is queued, streaming is running, ready is done, error is failed. */
export function agentStatusFromChat(status: AgentChatStatus): AgentStatusState {
  return ({ submitted: "queued", streaming: "running", ready: "done", error: "failed" } as const)[status];
}

/** The run state for a tool call: input-streaming is queued, input-available is running, output-available is done, output-error is failed. */
export function agentStatusFromTool(state: AgentToolState): AgentStatusState {
  return ({ "input-streaming": "queued", "input-available": "running", "output-available": "done", "output-error": "failed" } as const)[state];
}

/** The locked default words. Pass your own (translated) through labels or label. */
export const AgentStatusLabels: Record<AgentStatusState, string> = {
  queued: "Queued",
  running: "Running",
  waiting: "Waiting on you",
  done: "Done",
  failed: "Failed",
  stopped: "Stopped",
};

export type AgentStatusProps = Omit<ComponentPropsWithoutRef<"span">, "children"> & {
  /** The run's state. Changing it plays the change: the color first, then the shape and the words. */
  state: AgentStatusState;
  /** The words, when they are not the state's own ("Refunded", "Needs you"). Changing them plays the quiet swap. */
  label?: string;
  /** The words for each state, for translation. Defaults to AgentStatusLabels. */
  labels?: Partial<Record<AgentStatusState, string>>;
  /** A second tone after the words: a share ("42%") or a time ("2:14"). Tabular figures. */
  meta?: string;
  /** Share done, 0 to 100. Running and waiting draw an arc at it; running without it is a plain spinner. */
  progress?: number | null;
  /** sm 24, md 30 (the chip size, default), lg 32. */
  size?: AgentStatusSize;
  /** badge, the pill (default), or inline: the mark and words with no pill. */
  variant?: AgentStatusVariant;
  /** A still copy: no loops, results drawn, no glint. */
  frozen?: boolean;
};

/** The mark: the locked 16-unit drawing, one ring for the run. */
function Mark() {
  return (
    <span className="pixilui-agent-status-mark" aria-hidden="true">
      <svg viewBox="0 0 16 16">
        <circle className="pixilui-agent-status-track" cx="8" cy="8" r="6.25" />
        <circle className="pixilui-agent-status-ring" cx="8" cy="8" r="6.25" pathLength={100} />
        <rect className="pixilui-agent-status-square" x="5.75" y="5.75" width="4.5" height="4.5" rx="1.1" />
        <circle className="pixilui-agent-status-disc" cx="8" cy="8" r="7.15" />
        <path className="pixilui-agent-status-check" pathLength={1} d="M5.2 8.2 7.1 10.05 10.8 6.3" />
        <path className="pixilui-agent-status-bang" pathLength={1} d="M8 4.85V8.6" />
        <circle className="pixilui-agent-status-bang-dot" cx="8" cy="11" r=".95" />
      </svg>
    </span>
  );
}

const read = (el: Element, name: string) => getComputedStyle(el).getPropertyValue(name).trim();
const ms = (el: Element, name: string) => parseFloat(read(el, name));

/** The words and meta, as DOM nodes (the locked words(label, meta)). */
function wordsInto(span: HTMLElement, label: string, meta?: string) {
  span.append(document.createTextNode(label));
  if (meta) {
    const m = document.createElement("span");
    m.className = "pixilui-agent-status-meta";
    m.textContent = meta;
    span.append(m);
  }
}

/**
 * The quiet word swap (28 Nov), for any text that changes with a status: the old words fade out with a little blur, the
 * new words rise 2px as their blur melts, 60ms later; with glide the box's width follows, opening first when it grows and
 * waiting when it narrows. box holds one span of words; the new span gets data-label = label.
 */
export function swapStatusText(box: HTMLElement, label: string, meta?: string, { glide = false }: { glide?: boolean } = {}) {
  box.querySelectorAll(":scope > [data-out]").forEach((e) => e.remove());
  const old = box.querySelector<HTMLElement>(":scope > span:not([data-out])");
  const next = document.createElement("span");
  wordsInto(next, label, meta);
  next.dataset.label = label;
  if (prefersReducedMotion() || !old || typeof next.animate !== "function") {
    old?.remove();
    box.append(next);
    return;
  }
  old.getAnimations().forEach((a) => a.cancel());
  const w0 = box.getBoundingClientRect().width;
  // states first: the running shimmer steps aside while words move
  old.removeAttribute("data-in");
  old.dataset.out = "";
  old.removeAttribute("data-label");
  next.dataset.in = "";
  box.append(next);
  const w1 = next.getBoundingClientRect().width;
  const blur = `blur(${read(box, "--pixilui-blur-in")})`;
  safeAnimate(old, [{ opacity: 1, filter: "blur(0px)" }, { opacity: 0, filter: blur }], { duration: ms(box, "--pixilui-dur-exit"), easing: read(box, "--pixilui-ease-in"), fill: "forwards" })
    .finished.then(() => old.remove())
    .catch(() => {});
  safeAnimate(next, [{ opacity: 0, filter: blur, transform: `translateY(${read(box, "--pixilui-agent-status-text-rise")})` }, { opacity: 1, filter: "blur(0px)", transform: "none" }], {
      duration: ms(box, "--pixilui-dur-move"),
      delay: ms(box, "--pixilui-agent-status-text-lag"),
      easing: read(box, "--pixilui-ease-swap"),
      fill: "backwards",
    })
    .finished.then(() => {
      if (next.isConnected && "in" in next.dataset) delete next.dataset.in;
    })
    .catch(() => {});
  if (glide && Math.abs(w1 - w0) > 0.5)
    safeAnimate(box, [{ width: `${w0}px` }, { width: `${w1}px` }], { duration: ms(box, "--pixilui-agent-status-width-time"), easing: read(box, w1 > w0 ? "--pixilui-ease-out" : "--pixilui-ease-move") });
}

/** Leaving the spinner: reads the arc's angle before the state moves on, and returns the move that carries it. */
function settle(el: HTMLElement, next: AgentStatusState) {
  const ring = el.querySelector<SVGElement>(".pixilui-agent-status-ring");
  if (!ring || el.dataset.state !== "running" || "progress" in el.dataset || next === "running" || next === "queued" || prefersReducedMotion() || typeof DOMMatrixReadOnly === "undefined") return null;
  const m = new DOMMatrixReadOnly(getComputedStyle(ring).transform);
  const a0 = (Math.atan2(m.b, m.a) * 180) / Math.PI;
  return () => {
    const dur = ms(el, "--pixilui-agent-status-fill");
    const turn = ms(el, "--pixilui-agent-status-turn");
    const ease = read(el, "--pixilui-ease-out");
    const [x1, y1] = (ease.match(/[\d.]+/g) ?? [".23", "1"]).map(Number) as [number, number];
    safeAnimate(ring, [{ transform: `rotate(${a0}deg)` }, { transform: `rotate(${a0 + ((360 / turn) * dur) / (y1 / x1)}deg)` }], { duration: dur, easing: ease });
  };
}

function setProgress(el: HTMLElement, p: number | null | undefined) {
  if (p == null) {
    delete el.dataset.progress;
    el.style.removeProperty("--pixilui-agent-status-progress");
  } else {
    el.dataset.progress = "";
    el.style.setProperty("--pixilui-agent-status-progress", String(p));
  }
}

/** Replays a one-shot state attribute (the shake, the glint). */
function replay(el: HTMLElement, name: "shake" | "glint") {
  delete el.dataset[name];
  void el.offsetWidth;
  el.dataset[name] = "";
}

export type AgentStatusSimulationStep = { state: AgentStatusState; progress?: number | null; meta?: string; at: number };
export type AgentStatusSimulation = { state: AgentStatusState; progress: number | null; meta?: string; restart: () => void };

/** A believable run, at human speed: queued, then running in reports (a share each), a pause for you, and done in 2:14. */
export const AgentStatusRun: AgentStatusSimulationStep[] = [
  { state: "queued", at: 0 },
  { state: "running", progress: 12, meta: "12%", at: 800 },
  { state: "running", progress: 31, meta: "31%", at: 1600 },
  { state: "running", progress: 48, meta: "48%", at: 2400 },
  { state: "waiting", progress: 48, at: 3300 },
  { state: "running", progress: 74, meta: "74%", at: 5200 },
  { state: "running", progress: 100, meta: "100%", at: 6000 },
  { state: "done", progress: null, meta: "2:14", at: 6800 },
];

/** Plays a run through the states for demos and tests (plain data out, no model call). Pass steps for your own run. */
export function useAgentStatusSimulation({ steps = AgentStatusRun, autoplay = true }: { steps?: AgentStatusSimulationStep[]; autoplay?: boolean } = {}): AgentStatusSimulation {
  const [at, setAt] = useState(0);
  const [run, setRun] = useState(autoplay ? 1 : 0);
  useEffect(() => {
    if (!run) return;
    const timers = steps.slice(1).map((step, i) => setTimeout(() => setAt(i + 1), step.at));
    return () => timers.forEach(clearTimeout);
  }, [run, steps]);
  const step = steps[at] ?? steps[0]!;
  return {
    state: step.state,
    progress: step.progress ?? null,
    meta: step.meta,
    restart: () => {
      setAt(0);
      setRun((n) => n + 1);
    },
  };
}

/** What an agent run is doing right now: queued, running, waiting on you, done, failed or stopped, in a pill or inline. */
export const AgentStatus = forwardRef<HTMLSpanElement, AgentStatusProps>(function AgentStatus(
  { state, label, labels, meta, progress, size = "md", variant = "badge", frozen, className, style, ...props },
  forwarded,
) {
  const words = label ?? labels?.[state] ?? AgentStatusLabels[state];
  const ref = useRef<HTMLSpanElement | null>(null);
  // React writes the first state, words and progress; every later change goes through the effect, in the locked order
  // (read the spinner's angle, then progress, then the state, then the words).
  const [first] = useState(() => ({ state, words, meta, progress }));
  const setRef = useCallback(
    (el: HTMLSpanElement | null) => {
      ref.current = el;
      if (typeof forwarded === "function") forwarded(el);
      else if (forwarded) forwarded.current = el;
    },
    [forwarded],
  );
  const seen = useRef({ progress: first.progress });
  useLayoutEffect(() => {
    const el = ref.current;
    if (!el) return;
    const same = el.dataset.state === state;
    const progressChanged = seen.current.progress !== progress;
    const box = el.querySelector<HTMLElement>(".pixilui-agent-status-label")!;
    const cur = box.querySelector<HTMLElement>(":scope > span:not([data-out])");
    const curText = cur ? (cur.dataset.label ?? (cur.firstChild?.nodeType === 3 ? cur.firstChild.textContent : cur.textContent) ?? "") : "";
    const curMeta = cur?.querySelector(".pixilui-agent-status-meta")?.textContent ?? undefined;
    if (same && curText === words && curMeta === meta && !progressChanged) return;
    const carry = same ? null : settle(el, state);
    if (progressChanged) setProgress(el, progress);
    seen.current.progress = progress;
    if (!same) el.dataset.changed = "";
    el.dataset.state = state;
    carry?.();
    if (same && curText === words) {
      // only the meta changed: update in place
      let m = cur?.querySelector<HTMLElement>(".pixilui-agent-status-meta") ?? null;
      if (meta && !m && cur) {
        m = document.createElement("span");
        m.className = "pixilui-agent-status-meta";
        cur.append(m);
      }
      if (m) {
        if (meta) m.textContent = meta;
        else m.remove();
      }
      return;
    }
    swapStatusText(box, words, meta, { glide: true });
    if (prefersReducedMotion()) return;
    if (state === "failed") replay(el, "shake");
    if (state === "done" && el.dataset.variant !== "inline") replay(el, "glint");
  }, [state, words, meta, progress]);
  const hasProgress = first.progress != null;
  return (
    <span
      ref={setRef}
      className={cn("pixilui-agent-status", className)}
      role="status"
      data-state={first.state}
      data-size={size === "md" ? undefined : size}
      data-variant={variant === "inline" ? "inline" : undefined}
      data-frozen={frozen ? "" : undefined}
      data-progress={hasProgress ? "" : undefined}
      style={hasProgress ? ({ "--pixilui-agent-status-progress": first.progress, ...style } as CSSProperties) : style}
      {...props}
    >
      <Mark />
      <span className="pixilui-agent-status-label">
        <span data-label={first.words}>
          {first.words}
          {first.meta ? <span className="pixilui-agent-status-meta">{first.meta}</span> : null}
        </span>
      </span>
    </span>
  );
});
```

## Usage

When to use:

- Run lists, tables, tool call logs and run headers: anywhere a run, task or tool call has a live state.
- Running with a known share done: pass progress and meta ("42%").
- A finished run with its time: state="done" meta="2:14".

When not to use:

- A state that never changes: write plain text.
- Tight places with words beside it already (logs, table cells): use Status dot, the same node without the pill.
- Warnings and errors about a form: use the field's message.

```tsx
import { AgentStatus, useAgentStatusSimulation, type AgentStatusState } from "@/components/pixilui/agent-status";

// The first option of each knob is the demo's default; the docs preview starts there.
export const knobs = {
  state: ["live run", "queued", "running", "waiting", "done", "failed", "stopped"],
  size: ["md", "sm", "lg"],
  variant: ["badge", "inline"],
} as const;

const rows: { name: string; meta: Partial<Record<AgentStatusState, string>> }[] = [
  { name: "Refund ticket 4471", meta: { running: "42%", done: "2:14" } },
  { name: "Weekly churn digest", meta: { done: "0:48" } },
  { name: "Migrate billing tables", meta: { running: "3 of 7" } },
];

/** A run list: the first row plays a live run (queued, running in reports, a pause for you, done); the state knob holds every row in one state. */
export default function AgentStatusDemo({ state = "live run", size = "md", variant = "badge" }: KnobValues<typeof knobs>) {
  const run = useAgentStatusSimulation();
  return (
    <ul className="flex w-full max-w-md flex-col rounded-panel bg-surface p-2 elevation-raised">
      {rows.map((row, i) => {
        const live = state === "live run";
        const s: AgentStatusState = live ? (i === 0 ? run.state : i === 1 ? "done" : "queued") : state;
        return (
          <li key={row.name} className="flex items-center justify-between gap-3 rounded-control px-3 py-2">
            <span className="type-label truncate text-foreground">{row.name}</span>
            <AgentStatus
              state={s}
              size={size}
              variant={variant}
              progress={live && i === 0 ? run.progress : s === "running" && i === 0 ? 42 : null}
              meta={live && i === 0 ? run.meta : row.meta[s]}
            />
          </li>
        );
      })}
    </ul>
  );
}
```

## Examples

None.

## API

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `state` (required) | `"queued" \| "running" \| "waiting" \| "done" \| "failed" \| "stopped"` |  | The run's state. Changing it plays the change: the color first, then the shape and the words. |
| `label` | `string` |  | The words, when they are not the state's own ("Refunded", "Needs you"). Changing them plays the quiet swap. |
| `labels` | `Partial<Record<AgentStatusState, string>>` |  | The words for each state, for translation. Defaults to AgentStatusLabels. |
| `meta` | `string` |  | A second tone after the words: a share ("42%") or a time ("2:14"). Tabular figures. |
| `progress` | `number \| null` |  | Share done, 0 to 100. Running and waiting draw an arc at it; running without it is a plain spinner. |
| `size` | `"sm" \| "md" \| "lg"` | `"md"` | sm 24, md 30 (the chip size, default), lg 32. |
| `variant` | `"badge" \| "inline"` | `"badge"` | badge, the pill (default), or inline: the mark and words with no pill. |
| `frozen` | `boolean` |  | A still copy: no loops, results drawn, no glint. |

Also accepts every native `<span>` attribute, and a ref to it.

## Keyboard

- `Tab`: Never takes focus: the pill is not interactive. The control it sits in owns focus.

## Accessibility

- The root is role="status", so a change of words is announced politely; the mark is aria-hidden and the words carry the meaning.
- Color is never the only signal: each state has its own words and its own mark shape (dashes, arc, check, exclamation, square).
- All words pass 4.5:1 on their pill in light and dark, and on the surface inline.

## Motion

- The tint, words and mark change color first (150ms), then the shape carries on from where it was.
- Words swap quietly: the old fade out with a 2px blur, the new rise 2px as their blur melts, 60ms later; the width follows over 260ms, opening first when it grows and waiting when it narrows.
- Leaving running, the spinner keeps its angle and slows to a stop while the ring closes; done and failed fill the ring inward, then the check or exclamation draws. Done sends one glint across the pill; failed shakes once.
- Running repeats a glint every 2.4s with a light band through the words; waiting breathes a halo. Nothing plays on first render.
- Reduced motion: no loops, results drawn, words swapped at once.

## Responsive

- Sizes sm 24, md 30 (the chip size), lg 32; inline is a 28 row. The pill is as wide as its words and never wraps.

## Performance

- Look and motion are CSS in the foundation (section 8). A change reads one transform and runs two short Web Animations on the words.

## Notes for AI

- <AgentStatus state="running" progress={42} meta="42%" />. States: queued, running, waiting (on the person), done, failed, stopped.
- From the Vercel AI SDK: agentStatusFromChat(status) maps submitted, streaming, ready, error; agentStatusFromTool(state) maps input-streaming, input-available, output-available, output-error. Nothing imports from ai.
- Keep one element and change its props: the change plays from where it is. Re-keying it skips the motion.
- Words are props: label for this one ("Refunded"), labels for every state (translation). meta is the second tone (a share or a time).
- useAgentStatusSimulation() plays a believable run for demos and tests; pass steps for your own.
- swapStatusText(box, words, meta, { glide }) is the same quiet swap for any text that changes with a status.
- variant="inline" is the mark and words with no pill; its words turn to the hue only for waiting and failed.
- Per-style rule: in quiet the pill takes the control corner and a hairline ring in its hue instead of the fade (foundation.css section 8, quiet hook).

## Related

- [Status dot](https://pixilui.com/components/status-dot/markdown): The one mark for a run's state, queued, running, waiting on you, done, failed or stopped, at four sizes, so a plan, a log and an inbox read the same.
- [Badge](https://pixilui.com/components/badge/markdown): A fixed fact about a run as a tag, a badge inline in a table, or a small count beside a name, in the locked status colors with solid icons cut from the free Hugeicons.
