Agent Activity

One stream for reasoning, searches, tool calls and traces.

Streaming Text

index.tsx
"use client";

import { RotateCcw } from "lucide-react";
import { useReducedMotion } from "motion/react";
import { useEffect, useState } from "react";
import {
  AgentActivity,
  type AgentActivityItem,
} from "@/components/agents/agent-activity";

const REASONING = [
  "Reading the request and separating the content model from its presentation.",
  "The activity shell can stay consistent while each event supplies its own compact renderer.",
  "Text remains freeform so partial tokens can update without recreating the surrounding timeline.",
  "As each sentence wraps, the measured stream moves upward through a single transform instead of repeatedly jumping the native scroll position.",
  "Older context stays available above the fold while the newest tokens remain crisp at the bottom edge.",
  "Once the run finishes, the viewport switches from automatic following to ordinary user-controlled scrolling.",
  "Opening the completed disclosure returns to the beginning so the reasoning can be read in order.",
  "The capped viewport follows the latest sentence and preserves the full log after completion.",
].join("\n");

const CHARACTERS_PER_SECOND = 90;
const STREAM_SECONDS = REASONING.length / CHARACTERS_PER_SECOND;

function StreamingTextDemo() {
  const reduce = useReducedMotion() ?? false;
  const [stream, setStream] = useState("");
  const [complete, setComplete] = useState(false);

  useEffect(() => {
    if (reduce) {
      setStream(REASONING);
      setComplete(true);
      return;
    }

    const startedAt = performance.now();
    let frame = 0;
    let completionTimer: number | undefined;

    const streamNextFrame = (now: number) => {
      const cursor = Math.min(
        REASONING.length,
        Math.floor(((now - startedAt) / 1000) * CHARACTERS_PER_SECOND),
      );
      const next = REASONING.slice(0, cursor);
      setStream((current) => (current === next ? current : next));

      if (cursor === REASONING.length) {
        completionTimer = window.setTimeout(() => setComplete(true), 500);
      } else {
        frame = requestAnimationFrame(streamNextFrame);
      }
    };

    frame = requestAnimationFrame(streamNextFrame);
    return () => {
      cancelAnimationFrame(frame);
      if (completionTimer) window.clearTimeout(completionTimer);
    };
  }, [reduce]);

  const items: AgentActivityItem[] = stream
    .split("\n")
    .filter(Boolean)
    .map((content, index) => ({
      id: `reasoning-${index}`,
      type: "text",
      content,
    }));

  return (
    <AgentActivity
      items={items}
      contentType="text"
      status={complete ? "complete" : "working"}
      duration={STREAM_SECONDS}
      defaultOpen={reduce}
      collapseOnComplete={!reduce}
      maxHeight={180}
    />
  );
}

export function AgentActivityTextPreview() {
  const [run, setRun] = useState(0);

  return (
    <div className="relative h-[330px] w-full max-w-lg">
      <StreamingTextDemo key={run} />
      <button
        type="button"
        onClick={() => setRun((current) => current + 1)}
        className="absolute bottom-0 left-0 inline-flex items-center gap-1.5 rounded-full px-2.5 py-1 text-xs font-medium text-muted-foreground outline-none transition-colors hover:bg-muted hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring"
      >
        <RotateCcw className="size-3" />
        Replay
      </button>
    </div>
  );
}

Reasoning Steps

index.tsx
"use client";

import { RotateCcw } from "lucide-react";
import { useReducedMotion } from "motion/react";
import { useEffect, useState } from "react";
import { AgentActivity } from "@/components/agents/agent-activity";

const STEPS = [
  { id: "brief", label: "Reading the product brief" },
  { id: "patterns", label: "Mapping the interaction patterns" },
  {
    id: "states",
    label: "Connecting the loading and completion states",
    meta: "3 states",
  },
  { id: "verify", label: "Verifying the final behavior" },
];

