# LangChain useStream

Render a LangChain conversation and keep graph state and interrupts in the native hook.

## Connect the React hook

[Install Ghost UI and its view dependencies](/libraries/ai#installation), then add the tested LangChain packages.

```bash
npm install @langchain/react@1.2.9 @langchain/core@1.3.2 @langchain/langgraph-sdk@1.12.9
```

Pass your graph’s apiUrl, assistantId, and native thread ID. Keep credentials in your app’s server proxy. See the [LangChain frontend setup guide](https://docs.langchain.com/oss/javascript/langchain/streaming/frontend) to configure the graph connection.

```tsx
import { useState } from "react";
import { Button } from "@collectivecreation/ghost-ui/components/button";
import { useStream } from "@langchain/react";
import { createLangChainAdapter } from "@collectivecreation/ghost-ui/chat-adapter-langchain";
import { useChatAdapter } from "@collectivecreation/ghost-ui/chat-runtime-react";
import { Message, MessageBody } from "@collectivecreation/ghost-ui/components/message";
import { MessageParts } from "@collectivecreation/ghost-ui/components/message-parts";
const adapter = createLangChainAdapter();
export function LangChainConversation({ apiUrl, assistantId, threadId, revision }: {
  apiUrl: string; assistantId: string; threadId: string; revision: number;
}) {
  const stream = useStream({ apiUrl, assistantId, threadId });
  const runtime = useChatAdapter(adapter, stream, { identity: { threadId, revision } });
  const [error, setError] = useState<unknown>();
  return <>
    {runtime.messages.map(message => <Message key={message.id} actor={message.actor}><MessageBody>
      <MessageParts parts={message.parts} />
    </MessageBody></Message>)}
    <Button disabled={runtime.capabilities.send.support !== "supported" || !runtime.capabilities.send.available}
      onClick={() => { setError(undefined); void Promise.resolve().then(() => runtime.controller.send({ text: "Review the brief", attachments: [] })).catch(setError); }}>Review brief</Button>
    {runtime.capabilities.stop.support === "supported" && runtime.capabilities.stop.available &&
      <Button onClick={() => { void Promise.resolve().then(() => runtime.controller.stop?.()).catch(setError); }}>Stop</Button>}
    {(error || runtime.controller.error) ? <p role="alert">The request could not complete.</p> : null}
  </>;
}

```

The adapter reads actual BaseMessage instances or serialized messages, including tool IDs and removal records. It binds text send to native submit({ messages: [...] }) and stop to native stop(). Compose [Composer](/ai-elements/composer) with runtime.controller for input; the native hook remains available in the same component.

## Fork and resume deliberately

```tsx
import type { UseStreamReturn } from "@langchain/react";
export function forkAt(stream: UseStreamReturn, checkpointId: string, text: string) {
  return stream.submit({ messages: [{ type: "human", id: crypto.randomUUID(), content: text }] }, { forkFrom: checkpointId });
}
export function resumeInterrupt(stream: UseStreamReturn, interruptId: string, response: unknown) {
  return stream.respond(response, { interruptId });
}

```

stream.values holds custom graph state; validate it for your application panel. isThreadLoading hydrates history and disables send; isLoading describes active work. Native stop() requests server cancellation; disconnect() stops observing without the same cancellation meaning. Checkpoint editing, branch navigation and typed interrupts remain native capabilities, not aliases for Ghost retry/edit/approval.

## Troubleshooting

If records are missing IDs, use getId with a stable application key. Keep one hook per [thread and revision](/libraries/ai-threads) and retain native checkpoint IDs when saving history. Use the [LangGraph SDK recipe](/libraries/ai-runtime-langgraph) for a client managed outside React.
