# useAgentStatus

> Maps AI SDK status, reasoning, sources, text, and tool parts to wait states.

## Install

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

## Import

```tsx
import { useAgentStatus } from "@/hooks/use-agent-status";
```

## Signature

```ts
useAgentStatus(chat: ChatLike, options: UseAgentStatusOptions): AgentStatusSnapshot
```

## Options

| Prop | Type | Required | Default | Notes |
| --- | --- | --- | --- | --- |
| `manualStatus` | `AgentStatus` | no |  |  |
| `onCancel` | `(() => void)` | no |  |  |
| `stallAfterMs` | `number` | no |  |  |

## Returns

```ts
export type AgentStatus =
  | "thinking"
  | "reasoning"
  | "sources"
  | "tool"
  | "plan"
  | "approval"
  | "queue"
  | "file"
  | "streaming"
  | "stalled"
  | "error"
  | "done";

export type AgentStatusSnapshot = {
  state: AgentStatus;
  activeToolName?: string;
  reasoning?: string;
  sources: AgentSource[];
  elapsedMs: number;
  showCancel: boolean;
  label: string;
  cancel?: () => void;
};
```

## Labels

Read from the nearest `CrateProvider`.

| Label | English default |
| --- | --- |
| `sourceTitle` | `"Source"` |
| `stillThinking` | `"Still thinking…"` |
| `thinking` | `"Thinking…"` |

## 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}
/>
```
