Get the FREE Ultimate OpenClaw Setup Guide →

assistant-ui

Scanned
npx machina-cli add skill petekp/claude-code-setup/assistant-ui --openclaw
Files (1)
SKILL.md
4.7 KB

assistant-ui

Always consult assistant-ui.com/llms.txt for latest API.

React library for building AI chat interfaces with composable primitives.

References

When to Use

Use CaseBest For
Chat UI from scratchFull control over UX
Existing AI backendConnects to any streaming backend
Custom message typesTools, images, files, custom parts
Multi-thread appsBuilt-in thread list management
Production appsCloud persistence, auth, analytics

Architecture

┌─────────────────────────────────────────────────────────┐
│                  UI Components (Primitives)             │
│    ThreadPrimitive, MessagePrimitive, ComposerPrimitive │
└─────────────────────────┬───────────────────────────────┘
                          │
┌─────────────────────────▼───────────────────────────────┐
│                   Context Hooks                         │
│   useAui, useAuiState, useAuiEvent │
└─────────────────────────┬───────────────────────────────┘
                          │
┌─────────────────────────▼───────────────────────────────┐
│                    Runtime Layer                        │
│  AssistantRuntime → ThreadRuntime → MessageRuntime      │
└─────────────────────────┬───────────────────────────────┘
                          │
┌─────────────────────────▼───────────────────────────────┐
│                   Adapters/Backend                      │
│   AI SDK · LangGraph · Custom · Cloud Persistence       │
└─────────────────────────────────────────────────────────┘

Pick a Runtime

Using AI SDK?
├─ Yes → useChatRuntime (recommended)
└─ No
   ├─ External state (Redux/Zustand)? → useExternalStoreRuntime
   ├─ LangGraph agent? → useLangGraphRuntime
   ├─ AG-UI protocol? → useAgUiRuntime
   ├─ A2A protocol? → useA2ARuntime
   └─ Custom API → useLocalRuntime

Core Packages

PackagePurpose
@assistant-ui/reactUI primitives & hooks
@assistant-ui/react-ai-sdkVercel AI SDK v6 adapter
@assistant-ui/react-langgraphLangGraph adapter
@assistant-ui/react-markdownMarkdown rendering
assistant-streamStreaming protocol
assistant-cloudCloud persistence

Quick Start

import { AssistantRuntimeProvider } from "@assistant-ui/react";
import { Thread } from "@/components/assistant-ui/thread";
import { useChatRuntime, AssistantChatTransport } from "@assistant-ui/react-ai-sdk";

function App() {
  const runtime = useChatRuntime({
    transport: new AssistantChatTransport({ api: "/api/chat" }),
  });
  return (
    <AssistantRuntimeProvider runtime={runtime}>
      <Thread />
    </AssistantRuntimeProvider>
  );
}

State Access

import { useAui, useAuiState } from "@assistant-ui/react";

const api = useAui();
api.thread().append({ role: "user", content: [{ type: "text", text: "Hi" }] });
api.thread().cancelRun();

const messages = useAuiState(s => s.thread.messages);
const isRunning = useAuiState(s => s.thread.isRunning);

Related Skills

  • /setup - Installation and configuration
  • /primitives - UI component customization
  • /runtime - State management deep dive
  • /tools - Tool registration and UI
  • /streaming - Streaming protocols
  • /cloud - Persistence and auth
  • /thread-list - Multi-thread management
  • /update - Version updates and migrations

Source

git clone https://github.com/petekp/claude-code-setup/blob/main/skills/assistant-ui/SKILL.mdView on GitHub

Overview

assistant-ui is a React library for building AI chat interfaces using composable primitives. It exposes UI primitives (ThreadPrimitive, MessagePrimitive, ComposerPrimitive), context hooks (useAui, useAuiState, useAuiEvent), a layered Runtime (AssistantRuntime → ThreadRuntime → MessageRuntime), and adapters for AI SDKs, LangGraph, and cloud persistence. This enables precise UX control, backend flexibility, and scalable production apps.

How This Skill Works

Developers compose the chat UI from primitives and access state via context hooks like useAui and useAuiState. The Runtime layer orchestrates thread and message flows through ThreadRuntime and MessageRuntime, connecting to Adapters/Backends such as AI SDK, LangGraph, or custom APIs. Start by wrapping your app in AssistantRuntimeProvider with a configured runtime (e.g., useChatRuntime with AssistantChatTransport) to drive real-time AI conversations.

When to Use It

  • Chat UI from scratch for full control over UX
  • Existing AI backend integration with streaming capabilities
  • Custom message types (tools, images, files, etc.)
  • Multi-thread apps with built-in thread list management
  • Production apps requiring cloud persistence, authentication, and analytics

Quick Start

  1. Step 1: Import required pieces from @assistant-ui/react and @assistant-ui/react-ai-sdk
  2. Step 2: Initialize runtime with useChatRuntime({ transport: new AssistantChatTransport({ api: '/api/chat' }) })
  3. Step 3: Wrap your app with <AssistantRuntimeProvider runtime={runtime}> and render <Thread />

Best Practices

  • Define UI primitives first (Thread, Message, Composer) to shape UX before wiring data
  • Use the context hooks (useAui, useAuiState) to keep UI in sync with runtime state
  • Choose the appropriate runtime based on backend: AI SDK (recommended), LangGraph, or custom API
  • Leverage built-in thread/message runtimes to manage streaming and state
  • Enable cloud persistence and analytics in production for durability and insights

Example Use Cases

  • Build a chat UI from scratch with full control over layout and interactions
  • Connect to a streaming AI backend using useChatRuntime and AssistantChatTransport
  • Extend messages with custom types such as tools, images, or files
  • Create and manage multiple conversation threads with the thread list
  • Deploy a production app with cloud persistence, authentication, and analytics

Frequently Asked Questions

Add this skill to your agents
Sponsor this space

Reach thousands of developers