function StepsDemo() {
  const reduce = useReducedMotion() ?? false;
  const [visible, setVisible] = useState(reduce ? STEPS.length : 1);
  const [settled, setSettled] = useState(false);
  const [complete, setComplete] = useState(false);

  useEffect(() => {
    if (reduce) {
      setVisible(STEPS.length);
      setSettled(true);
      setComplete(true);
      return;
    }

    const stepTimers = STEPS.slice(1).map((_, index) =>
      window.setTimeout(() => setVisible(index + 2), 850 + index * 800),
    );
    const settleTimer = window.setTimeout(() => setSettled(true), 3300);
    const completeTimer = window.setTimeout(() => setComplete(true), 4200);
    return () => {
      stepTimers.forEach(window.clearTimeout);
      window.clearTimeout(settleTimer);
      window.clearTimeout(completeTimer);
    };
  }, [reduce]);

  return (
    <AgentActivity
      status={complete ? "complete" : "working"}
      contentType="step"
      duration={4.2}
      defaultOpen={reduce}
      collapseOnComplete={!reduce}
      maxHeight={220}
      items={STEPS.slice(0, visible).map((step, index) => ({
        ...step,
        type: "step" as const,
        status:
          settled || index < visible - 1
            ? ("complete" as const)
            : ("active" as const),
      }))}
    />
  );
}

export function AgentActivityStepsPreview() {
  const [run, setRun] = useState(0);

  return (
    <div className="relative h-[330px] w-full max-w-lg">
      <StepsDemo key={run} />
      <button
        type="button"
        onClick={() => setRun((current) => current + 1)}
        className="absolute bottom-0 left-0 inline-flex items-center gap-1.5 rounded-full px-2.5 py-1 text-xs font-medium text-muted-foreground outline-none transition-colors hover:bg-muted hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring"
      >
        <RotateCcw className="size-3" />
        Replay
      </button>
    </div>
  );
}

Tool Calls

index.tsx
"use client";

import { RotateCcw } from "lucide-react";
import { useReducedMotion } from "motion/react";
import { useEffect, useState } from "react";
import {
  AgentActivity,
  type AgentActivityItem,
} from "@/components/agents/agent-activity";

const TOOLS: AgentActivityItem[] = [
  {
    id: "read",
    type: "tool",
    action: "read",
    target: "campaign-notes.md",
  },
  {
    id: "edit",
    type: "tool",
    action: "edit",
    target: "launch-plan.ts",
    additions: 42,
    deletions: 8,
  },
  {
    id: "run",
    type: "tool",
    action: "run",
    target: "bun test launch",
  },
];

function ToolsDemo() {
  const reduce = useReducedMotion() ?? false;
  const [visible, setVisible] = useState(0);
  const [complete, setComplete] = useState(false);

  useEffect(() => {
    if (reduce) {
      setVisible(TOOLS.length);
      setComplete(true);
      return;
    }

    const toolTimers = TOOLS.map((_, index) =>
      window.setTimeout(() => setVisible(index + 1), 550 + index * 850),
    );
    const completeTimer = window.setTimeout(() => setComplete(true), 3600);
    return () => {
      toolTimers.forEach(window.clearTimeout);
      window.clearTimeout(completeTimer);
    };
  }, [reduce]);

  return (
    <AgentActivity
      status={complete ? "complete" : "working"}
      contentType="tool"
      defaultOpen={reduce}
      collapseOnComplete={!reduce}
      maxHeight={220}
      items={TOOLS.slice(0, visible)}
    />
  );
}

export function AgentActivityToolsPreview() {
  const [run, setRun] = useState(0);

  return (
    <div className="relative h-[330px] w-full max-w-lg">
      <ToolsDemo key={run} />
      <button
        type="button"
        onClick={() => setRun((current) => current + 1)}
        className="absolute bottom-0 left-0 inline-flex items-center gap-1.5 rounded-full px-2.5 py-1 text-xs font-medium text-muted-foreground outline-none transition-colors hover:bg-muted hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring"
      >
        <RotateCcw className="size-3" />
        Replay
      </button>
    </div>
  );
}

Mixed Activity

index.tsx
"use client";

import { RotateCcw } from "lucide-react";
import { useReducedMotion } from "motion/react";
import { useEffect, useState } from "react";
import {
  AgentActivity,
  type AgentActivityItem,
} from "@/components/agents/agent-activity";

const ACTIVE_BRIEF: AgentActivityItem = {
  id: "brief",
  type: "step",
  label: "Reading the launch brief",
  status: "active",
};

