affectUI › Components › Agents

Agent Tree

Who started whom – an orchestrator and its sub-agents as a live tree, with status, cost and time on every card, costs rolling up each branch, and branches that fold to one line.

Part of affectUI Pro. Install: npx shadcn@latest add https://www.affectui.com/r/agent-tree.json · Import from @/components/ui/agent-tree

When to use

  • Multi-agent runs where an orchestrator hands parts of a job to sub-agents – and those start their own
  • Seeing at a glance which branch is still running, which one waits for you and which one is expensive
  • A run overview next to a chat or a log – click a card to open what that agent did

When not to use

  • When things happened, in time order – use Agent Lanes
  • One agent's steps – use Agent Plan or Agent Steering
  • Handing tasks to agents yourself – use Delegate Board

Usage

import { AgentTree, type TreeAgent } from "@/components/ui/agent-tree";

const run: TreeAgent = {
  id: "lead", name: "Orchestrator", model: "Opus 5.5", task: "Launch the new pricing page",
  status: "running", cost: 0.42, started: Date.now() - 80_000,
  children: [
    { id: "research", name: "Researcher", task: "Compare five competitors", status: "done", cost: 0.29, started: Date.now() - 70_000, ended: Date.now() - 25_000 },
    { id: "build", name: "Coder", task: "Build the page", status: "running", cost: 0.18, started: Date.now() - 60_000 },
  ],
};

export function Run() {
  return <AgentTree root={run} onSelect={(agent) => openLog(agent.id)} />;
}

Props

NameTypeDefaultDescription
rootTreeAgent{ id, name, task, model?, avatar?, tools?, status, ask?, error?, cost?, started?, ended?, children? } – the whole tree, rebuilt as the run goes on; tools are small marks shown as overlapping tiles before the task
status"queued" | "running" | "waiting" | "done" | "failed" | "stopped"Per agent – "waiting" reads "Needs you"; queued and stopped agents and their connectors are muted
costnumberPer agent, its own cost – a card with children shows the whole branch
collapsed / defaultCollapsedstring[][]Ids of folded branches, controlled or uncontrolled
onCollapsedChange(collapsed: string[]) => voidA branch was folded or opened
ask / errorstringPer agent – what a waiting agent needs you to decide, and what went wrong for a failed one; shown in the window behind "needs you" and "failed"
onResolve(agent, action: "approve" | "reject" | "retry" | "dismiss") => voidAn answer from that window – update the agent's status in your data
onSelect(agent: TreeAgent) => voidA click on a card – makes the cards clickable
nownumberDate.now()The clock for running times – without it the tree ticks every second while an agent runs
formatCost(amount: number) => stringdollars, e.g. "$0.42"Formats every cost
titlestring"Agents"Heading of the bar
classNamestringExtra class on the root

Keyboard

  • Tab: Moves between the fold buttons – and the cards, when onSelect is set
  • Enter: On a card: selects it (onSelect)
  • Enter / Space: Folds or opens the focused branch

Accessibility

  • The tree is a tree with groups; every agent is a treeitem labelled with its name and status, aria-expanded on branches
  • Fold buttons name what they do, e.g. "Show 2 sub-agents of Researcher"
  • "needs you" and "failed" are buttons with aria-expanded; their window is a dialog, the first answer is focused and Esc closes it
  • The totals in the bar – agents, running, needs you, failed, cost – are announced politely when they change

Responsive

  • From 560px the first level sits side by side under the root, deeper levels hang below their parent – every card has the same width
  • Narrower, every level is indented under its parent and the connectors run down the left; the cards shrink together so the deepest level still fits
  • The connectors are measured from the cards, so any width or zoom works
  • Dark mode built in: switches when an ancestor (usually <html>) has the class dark or data-theme="dark"

Requirements

  • React 19

Related

  • Agent Lanes – Where every agent is right now – a live timeline with a lane per agent, tasks growing into “now”, hand-offs drawn between agents and approvals right on the block
  • Agent Plan – An agent's step-by-step plan to review before it runs – rename, drag to reorder, remove or add steps, then watch each one run with live timers and retry from a failed step
  • Delegate Board – Hand work to your agents by dragging it onto them – each agent previews its new “busy until” time, or switch to Auto and every new task goes to whoever is free first
  • Agent Steering – Steer an agent while it works – queue a note for the next step and watch it glide into the plan when the agent picks it up, or interrupt right away

Guides