The result object-type returned by the useChat hook that provides functions and state for interacting with the chat.
API
interface UseChatResult<Tools extends Chat.AnyTool, State = unknown> {error: Error | undefined;exhaustedRetries: boolean;generatingError: Error | undefined;getRecoveryConfiguration(): ConversationRecoveryConfiguration;isGenerating: boolean;isLoading: boolean;isReceiving: boolean;readonly isResuming: boolean;isRunningToolCalls: boolean;isSending: boolean;lastAssistantMessage: Chat.AssistantMessage <
string,
Tools
> | undefined;lastRunFinishReason: FinishReason | undefined;lastRunResult: JsonValue | undefined;lastRunUsage: readonly TokenUsage[] | undefined;messages: (Chat.Message < string, Tools > []);readonly pendingConversationRecovery: PendingConversationRecovery | undefined;readonly pendingInterrupts: PendingInterruptBatch | undefined;readonly recovery: ConversationRecoveryState;reload: () => void;restoreConversation(snapshot: ConversationSnapshot<State>, options: ConversationRestoreOptions): void;resume(options: ResumeOptions): void;resumeConversationRecovery(options: ResumeConversationRecoveryOptions): void;sendingError: Error | undefined;sendMessage: (message: Chat.MessageInput<string, Tools>) => void;setMessages: (messages: Chat.MessageInput<string, Tools>[]) => void;setState(state: State): void;readonly state: State | undefined;stop: (clearStreamingMessage?: boolean) => void;readonly subagents: readonly SubagentRun[];}@typeToolsChat.AnyTool@typeStateError | undefinedThe error encountered during chat operations, if any.
booleanWhether the current request has exhausted retries.
Error | undefinedError emitted during generation events.
booleanWhether the chat is currently generating (between start and finish/error events).
booleanAggregate loading flag across transport, generation, and tool calls.
booleanWhether the chat is receiving a response.
booleanWhether the resumed interaction is still running.
booleanWhether the chat is running tool calls.
booleanWhether the chat is sending a response.
Chat.AssistantMessage<string, Tools> | undefinedThe last assistant message.
FinishReason | undefinedWhy the model stopped in the last run that completed, such as length
when the answer was cut off by a token limit, or undefined when the
server did not say. Cleared when the next run starts.
JsonValue | undefinedThe return value the agent attached to the last run that completed
(AG-UI's RUN_FINISHED.result), or undefined when it attached none.
Cleared when the next run starts. Interrupted, cancelled, and failed
runs never set it.
readonly TokenUsage[] | undefinedThe token usage of the last run that completed (AG-UI's
RUN_FINISHED.usage), one entry per provider and model, or undefined
when the server reported none. Cleared when the next run starts, so a turn
that calls tools reports only its final run.
Chat.Message<string, Tools>[]An array of chat messages.
PendingConversationRecovery | undefinedThe inert browser recovery batch awaiting explicit settlement.
PendingInterruptBatch | undefinedThe complete pending interrupt batch, including while claimed.
ConversationRecoveryStateThe local recovery revision and whether an explicit restore is required.
() => voidReload the chat, useful for retrying when an error occurs.
Error | undefinedTransport/request failure before generation events arrive.
(message: Chat.MessageInput<string, Tools>) => voidFunction to send a new chat message.
(messages: Chat.MessageInput<string, Tools>[]) => voidFunction to update the chat messages.
State | undefinedThe currently visible shared agent state.
(clearStreamingMessage?: boolean) => voidFunction to stop the chat.
readonly SubagentRun[]Observed native subagent invocations in the current conversation.