# assistant-ui · The frontend library for AI agents

> For AI agents: a documentation index is available at [llms.txt](/llms.txt). Use `.md` for canonical markdown pages; `.mdx` is kept as a backwards-compatible alias on supported URL paths.

Open-source React components and runtimes for building AI chat. Streaming, tools, and persistence in TypeScript.

## @assistant-ui/react

The runtime owns the thread, the stream, and the tools.

### AI SDK

Your route runs the model. The transport streams it back.

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

export default function App() {
  const runtime = useChatRuntime({
    transport: new AssistantChatTransport({ api: "/api/chat" }),
  });

  return (
    <AssistantRuntimeProvider runtime={runtime}>
      <Thread />
    </AssistantRuntimeProvider>
  );
}
```

[Read the AI SDK guide](/docs/runtimes/ai-sdk/overview)

### LangGraph

Point stream at your graph. Threads and interrupts included.

Abridged excerpt. Define `streamMessage` for your graph.

```tsx
import { AssistantRuntimeProvider } from "@assistant-ui/react";
import { useLangGraphRuntime } from "@assistant-ui/react-langgraph";
import { Thread } from "@/components/assistant-ui/thread";

export default function App() {
  const runtime = useLangGraphRuntime({
    stream: (messages, config) => streamMessage({ messages, config }),
  });

  return (
    <AssistantRuntimeProvider runtime={runtime}>
      <Thread />
    </AssistantRuntimeProvider>
  );
}
```

[Read the LangGraph guide](/docs/runtimes/langgraph/overview)

### LangChain

Connects to your deployed assistant by id.

```tsx
import { AssistantRuntimeProvider } from "@assistant-ui/react";
import { useStreamRuntime } from "@assistant-ui/react-langchain";
import { Thread } from "@/components/assistant-ui/thread";

export default function App() {
  const runtime = useStreamRuntime({
    assistantId: process.env["NEXT_PUBLIC_LANGGRAPH_ASSISTANT_ID"]!,
  });

  return (
    <AssistantRuntimeProvider runtime={runtime}>
      <Thread />
    </AssistantRuntimeProvider>
  );
}
```

[Read the LangChain guide](/docs/runtimes/langchain)

### Mastra

Set NEXT_PUBLIC_MASTRA_URL to your Mastra server's chat route.

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

export default function App() {
  const runtime = useChatRuntime({
    transport: new AssistantChatTransport({ api: process.env.NEXT_PUBLIC_MASTRA_URL! }),
  });

  return (
    <AssistantRuntimeProvider runtime={runtime}>
      <Thread />
    </AssistantRuntimeProvider>
  );
}
```

[Read the Mastra guide](/docs/integrations/frameworks/mastra/separate-server)

### Custom

No adapter at all. Your store, your transport, any backend.

Abridged excerpt. Supply `messages`, `convertMessage`, and `onNew` from your store.

```tsx
import { AssistantRuntimeProvider } from "@assistant-ui/react";
import { useExternalStoreRuntime } from "@assistant-ui/react";
import { Thread } from "@/components/assistant-ui/thread";

export default function App() {
  const runtime = useExternalStoreRuntime({
    messages, convertMessage, onNew,
  });

  return (
    <AssistantRuntimeProvider runtime={runtime}>
      <Thread />
    </AssistantRuntimeProvider>
  );
}
```

[Read the Custom guide](/docs/runtimes/custom/overview)

[Examples](/examples) · [Components](/components) · [Contact sales](/contact-sales) · [Privacy](/privacy-policy)
