import { Canvas, Controls, Meta, Title } from '@storybook/addon-docs/blocks';
import * as AgentTreeStories from './AgentTree.stories';
<Meta of={AgentTreeStories} name='Usage' />
<Title />
## Purpose
A lead agent and its sub-agents as one live tree of cards, so a person can see who is doing what for the whole run: each agent's status, what it does now, how full its context window is, what it works with and who handed it work.
## Usage
- The lead sits on top, its sub-agents side by side below it and their helpers under them, joined by thin connectors. Every agent stays on screen; a working agent has the AI gradient border, a halo on the avatar, a shimmer on its line and a working status, and the ones resting are quieter.
- A card is laid out like an Agent Inbox card: the avatar and name with the model under it, a chevron, the activity line, the context window, then the status badge with the elapsed time and the tools. A card opens its **details** (task, model, time, cost, tokens, tools and the last handoff) in place, the way an Agent Inbox card does: the card grows with a divider and the details under its summary. One card is open at a time. A card below or beside it does not move, but the helpers under an open card move down, and their connectors follow.
- **Steering** is the row at the foot of the details: a message icon button (it opens the compact Composer in a floating bar in the middle of the screen), then pause, resume, stop, retry, or approve and decline when the agent needs you. The tree reports them through `onSteer`; the screen decides what they do. Without `onSteer` the row does not show.
- A **handoff** is more than the light: work moves, so change the data when it arrives. `onHandoffArrive` fires when the light reaches the receiver; set the receiver to `active` (with a new `activity` and the handed-over text as its `last`) and let a finished sender rest, and the gradient border and connector turn on as the work lands. A handoff runs as a short light along the connectors (through the lead when two sub-agents talk). Give `handoffs` a new `id` to run one; the ones there on first render and in a new project do not run.
- Only Zappy, Pantheon's own agent, wears the bolt avatar. Set `iconName='sparklesSolid'` on a third-party agent; leave it out for Zappy.
- A **project switcher** shows top left when `projects` is set; there is no visible heading or tally. The project shown is `project`; pass its crew as `root`.
- Wide containers lay the sub-agents out side by side; narrow ones (a drawer) indent every level and stretch the cards.
- Every visible word is in `labelStrings` or in the agent data. Cost and duration go through `formatCost` and `formatDuration`.
- Not for a list of tasks by what they need from you: use the Agent Inbox. Not for a timeline of events: use the Event Log.
## Accessibility
- The tree is a `tree` and every card a `treeitem` with its level, position and size, so a screen reader announces "Code reviewer, level 2, 1 of 3". The card's name is the agent, its status, what it does and its context.
- One tab stop. **Down** and **Up** walk the cards in tree order, **Right** goes to the first child, **Left** to the parent, **Home** and **End** to the first and last. **Enter** and **Space** open the details, **Escape** closes them and returns to the card. **Tab** from a card moves into its open details.
- The selected card (details open) has `aria-selected='true'`.
- Handoffs and steering are announced in a polite live region. The light is decorative and hidden from assistive technology, and off for reduced motion.
## Implementation
Built from the package `Panel`, `AgentAvatar`, `StatusBadge`, `ProgressBar`, `Button`, `IconButton`, `TextInput` and `Icon`, and the local bare `Select`. See the table below for the available props.
- `isAnimated` — Slide the AI gradient around the border of the working agents and along the connectors between them, as the animated Panel does. Off by default; off for reduced motion.
- `onAgentSelect` — Called on a click or Enter on a card. The card also opens its details.
- `onProjectChange` — Called when another project is chosen in the switcher.
| What | Value |
| ----------------------- | -------------------------------------------------------------------------------------------------------------------------------- |
| Card width, wide layout | `15rem` (`--agent-tree-card-width`) |
| Indent per level | `--pds-spacing-xl` |
| Context bar | `ProgressBar` size `s`; info under 80%, warning from 80%, critical from 95% |
| Connector and dot | `--pds-color-interactive-focus` at 50% over the surface, 1px; resting agents at 55% opacity |
| Footprint | The details panel draws outside the card; a parent with `overflow: hidden` does not clip the details, which are in the top layer |
<hr />
<Canvas of={AgentTreeStories.Default} />
<Controls of={AgentTreeStories.Default} />
Context: AgentTree
A tree of agent cards: the lead on top, its sub-agents side by side below, their helpers under them, joined by thin connectors.
Net-new componentOpen in Storybook