const COMPLETE_BRIEF: AgentActivityItem = {
  ...ACTIVE_BRIEF,
  status: "complete",
};

const PENDING_SEARCH: AgentActivityItem = {
  id: "search",
  type: "search",
  query: "independent coffee roasters in Portland",
  results: [],
};

const COMPLETE_SEARCH: AgentActivityItem = {
  ...PENDING_SEARCH,
  results: [
    { id: "heart", title: "Heart Coffee", domain: "heartroasters.com" },
    {
      id: "coava",
      title: "Coava Coffee",
      domain: "coavacoffee.com",
    },
    {
      id: "upper-left",
      title: "Upper Left Roasters",
      domain: "upperleftroasters.com",
    },
  ],
  moreCount: 5,
};

const READ_TOOL: AgentActivityItem = {
  id: "read",
  type: "tool",
  action: "read",
  target: "campaign-notes.md",
};

const ACTIVITY_FRAMES: AgentActivityItem[][] = [
  [ACTIVE_BRIEF],
  [COMPLETE_BRIEF, PENDING_SEARCH],
  [COMPLETE_BRIEF, COMPLETE_SEARCH],
  [COMPLETE_BRIEF, COMPLETE_SEARCH, READ_TOOL],
  [
    COMPLETE_BRIEF,
    COMPLETE_SEARCH,
    READ_TOOL,
    {
      id: "edit",
      type: "tool",
      action: "edit",
      target: "launch-plan.ts",
      additions: 42,
      deletions: 8,
    },
    { id: "run", type: "tool", action: "run", target: "bun test launch" },
    {
      id: "verify",
      type: "step",
      label: "Checking the final campaign plan",
      status: "complete",
    },
  ],
];

function ActivityDemo() {
  const reduce = useReducedMotion() ?? false;
  const [frame, setFrame] = useState(0);
  const [complete, setComplete] = useState(false);

  useEffect(() => {
    if (reduce) {
      setFrame(ACTIVITY_FRAMES.length - 1);
      setComplete(true);
      return;
    }

    const timers = ACTIVITY_FRAMES.slice(1).map((_, index) =>
      window.setTimeout(() => setFrame(index + 1), 850 + index * 1050),
    );
    const finalFrameAt = 850 + (ACTIVITY_FRAMES.length - 2) * 1050;
    const completeTimer = window.setTimeout(
      () => setComplete(true),
      finalFrameAt + 900,
    );
    return () => {
      timers.forEach(window.clearTimeout);
      window.clearTimeout(completeTimer);
    };
  }, [reduce]);

  return (
    <AgentActivity
      items={ACTIVITY_FRAMES[frame]}
      status={complete ? "complete" : "working"}
      duration={5.1}
      defaultOpen={reduce}
      collapseOnComplete={!reduce}
      maxHeight={220}
    />
  );
}

export function AgentActivityMixedPreview() {
  const [run, setRun] = useState(0);

  return (
    <div className="relative h-[330px] w-full max-w-xl">
      <ActivityDemo key={run} />
      <button
        type="button"
        onClick={() => setRun((current) => current + 1)}
        className="absolute bottom-0 left-0 inline-flex items-center gap-1.5 rounded-full px-2.5 py-1 text-xs font-medium text-muted-foreground outline-none transition-colors hover:bg-muted hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring"
      >
        <RotateCcw className="size-3" />
        Replay
      </button>
    </div>
  );
}

Agent Trace

index.tsx
"use client";

import { RotateCcw } from "lucide-react";
import { useReducedMotion } from "motion/react";
import { useEffect, useState } from "react";
import {
  AgentActivity,
  type AgentActivityItem,
} from "@/components/agents/agent-activity";

const TRACE_ITEMS: AgentActivityItem[] = [
  {
    id: "plan",
    type: "trace",
    kind: "thinking",
    label: "Thinking",
    detail: "Mapping the interaction flow…",
  },
  {
    id: "decision",
    type: "trace",
    kind: "message",
    label: "Decision",
    detail: "Use one compact disclosure",
  },
  {
    id: "write",
    type: "trace",
    kind: "write",
    label: "Draft component",
    detail: "components/agents/run-log.tsx",
  },
  {
    id: "verify",
    type: "trace",
    kind: "run",
    label: "Validate types",
    detail: "bun run typecheck",
  },
  {
    id: "inspect",
    type: "trace",
    kind: "read",
    label: "Inspect preview",
    detail: "activity-preview.png",
  },
];

