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
>;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
>;messages: StateSignal <
Chat.Message <Output, Tools>[]
>;readonly pendingInterrupts: StateSignal<PendingInterruptBatch | undefined>;resendMessages: () => void;resume(options: ResumeOptions): void;sendingError: StateSignal <
Error | undefined
>;sendMessage: (message: Chat.Message<Output, Tools>) => void;setMessages: (messages: Chat.Message<Output, Tools>[]) => void;setState(state: State): void;start: () => () => void;readonly state: StateSignal<State | undefined>;stop: (clearStreamingMessage?: boolean) => void;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;}ChatRuntime
@typeOutput@typeToolsChat.AnyTool@typeStateerror
StateSignal<Error | undefined>exhaustedRetries
StateSignal<boolean>generatingError
StateSignal<Error | undefined>isGenerating
StateSignal<boolean>isLoading
StateSignal<boolean>isReceiving
StateSignal<boolean>isResuming
StateSignal<boolean>Whether the whole resumed interaction is still executing.
isRunningToolCalls
StateSignal<boolean>isSending
StateSignal<boolean>lastAssistantMessage
StateSignal<Chat.AssistantMessage<Output, Tools> | undefined>messages
StateSignal<Chat.Message<Output, Tools>[]>pendingInterrupts
StateSignal<PendingInterruptBatch | undefined>The current batch, retained until the server acknowledges resume.
resendMessages
() => voidResend messages and update state. Often used manually after an error.
sendingError
StateSignal<Error | undefined>sendMessage
(message: Chat.Message<Output, Tools>) => voidSend a new message to the LLM and update state.
setMessages
(messages: Chat.Message<Output, Tools>[]) => voidReplace the current set of messages in the chat state.
start
() => () => voidStart the runtime effect loop and return a function that disposes it.
state
StateSignal<State | undefined>The currently visible shared agent state.
stop
(clearStreamingMessage?: boolean) => voidStop the current LLM interaction.
threadId
StateSignal<string | undefined>The opaque AG-UI thread identity used by the current and subsequent runs.
updateOptions
(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