Skip to main content
The useStream hook from @langchain/react is UI-agnostic. It returns plain reactive state that you wire up to any component library you already use. This page shows how two popular libraries, AI Elements and assistant-ui, integrate with useStream to give you a fully-featured chat UI with minimal custom code.

How it works

useStream handles everything related to the LangGraph connection: streaming messages, thread management, tool call state, and reconnection. The library of your choice handles the visual layer. The integration is always the same shape:
This separation means you can switch, replace, or compose UI libraries without touching any of the agent wiring.

AI Elements

AI Elements is a composable, shadcn/ui-based component library purpose-built for AI chat interfaces. Components like Conversation, Message, Tool, Reasoning, and PromptInput are designed to be dropped directly into any React project.
Clone and run the full AI Elements example to see tool call rendering, reasoning display, streaming messages, and more in a working project.

Installation

Install AI Elements components via the CLI. Components are added as source files directly into your project (shadcn/ui registry style):

Wiring useStream

Render AI Elements components directly from stream.messages. Each LangChain BaseMessage maps to a component:
AI Elements works with any React setup — Vite, Next.js, or Remix. Components ship as source files in your project, so you can customise them freely without forking a library.

assistant-ui

assistant-ui is a headless React UI framework for AI chat. It provides a full runtime layer — thread management, message branching, attachment handling — that connects to useStream via the useExternalStoreRuntime adapter.
Clone and run the full assistant-ui example to see a Claude-style chat interface wired to a LangChain agent with useExternalStoreRuntime.

Installation

Wiring useStream

The useExternalStoreRuntime adapter bridges stream.messages into the assistant-ui runtime. Pass it to AssistantRuntimeProvider and then use any assistant-ui thread component:
assistant-ui ships a full thread UI out of the box via <Thread />, including a message list, composer, and scroll management. Customise individual parts — messages, tool UIs, attachments — by overriding the component slots.

Choosing a library

Both libraries connect to useStream the same way. The choice depends on how much control you need: Both work with any @langchain/react-compatible agent backend — createAgent, createDeepAgent, or any custom LangGraph graph.