function AgentTraceDemo() {
  const reduce = useReducedMotion() ?? false;
  const [visible, setVisible] = useState(reduce ? TRACE_ITEMS.length : 0);
  const [complete, setComplete] = useState(reduce);

  useEffect(() => {
    if (reduce) return;

    const timers = TRACE_ITEMS.map((_, index) =>
      window.setTimeout(() => setVisible(index + 1), 250 + index * 650),
    );
    timers.push(
      window.setTimeout(
        () => setComplete(true),
        250 + TRACE_ITEMS.length * 650,
      ),
    );
    return () => timers.forEach(window.clearTimeout);
  }, [reduce]);

  return (
    <AgentActivity
      items={TRACE_ITEMS.slice(0, visible)}
      contentType="trace"
      status={complete ? "complete" : "working"}
      activeLabel="Running the agent trace…"
      defaultOpen={reduce}
      collapseOnComplete={!reduce}
      maxHeight={190}
    />
  );
}

export function AgentTracePreview() {
  const [run, setRun] = useState(0);

  return (
    <div className="relative h-[300px] w-full max-w-xl">
      <AgentTraceDemo key={run} />
      <button
        type="button"
        onClick={() => setRun((value) => value + 1)}
        className="absolute bottom-0 left-0 inline-flex items-center gap-1.5 rounded-full px-2.5 py-1 text-xs font-medium text-muted-foreground outline-none transition-colors hover:bg-muted hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring"
      >
        <RotateCcw className="size-3" />
        Replay
      </button>
    </div>
  );
}

API Reference

items
AgentActivityItem[]

Chronological activity entries. Append or update items as events stream.

contentType?
"search" | "text" | "mixed" | "step" | "tool" | "trace"

Expected activity kind before the first streamed item arrives.

status?
"working" | "complete"

Current run phase. Active runs always stay expanded.

Defaultworking
duration?
number

Elapsed run time, in seconds. Used by the step-only summary.

Default0
open?
boolean

Controlled expanded state used after the run completes.

defaultOpen?
boolean

Initial expanded state used after the run completes.

Defaultfalse
onOpenChange?
((open: boolean) => void)

Called when the completed activity disclosure changes state.

collapseOnComplete?
boolean

Collapse the disclosure when status changes from working to complete.

Defaulttrue
activeLabel?
ReactNode

Optional label shown while the run is active.

summary?
ReactNode

Optional completed summary. Derived from the item types by default.

renderWorkingStatus?
((context: { label: ReactNode; duration: number; }) => ReactNode)

Optional renderer for the contents of the active status row.

renderCompletedStatus?
((context: { summary: ReactNode; duration: number; }) => ReactNode)

Optional renderer for the contents before the built-in disclosure chevron.

maxHeight?
number

Maximum visible activity height before the stream begins gliding.

Default208
labels?
Partial<{ thinking: string; searching: string; runningTools: string; workingTrace: string; workingMixed: string; thoughtFor: string; seconds: string; minutes: string; minutesSeconds: string; searched: string; ... 13 more ...; run: string; }>

Override any built-in string. Pick `One`/`Other` keys by count; `{count}`, `{duration}`, `{seconds}` and `{minutes}` fill the matching messages.

className?
string

Classes merged onto the root element.

contentClassName?
string

Classes merged onto the list of activity items.

Install

Add it with the shadcn CLI, or copy the source manually.

$ bunx --bun shadcn add @beui/agent-activity

Composition

Render progressive work as message content so it remains attached to the turn that produced it.

Message
└── MessageContent
    └── AgentActivity

Note: Agent Loading States covers the interval before the first structured event. Todo List separates durable planned work from transient events. Tool Result expands one completed execution into inspectable output.

How it works

Agent activity explains how work is progressing without exposing an unfiltered internal transcript. Events should arrive chronologically, remain easy to scan, and reduce to a useful summary when the run finishes.

Also on React Native. Steps, searches and tool calls in one live log.

Updated