How to implement Generative User Interfaces with LangGraph
How to implement Generative User Interfaces with LangGraph
https://langchain-ai.github.io/langgraph/cloud/how-tos/generative_ui_react/
Generative user interfaces (Generative UI) allows agents to go beyond text and generate rich user interfaces. This enables creating more interactive and context-aware applications where the UI adapts based on the conversation flow and AI responses.
LangGraph Platform supports colocating your React components with your graph code. This allows you to focus on building specific UI components for your graph while easily plugging into existing chat interfaces such as Agent Chat and loading the code only when actually needed.
assistant-ui-langgraph-fastapi
https://github.com/fanqingsong/assistant-ui-langgraph-fastapi
A demonstration project that combines LangGraph, assistant-stream, and FastAPI to create an AI agent with a modern UI. The project uses assistant-ui and Next.js.
This project showcases:
- A LangGraph agent running on a FastAPI
- Real-time response streaming to the frontend using assistant-stream
- A modern chat UI built with assistant-ui and Next.js
- Demonstrate how to integrate external tools and APIs
AI Agent Service Toolkit
https://github.com/fanqingsong/agent-service-toolkit
Full toolkit for running an AI agent service built with LangGraph, FastAPI and Streamlit
A full toolkit for running an AI agent service built with LangGraph, FastAPI and Streamlit.
It includes a LangGraph agent, a FastAPI service to serve it, a client to interact with the service, and a Streamlit app that uses the client to provide a chat interface. Data structures and settings are built with Pydantic.
This project offers a template for you to easily build and run your own agents using the LangGraph framework. It demonstrates a complete setup from agent definition to user interface, making it easier to get started with LangGraph-based projects by providing a full, robust toolkit.
🎥 Watch a video walkthrough of the repo and app
How to integrate LangGraph into your React application¶
https://langchain-ai.github.io/langgraph/cloud/how-tos/use_stream_react/
!!! info "Prerequisites" - LangGraph Platform - LangGraph Server
The useStream() React hook provides a seamless way to integrate LangGraph into your React applications. It handles all the complexities of streaming, state management, and branching logic, letting you focus on building great chat experiences.
Key features:
- Messages streaming: Handle a stream of message chunks to form a complete message
- Automatic state management for messages, interrupts, loading states, and errors
- Conversation branching: Create alternate conversation paths from any point in the chat history
- UI-agnostic design: bring your own components and styling
Let's explore how to use useStream() in your React application.
The useStream() provides a solid foundation for creating bespoke chat experiences. For pre-built chat components and interfaces, we also recommend checking out CopilotKit and assistant-ui.
Installation¶
Example¶
"use client";
import { useStream } from "@langchain/langgraph-sdk/react";
import type { Message } from "@langchain/langgraph-sdk";
export default function App() {
const thread = useStream<{ messages: Message[] }>({
apiUrl: "http://localhost:2024",
assistantId: "agent",
messagesKey: "messages",
});
return (
<div>
<div>
{thread.messages.map((message) => (
<div key={message.id}>{message.content as string}</div>
))}
</div>
<form
onSubmit={(e) => {
e.preventDefault();
const form = e.target as HTMLFormElement;
const message = new FormData(form).get("message") as string;
form.reset();
thread.submit({ messages: [{ type: "human", content: message }]


