# Flue Runtime
URL: /docs/runtimes/flue

Connect a durable Flue agent conversation to an assistant-ui chat UI with useFlueRuntime, including streaming, tool calls, image attachments, cancellation, and reconnects.

> 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.

`@assistant-ui/flue` connects one durable [Flue](https://flueframework.com/) conversation to assistant-ui. It wraps `useFlueAgent` from `@flue/react` and exposes it as an `ExternalStoreRuntime`, so Flue owns execution, streaming, and history on the server while assistant-ui renders the thread.

## When to use it

Pick the Flue runtime when:

- Your agent runs on Flue and is mounted with `createAgentRouter`.
- You want the conversation to survive a browser reload, since Flue keeps the history on the server.
- You want Flue text, reasoning, tool calls, and files rendered by the standard thread without writing a converter. `data-*` parts arrive as data parts, which the thread shows once you register a renderer for each name with `makeAssistantDataUI`.

## Architecture

The runtime addresses one conversation by URL: the route where the application mounts the agent, followed by a conversation id the application chooses. On mount, the runtime loads that conversation's history and follows its live updates; sending appends a user turn and cancelling calls the conversation's `abort` route. Pass `live` as `"sse"` or `"long-poll"` to choose how live updates arrive.

Flue has no thread list, so titles, enumeration, and deletion stay with the application. To switch conversations, change the URL, and the runtime replaces the session.

## Requirements

- React 18 or 19.
- `@flue/react` and `@flue/sdk` 2.3 or later, at the same version.
- A Flue agent served over HTTP, for example with `@flue/runtime`.

## Install

```bash
npm install @assistant-ui/react @assistant-ui/flue @flue/react @flue/sdk
```

## Quickstart

1. ### Mount the agent

   The server runs on `@flue/runtime` and is built with the `flue()` Vite plugin from `@flue/vite`, which compiles `"use agent"` modules:

   ```bash
   npm install @flue/runtime @flue/vite hono vite
   ```

   `vite.config.ts`

   ```
   import { flue } from "@flue/vite";
   import { defineConfig } from "vite";

   export default defineConfig({
     plugins: [flue()],
   });
   ```

   The agent selects the model and reads the provider key from the server environment, so the key never reaches the browser:

   `src/agents/chat.ts`

   ```
   "use agent";

   import { useModel } from "@flue/runtime";

   export function ChatAgent() {
     useModel("openai/gpt-4o-mini");
     return "You are a helpful assistant.";
   }
   ```

   Mount its routes where the client will address them:

   `src/app.ts`

   ```
   import { createAgentRouter } from "@flue/runtime/routing";
   import { Hono } from "hono";
   import { ChatAgent } from "./agents/chat";

   const app = new Hono();

   app.route("/api/agents/chat", createAgentRouter(ChatAgent));

   export default app;
   ```

2. ### Connect the runtime

   `src/runtime-provider.tsx`

   ```
   "use client";

   import { AssistantRuntimeProvider } from "@assistant-ui/react";
   import { useFlueRuntime } from "@assistant-ui/flue";
   import type { ReactNode } from "react";

   export function FlueRuntimeProvider({
     conversationId,
     children,
   }: {
     conversationId: string;
     children: ReactNode;
   }) {
     const runtime = useFlueRuntime({
       url: `/api/agents/chat/${conversationId}`,
     });

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

3. ### Render the thread

   `src/chat.tsx`

   ```
   import { Thread } from "@/components/assistant-ui/elements/thread.aui";
   import { FlueRuntimeProvider } from "./runtime-provider";

   export function Chat({ conversationId }: { conversationId: string }) {
     return (
       <FlueRuntimeProvider conversationId={conversationId}>
         <Thread />
       </FlueRuntimeProvider>
     );
   }
   ```

   Keep `conversationId` stable across reloads, for example in `localStorage` or the route, so a reload reconnects to the same history.

## Authentication

Pass a memoized Flue client instead of `url` when the conversation needs a token or custom headers. A new client instance replaces the session, so create it only when its inputs change:

```
import { useFlueRuntime } from "@assistant-ui/flue";
import { createFlueClient } from "@flue/sdk";
import { useMemo } from "react";

export function useChatRuntime(conversationId: string, token: string) {
  const client = useMemo(
    () =>
      createFlueClient({
        url: `/api/agents/chat/${conversationId}`,
        token,
      }),
    [conversationId, token],
  );

  return useFlueRuntime({ client });
}
```

The agent routes have no access control of their own. Protect the mount with your application's middleware before deploying.

## Attachments

The runtime forwards image attachments and rejects other file types. Configure an image attachment adapter so the composer accepts images:

```
import { useFlueRuntime } from "@assistant-ui/flue";
import { SimpleImageAttachmentAdapter } from "@assistant-ui/react";
import { useMemo } from "react";

export function useImageChatRuntime(url: string) {
  const adapters = useMemo(
    () => ({ attachments: new SimpleImageAttachmentAdapter() }),
    [],
  );
  return useFlueRuntime({ url, adapters });
}
```

To pass other Flue send options for a turn, such as an idempotency key, return them from `getSendOptions`, which receives the message being sent.

## Run outcomes

A run that is cancelled ends its assistant message as incomplete with the reason `cancelled`, and a run that fails ends it as incomplete with the reason `error` and the server's error, so the thread renders both like a stopped or failed turn from any other runtime.

## Conversation state

`useFlueRuntimeExtras` reads the Flue state the runtime is built from, for UI the thread does not cover:

```
import { useFlueRuntimeExtras } from "@assistant-ui/flue";

function FailedSends() {
  const { failedSends } = useFlueRuntimeExtras();
  if (failedSends.length === 0) return null;
  return <p>{failedSends.length} message(s) could not be confirmed as delivered.</p>;
}
```

| Field          | Use                                                                                                                                                          |
| -------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `status`       | The connection and run status of the conversation.                                                                                                           |
| `historyReady` | Whether the stored history has loaded.                                                                                                                       |
| `failedSends`  | Sends whose admission never reached the client, because the server rejected them or the response was lost, so they can be shown instead of silently dropped. |
| `settlements`  | The final outcome of each tracked submission.                                                                                                                |
| `messages`     | The raw Flue messages before conversion.                                                                                                                     |
| `error`        | The last conversation error.                                                                                                                                 |
| `refresh`      | Rechecks the conversation and resumes live updates, for a conversation created after mount.                                                                  |

Call it inside the `AssistantRuntimeProvider` that holds a Flue runtime.

## Example

[`examples/with-flue`](https://github.com/assistant-ui/assistant-ui/tree/main/examples/with-flue) is a runnable chat app with the client and server setup above, image attachments, and a new conversation button. It keeps history in server memory, so a server restart starts over; add a database adapter from Flue's docs to keep it.

## API reference

See [`@assistant-ui/flue`](/docs/api-reference/integrations/flue) for every export and option.