- Client Tools - Define the whole process of client-side tools, including name, parameters, handler and how to render the running process of client-side tools.
- Server Tools - Define how to render the running process of server-side tools.
- Human-in-the-Loop Interrupts - Define the resume logic and how to render the interrupt when the agent pauses and requests user input.
Concept of Generative UI
In Generative UI, the agent doesn’t generate raw JSX (for security reasons). Instead, it triggers predefined rendering logic on the client by calling tools or sending interrupts with structured payloads. The client then uses this data to render React components dynamically. Key benefits:- Dynamic interfaces based on agent logic
- Interactive elements like forms and charts
Component Registration
useChat provides easy ways to define rendering logic.
Registration for Tools (Client Tools & Server Tools)
For client-side tools, useclientTool with render (for display-only) or renderAndWaitForResponse (if needing to send result back). They receive {input} (and submitToolResult for the latter) and return JSX.
Simple Example (display-only):
serverTool with render. They receive {input} and return JSX.
Simple Example:
Registration for Interrupts (Human-in-the-Loop)
Use this when the agent needs to pause and get user input via a custom UI. API: InuseChat options, provide interrupt.renderWithResume function. It receives {interrupt, resume} and returns JSX. Call resume(payload) to send data back.
Simple Example:
Rendering Generative UI
If you’ve registered rendering logic as above, the UI will appear automatically in your message stream. In your message rendering code, for parts of type ‘tool-call’ or ‘interrupt’, simply callpart.render?.() to display the component.
Example:
useChat hook handles the rest.
Example: Rendering a Chart with Client Tools
Define a tool that renders a chart:clientTools: [renderChart]