# LangGraph SDK

Render messages from a LangGraph client you manage outside React.

## Read messages from graph state

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

```bash
npm install @langchain/langgraph-sdk@1.12.9
```

Use the direct SDK when a server, store, or service already manages the run. For a React-owned client, use [LangChain useStream](/libraries/ai-runtime-langchain).

```tsx
import { Client } from "@langchain/langgraph-sdk";
import { normalizeLangChainMessages } from "@collectivecreation/ghost-ui/chat-normalizers";
export async function* runGraph(client: Client, threadId: string, assistantId: string, text: string, signal: AbortSignal) {
  for await (const event of client.runs.stream(threadId, assistantId, {
    input: { messages: [{ type: "human", id: crypto.randomUUID(), content: text }] },
    streamMode: "values", signal,
  })) {
    if (event.event !== "values") continue;
    const state: unknown = event.data;
    if (typeof state !== "object" || state === null || !("messages" in state) || !Array.isArray(state.messages)) {
      throw new TypeError("Expected graph values with messages.");
    }
    yield { native: event.data, messages: normalizeLangChainMessages(state.messages) };
  }
}

```

Create your Client({ apiUrl }) with application authentication, select/create a real thread and consume the generator into your existing store. Each yielded messages array is a replacement snapshot, not a list to append again. Render it with the [plain-data composition](/libraries/ai#installation), or expose the store through [runtime integration](/libraries/ai-runtime#external-store).

## Native state and lifecycle

values can contain graph fields beyond messages; the example retains the native state alongside the projection. Validate those fields before application rendering. The SDK owns network stream decoding. Ghost neither reconstructs graph deltas nor creates another graph store.

Use native checkpoint, interrupt, task and run APIs for branching and resumption. An aborted reader is not proof of remote cancellation; use the SDK's run cancellation command for your selected native run. Keep its run ID and eventual status. See the [LangGraph SDK reference](https://reference.langchain.com/javascript/langchain-langgraph-sdk/) for these richer operations.

## Troubleshooting

Pass complete values snapshots to the normalizer and replace the current view on each update. Give messages a stable ID when the SDK supplies none. Use [thread and revision](/libraries/ai-threads) to discard late results from a replaced run.
