Skip to main content

Generative UI

Generative UI allows you to create dynamic interfaces that change based on AI model outputs and tool calls. Instead of displaying raw text or JSON, you can render custom React components that provide rich, interactive experiences.

Basic Concept

Generative UI maps AI model outputs to React components:

State Management with createAI

createAI provides a context provider for managing AI and UI state across your application.

Setting Up the Provider

Using the Provider

Accessing State

Advanced Tool Patterns

Multi-Step Tool Execution

Use generators to show progress during tool execution:

Conditional UI Generation

Render different components based on tool parameters:

Interactive Components

Generate components with client-side interactivity:

Managing AI State

Reading AI State

Updating AI State

Persisting State

Use callbacks to persist state to a database:

Component Patterns

Skeleton Loading States

Incremental Rendering

Error Recovery

Routing Components

Route to different UIs based on model decisions:

Best Practices

1. Type Safety

2. Component Reusability

3. Progressive Disclosure

Next Steps