Docs / useAgentStatus

useAgentStatus

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

Install

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

Import

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

Signature

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

Options

PropTypeRequiredDefaultNotes
manualStatusAgentStatusno
onCancel(() => void)no
stallAfterMsnumberno

Returns

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.

LabelEnglish default
sourceTitle"Source"
stillThinking"Still thinking…"
thinking"Thinking…"

Example

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

For coding agents: /llms/use-agent-status.md, generated from the same source.