Docs / AgentState

AgentState

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

Install

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

Playground

  1. Running searchDocs…

Sample data for sources, planSteps.

Callbacks (onRetry, onCancel, onAllow, onDeny) are logged here when the component calls them.

<AgentState
  status="tool"
  text="Here is what I found in the docs"
  toolName="searchDocs"
  errorMessage="The connection dropped before the answer finished."
  reasoning="The user wants a loading state for a chat."
  minDisplayMs={600}
  sources={sources}
  planSteps={planSteps}
  onRetry={() => {}}
  onCancel={() => {}}
  onAllow={() => {}}
  onDeny={() => {}}
/>

Import

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

Props

PropTypeRequiredDefaultNotes
classNamestringno
accentbooleannofalse
labelsPartial<CrateLabels>noReplace any of this component's labels. Overrides CrateProvider.
statusAgentStatus | AgentStatusSnapshotyes
textstringno
toolNamestringno
stepsToolStep[]no
errorMessagestringno
onRetry(() => void)no
onCancel(() => void)no
reasoningstringno
reasoningDonebooleanno
reasoningDurationSecondsnumberno
sourcesAgentSource[]no
planStepsPlanStep[]no[]
approvalTitlestringno
approvalPreviewReactNodeno
onAllow(() => void)no
onDeny(() => void)no
approvalExpiresInnumberno
queueVariant"line" | "rate-limit"no
queuePositionnumberno
retryInnumberno
filenamestringno
fileSizestringno
fileStageFileStageno
fileProgressnumberno
minDisplayMsnumberno600How 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:

StateRenders
thinkingThinking
reasoningReasoningTrace
sourcesSources
toolToolCall
planAgentPlan
approvalApproval
queueQueue
fileFileProcessing
streamingStreaming
stalledStalled
errorErrorState
doneDone

Labels

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

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/agent-state.md, generated from the same source.