Agent activity timeline
What an agent did, in order: tokens, tool calls, approvals and refusals, each with its trace.
The audit record of one agent, in a form that a person can read. Use it on the page of an agent and after an incident. Events of one task stand together, and each can link to its trace.
Installation
- CLI
- Manual
The command adds the file to your project, with the shadcn/ui components that it uses. Your project needs shadcn/ui.
- pnpm
- npm
- yarn
- bun
pnpm dlx shadcn@latest add https://examples.lumoauth.dev/r/agent-activity.json
npx shadcn@latest add https://examples.lumoauth.dev/r/agent-activity.json
yarn dlx shadcn@latest add https://examples.lumoauth.dev/r/agent-activity.json
bunx --bun shadcn@latest add https://examples.lumoauth.dev/r/agent-activity.json
Add the shadcn/ui components that the pattern uses.
npx shadcn@latest add badge buttonInstall the packages.
npm install lucide-reactCopy the code into your project.
components/agent-activity.tsx'use client';import * as React from 'react';import { Activity, Ban, Check, Hand, TriangleAlert, UserRound, Waypoints } from 'lucide-react';import { Badge } from '@/components/ui/badge';import { Button } from '@/components/ui/button';import { cn } from '@/lib/utils';export type ActivityOutcome = 'success' | 'refused' | 'approval' | 'failed';export interface ActivityEvent {id: string;/** When it happened (ISO 8601). */time: string;/** The event type of the audit log, for example `oauth.token_exchange`. */type: string;/** The event in plain words. */summary: string;outcome: ActivityOutcome;/** The reason of a refusal or a failure. */reason?: string | null;/** The person that the agent acted for. */onBehalfOf?: string | null;/** Events with the same task are shown as one group. */taskId?: string | null;taskName?: string | null;/** The trace ID that LumoAuth stored with the audit row. */traceId?: string | null;}const OUTCOME = {success: { icon: Check, tone: 'text-emerald-700 dark:text-emerald-400', label: 'Allowed' },refused: { icon: Ban, tone: 'text-red-700 dark:text-red-400', label: 'Refused' },approval: { icon: Hand, tone: 'text-amber-700 dark:text-amber-400', label: 'Approval' },failed: { icon: TriangleAlert, tone: 'text-red-700 dark:text-red-400', label: 'Failed' },} as const;type Filter = 'all' | 'refused' | 'approval';export interface AgentActivityProps {/** The events, newest first. */events: ActivityEvent[];/** Builds the link to a trace in your tracing tool. */traceHref?: (traceId: string) => string;/** Load older events. The button appears when you pass it. */onLoadMore?: () => void;className?: string;}export function AgentActivity({ events, traceHref, onLoadMore, className }: AgentActivityProps) {const [filter, setFilter] = React.useState<Filter>('all');const shown = events.filter((e) => filter === 'all' || (filter === 'refused' ? e.outcome === 'refused' || e.outcome === 'failed' : e.outcome === 'approval'));// Group neighbours that belong to one task, and keep the order of time.const groups: Array<{ key: string; name: string | null; events: ActivityEvent[] }> = [];for (const event of shown) {const last = groups[groups.length - 1];if (last && event.taskId && last.key === event.taskId) last.events.push(event);else groups.push({ key: event.taskId ?? event.id, name: event.taskId ? event.taskName ?? event.taskId : null, events: [event] });}const refusals = events.filter((e) => e.outcome === 'refused' || e.outcome === 'failed').length;const clock = (iso: string) => new Date(iso).toLocaleTimeString([], { hour: '2-digit', minute: '2-digit', second: '2-digit' });return (<section className={cn('w-full max-w-xl rounded-xl border bg-card text-sm text-card-foreground shadow-sm', className)} aria-label="Agent activity"><header className="flex flex-wrap items-center justify-between gap-2 border-b px-4 py-3"><h2 className="flex items-center gap-2 font-semibold"><Activity className="size-4" aria-hidden="true" />Activity</h2><div className="flex gap-1" role="group" aria-label="Filter">{([['all', 'All'], ['refused', `Refused${refusals ? ` (${refusals})` : ''}`], ['approval', 'Approvals']] as const).map(([key, label]) => (<Button key={key} size="sm" variant={filter === key ? 'secondary' : 'ghost'} onClick={() => setFilter(key)}>{label}</Button>))}</div></header>{shown.length === 0 ? (<p className="px-4 py-10 text-center text-muted-foreground">{events.length === 0 ? 'This agent has done nothing yet.' : 'No event matches this filter.'}</p>) : (<div className="grid">{groups.map((group) => (<div key={`${group.key}-${group.events[0].id}`} className="border-b last:border-b-0">{group.name && (<p className="flex items-center gap-2 bg-muted/40 px-4 py-1.5 text-xs font-medium text-muted-foreground">Task <span className="font-mono">{group.name}</span></p>)}<ol>{group.events.map((event) => {const { icon: Icon, tone, label } = OUTCOME[event.outcome];return (<li key={event.id} className="flex gap-3 px-4 py-2.5"><span className={cn('mt-0.5 flex size-5 shrink-0 items-center justify-center', tone)} title={label}><Icon className="size-4" aria-hidden="true" /><span className="sr-only">{label}:</span></span><div className="grid min-w-0 flex-1 gap-0.5"><p>{event.summary}</p>{event.reason && <p className={tone}>{event.reason}</p>}<p className="flex flex-wrap items-center gap-x-3 gap-y-0.5 text-xs text-muted-foreground"><time dateTime={event.time} className="tabular-nums" suppressHydrationWarning>{clock(event.time)}</time><span className="font-mono">{event.type}</span>{event.onBehalfOf && (<span className="flex items-center gap-1"><UserRound className="size-3" aria-hidden="true" />{event.onBehalfOf}</span>)}{event.traceId && traceHref && (<a href={traceHref(event.traceId)} className="flex items-center gap-1 underline underline-offset-4 hover:text-foreground"><Waypoints className="size-3" aria-hidden="true" />Trace</a>)}</p></div></li>);})}</ol></div>))}</div>)}{onLoadMore && shown.length > 0 && (<footer className="border-t p-2 text-center"><Button variant="ghost" size="sm" onClick={onLoadMore}>Show older events</Button></footer>)}</section>);}Change the import paths if your project keeps its components in another place.
Usage
Map the audit events of your organization to the events of the timeline.
import { AgentActivity, type ActivityEvent } from '@/components/agent-activity';
export function Activity({ events, onLoadMore }: { events: ActivityEvent[]; onLoadMore: () => void }) {
return (
<AgentActivity
events={events}
traceHref={(traceId) => `https://cloud.langfuse.com/trace/${traceId}`}
onLoadMore={onLoadMore}
/>
);
}
Your API route reads the audit log with a credential that may read it, filtered by the agent. Write the summary of each event in your own words: the audit log gives the event type and its data, and your product knows what they mean to its users.
Where the data comes from
| What the pattern shows | Call |
|---|---|
| The events of one agent | Admin API, audit logs, filtered by the agent |
| From the terminal | lumo logs |
| The trace of an event | The trace ID that LumoAuth stores with each audit row, from the traceparent header of the request |
| New events as they happen | Webhooks, for the event types that you chose |
States
- A quiet agent. Nothing has happened yet.
- A run of refusals. The filter "Refused" counts them, and each shows its reason.
Props
| Prop | Type | Description |
|---|---|---|
eventsrequired | ActivityEvent[] | The events, newest first. |
traceHref | (traceId: string) => string | Builds the link to a trace in your tracing tool. |
onLoadMore | () => void | Load older events. The button appears when you pass it. |
className | string | Class name for the timeline. |
ActivityEvent
| Option | Type | Description |
|---|---|---|
idrequired | string | The ID of the event. |
timerequired | string | When it happened. |
typerequired | string | The event type of the audit log. |
summaryrequired | string | The event in plain words. |
outcomerequired | 'success' | 'refused' | 'approval' | 'failed' | The outcome. |
reason | string | null | The reason of a refusal or a failure. |
onBehalfOf | string | null | The person that the agent acted for. |
taskId | string | null | Events with the same task are shown as one group. |
taskName | string | null | A name for the task. |
traceId | string | null | The trace ID of the event. |