A stateful client runtime for sending messages, processing AG-UI events, executing tools, and exposing reactive chat state.
API
interface ChatRuntime<Output, Tools extends Chat.AnyTool, State = unknown> {error: StateSignal <
Error | undefined
>;exhaustedRetries: StateSignal <boolean>;generatingError: StateSignal <
Error | undefined
>;getRecoveryConfiguration(): ConversationRecoveryConfiguration;isGenerating: StateSignal <boolean>;isLoading: StateSignal <boolean>;isReceiving: StateSignal <boolean>;readonly isResuming: StateSignal<boolean>;isRunningToolCalls: StateSignal <boolean>;isSending: StateSignal <boolean>;lastAssistantMessage: StateSignal <
Chat.AssistantMessage <Output, Tools> | undefined
>;lastRunFinishReason: StateSignal <
FinishReason | undefined
>;lastRunResult: StateSignal <
JsonValue | undefined
>;lastRunUsage: StateSignal <
readonly TokenUsage [] | undefined
>;messages: StateSignal <
Chat.Message <Output, Tools>[]
>;readonly pendingConversationRecovery: StateSignal<PendingConversationRecovery | undefined>;readonly pendingInterrupts: StateSignal<PendingInterruptBatch | undefined>;readonly recovery: StateSignal<ConversationRecoveryState>;resendMessages: () => void;restoreConversation(snapshot: ConversationSnapshot<State>, options: ConversationRestoreOptions): void;resume(options: ResumeOptions): void;resumeConversationRecovery(options: ResumeConversationRecoveryOptions): void;sendingError: StateSignal <
Error | undefined
>;sendMessage: (message: Chat.MessageInput<Output, Tools>) => void;setMessages: (messages: Chat.MessageInput<Output, Tools>[]) => void;setState(state: State): void;start: () => () => void;readonly state: StateSignal<State | undefined>;stop: (clearStreamingMessage?: boolean) => void;readonly subagents: StateSignal<readonly SubagentRun[]>;threadId: StateSignal <string | undefined>;updateOptions: (options: Partial<{
debugName?: string;
system: string;
tools: Tools[];
responseSchema: s.SchemaOutput;
debounce: number;
retries: number;
transport: TransportOrFactory;
ui?: boolean;
threadId?: string | undefined;
}>) => void;}@typeOutput@typeToolsChat.AnyTool@typeStateStateSignal<Error | undefined>StateSignal<boolean>StateSignal<Error | undefined>StateSignal<boolean>StateSignal<boolean>StateSignal<boolean>StateSignal<boolean>Whether the whole resumed interaction is still executing.
StateSignal<boolean>StateSignal<boolean>StateSignal<Chat.AssistantMessage<Output, Tools> | undefined>StateSignal<FinishReason | undefined>Why the model stopped in the last run that completed, such as length
when the answer was cut off, or undefined when the server did not say.
Hashbrown's provider packages always report it. Cleared when the next run
starts; interrupted, cancelled, and failed runs never set it.
StateSignal<JsonValue | undefined>The 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, so it always belongs to the messages
currently shown. Interrupted, cancelled, and failed runs never set it.
StateSignal<readonly TokenUsage[] | undefined>The 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. Interrupted, cancelled, and
failed runs never set it.
StateSignal<Chat.Message<Output, Tools>[]>StateSignal<PendingConversationRecovery | undefined>Inert browser calls and genuine interrupts awaiting explicit recovery settlement.
StateSignal<PendingInterruptBatch | undefined>The current batch, retained until the server acknowledges resume.
Local lookup revision and acknowledged-failure recovery disposition.
() => voidResend messages and update state. Often used manually after an error.
StateSignal<Error | undefined>(message: Chat.MessageInput<Output, Tools>) => voidSend a new message to the LLM and update state.
(messages: Chat.MessageInput<Output, Tools>[]) => voidReplace the current set of messages in the chat state.
() => () => voidStart the runtime effect loop and return a function that disposes it.
StateSignal<State | undefined>The currently visible shared agent state.
(clearStreamingMessage?: boolean) => voidStop the current LLM interaction.
StateSignal<readonly SubagentRun[]>Observed native subagent invocations in the current conversation.
StateSignal<string | undefined>The opaque AG-UI thread identity used by the current and subsequent runs.
(options: Partial<{
debugName?: string;
system: string;
tools: Tools[];
responseSchema: s.SchemaOutput;
debounce: number;
retries: number;
transport: TransportOrFactory;
ui?: boolean;
threadId?: string | undefined;
}>) => voidUpdate the chat options after initialization