> ## Documentation Index
> Fetch the complete documentation index at: https://docs.pandaprobe.com/llms.txt
> Use this file to discover all available pages before exploring further.

# LangGraph

> Add Reflect to LangGraph with native tracing, tools, and continuation

Use Reflect with LangGraph’s native agent factory. Reflect attaches its filesystem tool and memory context; the existing PandaProbe callback records agent, model, and tool execution.

## Installation

Python 3.10+ and Node.js 22+ for these examples. Install Reflect together with the framework and model provider used below.

> [tab] pip
>
> ```bash theme={null}
> pip install "pandaprobe[reflect,langgraph]" langchain-openai
> ```

> [tab] uv
>
> ```bash theme={null}
> uv add "pandaprobe[reflect,langgraph]" langchain-openai
> ```

> [tab] npm
>
> ```bash theme={null}
> npm install pandaprobe @everruns/bashkit@0.19.0 fs-native-extensions@1.5.1 langchain @langchain/core @langchain/langgraph @langchain/openai
> ```

> [tab] yarn
>
> ```bash theme={null}
> yarn add pandaprobe @everruns/bashkit@0.19.0 fs-native-extensions@1.5.1 langchain @langchain/core @langchain/langgraph @langchain/openai
> ```

> [tab] pnpm
>
> ```bash theme={null}
> pnpm add pandaprobe @everruns/bashkit@0.19.0 fs-native-extensions@1.5.1 langchain @langchain/core @langchain/langgraph @langchain/openai
> ```

## Credentials

```bash theme={null}
export PANDAPROBE_API_KEY="your-pandaprobe-api-key"
export PANDAPROBE_PROJECT_NAME="support-agent"
export OPENAI_API_KEY="your-provider-api-key"
```

For a self-hosted platform, also set `PANDAPROBE_ENDPOINT` to your API base URL. Reflect uses the same client configuration as tracing.

## Enable Reflect

This example creates a policy assistant. Add your own domain tools where indicated; Reflect supplies `reflect_bash` automatically.

```python title="Python" theme={null}
import asyncio

from langgraph.prebuilt import create_react_agent
from langchain_openai import ChatOpenAI
from langgraph.checkpoint.memory import InMemorySaver
from pandaprobe.integrations.langgraph import LangGraphCallbackHandler
from pandaprobe import Client
from pandaprobe.reflect import Reflect


async def main():
    client = Client()
    try:
        async with Reflect(client) as reflect:
            agent = reflect.agent(
                create_react_agent,
                model=ChatOpenAI(model="gpt-6-luna", reasoning_effort="none"),
                prompt="For standard returns, refund merchandise paid and exclude outbound shipping. Explain the policy clearly.",
                tools=[],  # Your native business tools go here.
                checkpointer=InMemorySaver(),
            )
            result = await reflect.run(
                agent, "I paid $65 for an item and $7 for shipping. What is refundable?", session_id="customer-42",
                config={"callbacks": [LangGraphCallbackHandler(client=client)]},
            )
            print(result["messages"][-1].content)
    finally:
        client.shutdown()


asyncio.run(main())
```

```ts title="TypeScript" theme={null}
import { createReactAgent } from "@langchain/langgraph/prebuilt";
import { ChatOpenAI } from "@langchain/openai";
import { MemorySaver } from "@langchain/langgraph";
import { LangGraphCallbackHandler } from "pandaprobe/integrations/langgraph";
import { Client } from "pandaprobe";
import { Reflect as ReflectRuntime } from "pandaprobe/reflect";

async function main() {
  const client = new Client();
  const reflect = new ReflectRuntime(client);
  try {
    const agent = await reflect.agent(createReactAgent, {
      framework: "langgraph",
      options: {
        llm: new ChatOpenAI({ model: "gpt-6-luna", reasoning: { effort: "none" } }),
        prompt: "For standard returns, refund merchandise paid and exclude outbound shipping. Explain the policy clearly.",
        tools: [], // Your native business tools go here.
        checkpointer: new MemorySaver(),
      },
      invokeOptions: { callbacks: [new LangGraphCallbackHandler({ client })] },
    });
    const result = await reflect.run(agent, "I paid $65 for an item and $7 for shipping. What is refundable?", { sessionId: "customer-42" });
    console.log(result.messages.at(-1)?.content);
  } finally {
    await reflect.close();
    await client.shutdown();
  }
}

main().catch(error => { console.error(error); process.exitCode = 1; });
```

## How the integration behaves

Use the native prebuilt message-state agent shown above. Reflect composes its prompt and guards tool execution during reflection. An already compiled custom graph needs [explicit integration](https://docs.pandaprobe.com/reflect/custom-loops.md); adding a wrapper cannot insert missing tool nodes.

### Conversations and replay

The checkpointer keeps native conversation history. Use the same `session_id` / `sessionId` for related turns and a new one for a new conversation. Reflect assigns a fresh execution ID per call unless you supply one.

Reflection continues checkpoint-owned history with new feedback; do not append the previous result yourself. Validation uses a fresh thread and local memory, while your replay callback resets business state.

Tracing uses the [LangGraph callback](https://docs.pandaprobe.com/tracing/integrations/langgraph.md) attached to the same client. Keep that callback on replay invocations as well.

`run()` returns the task's native result after evaluation and any triggered reflection. A healthy answer may produce no proposal. The workspace persists accepted guidance and pending proposals across restarts.

## Validate learned rules

Add [independent replay or controlled trials](https://docs.pandaprobe.com/reflect/validation.md) before proposed changes can become shared accepted guidance. Reset your business environment and conversation for each validation arm. See [Rules and memory](https://docs.pandaprobe.com/reflect/rules-and-memory.md) for the working filesystem and session notes.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.