@ag-kit/ui-react package provides a lightweight React hook and TypeScript types to build agent chat interfaces that support streaming messages, tool calls with optional UI, and human-in-the-loop interrupts.
Installation
- Peer requirement:
zod(v3.25+ or v4) - Uses
fetch+ Server-Sent Events (SSE). Your server endpoint must stream events compatible with AG‑Kit.
Quick start
API
useChat
React hook for chat state, streaming, tool calls, and interrupts.- sendMessage forms:
sendMessage("text"): send a user messagesendMessage({ toolCallId, content }): submit a tool result messagesendMessage({ interruptId, payload }): resume from an interrupt with payload
Tools
Create strongly-typed tools withzod. Client tools can be declared with one of three capabilities: handler, render, or renderAndWaitForResponse. Server tools can be declared with render to render a UI for the tool call.
useChat({ clientTools: [...], serverTools: [...] }). When the server emits a tool call that matches a provided tool name:
- If the client tool has a
handler, it runs automatically when the input finishes streaming and its result is sent as a tool message. - If the client tool has
render, it will appear inuiMessageswith an optionalrender()function for custom UI. - If the client tool has
renderAndWaitForResponse, asubmitToolResultcallback is provided to return a string result, which is sent back to the agent. - If the server tool has
render, it will appear inuiMessageswith an optionalrender()function for custom UI.
Rendering tool calls in your UI
Client toolcall registration and execution modes
- Auto-run (handler): Provide a tool with
handler. It will auto-execute wheninput-availableand continue the round. - Self-handled run (renderAndWaitForResponse): Provide
renderAndWaitForResponseand callsubmitToolResult("...")to send the result. - Manual submission (UI-only tool): For tools without a handler, submit a result manually using
sendMessage({ toolCallId, content }).
uiToolCalls to show progress/state:
Interrupts
Provide a custom renderer for human-in-the-loop approval/inputs viainterrupt option.
uiMessages includes a part with type: "interrupt". If provided, your renderWithResume UI will be used, and calling resume(payload) continues the conversation.
Types
These TypeScript types are exported for building UIs:Server expectations
urlmust accept POST requests with JSON and respond with SSE events that conform to AG‑Kit’ssendMessageEventschema (text deltas, tool-call start/args/end, tool-result, interrupt, and[DONE]).- Default
urlis"/send-message"; set it to your agent server endpoint as needed.