# AgentState

> A state wrapper that renders and transitions the complete wait-state set.

## Install

```bash
npx shadcn@latest add https://crate.onerollstudios.com/r/agent-state.json
```

## Import

```tsx
import { AgentState } from "@/components/agent-wait-states/agent-state";
```

## Props

| Prop | Type | Required | Default | Notes |
| --- | --- | --- | --- | --- |
| `className` | `string` | no |  |  |
| `accent` | `boolean` | no | `false` |  |
| `labels` | `Partial<CrateLabels>` | no |  | Replace any of this component's labels. Overrides CrateProvider. |
| `status` | `AgentStatus \| AgentStatusSnapshot` | yes |  |  |
| `text` | `string` | no |  |  |
| `toolName` | `string` | no |  |  |
| `steps` | `ToolStep[]` | no |  |  |
| `errorMessage` | `string` | no |  |  |
| `onRetry` | `(() => void)` | no |  |  |
| `onCancel` | `(() => void)` | no |  |  |
| `reasoning` | `string` | no |  |  |
| `reasoningDone` | `boolean` | no |  |  |
| `reasoningDurationSeconds` | `number` | no |  |  |
| `sources` | `AgentSource[]` | no |  |  |
| `planSteps` | `PlanStep[]` | no | `[]` |  |
| `approvalTitle` | `string` | no |  |  |
| `approvalPreview` | `ReactNode` | no |  |  |
| `onAllow` | `(() => void)` | no |  |  |
| `onDeny` | `(() => void)` | no |  |  |
| `approvalExpiresIn` | `number` | no |  |  |
| `queueVariant` | `"line" \| "rate-limit"` | no |  |  |
| `queuePosition` | `number` | no |  |  |
| `retryIn` | `number` | no |  |  |
| `filename` | `string` | no |  |  |
| `fileSize` | `string` | no |  |  |
| `fileStage` | `FileStage` | no |  |  |
| `fileProgress` | `number` | no |  |  |
| `minDisplayMs` | `number` | no | `600` | How long a tool call or sources stay on screen at least, in ms. One that ends sooner stays, shown as finished, until this has passed. Errors, approvals, and stalls never wait. 0 turns it off. |

## States

Pass a `status` (an `AgentStatus` string, or the snapshot from `useAgentStatus`), and AgentState shows the matching component for each state:

| State | Renders |
| --- | --- |
| `thinking` | `Thinking` |
| `reasoning` | `ReasoningTrace` |
| `sources` | `Sources` |
| `tool` | `ToolCall` |
| `plan` | `AgentPlan` |
| `approval` | `Approval` |
| `queue` | `Queue` |
| `file` | `FileProcessing` |
| `streaming` | `Streaming` |
| `stalled` | `Stalled` |
| `error` | `ErrorState` |
| `done` | `Done` |

## Labels

Pass `labels` to override labels for whichever state is showing. See the CrateProvider doc for every key.

## Example

```tsx
// Give the chat a fixed id. Without one, useChat makes a random id while
// rendering, which Next.js with Cache Components refuses to prerender.
const chat = useChat({ id: "chat" });
const status = useAgentStatus(chat);

<AgentState
  status={status}
  text={streamedText}
  reasoning={status.reasoning}
  sources={status.sources}
/>
```
