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

# LangGraph

> Integrate Snow Leopard with LangGraph workflows for stateful data retrieval.

This guide shows you how to add Snow Leopard data retrieval to a [LangGraph](https://langchain-ai.github.io/langgraph/) workflow.

## Prerequisites

* Python 3.10+
* OpenAI API key (or another [supported model provider](https://python.langchain.com/docs/integrations/chat/))
* [Snow Leopard API key](https://auth.snowleopard.ai/account/api_keys)
* A datafile uploaded to [Snow Leopard Playground](https://try.snowleopard.ai)

<Note>
  Don't have data? Use our [sample superheroes dataset](https://github.com/SnowLeopard-AI/playground_datasets/raw/refs/heads/main/superheroes.db) to get started, or choose from our other [sample datasets](https://github.com/SnowLeopard-AI/playground_datasets/).
</Note>

## Start from scratch

Clone and run the [complete working example](https://github.com/SnowLeopard-AI/snowy-examples/tree/main/quickstart/langgraph):

```bash theme={null}
git clone https://github.com/SnowLeopard-AI/snowy-examples.git
cd snowy-examples/quickstart/langgraph
```

Install dependencies:

```bash theme={null}
pip install langgraph langchain-openai snowleopard
```

Set your environment variables:

```bash theme={null}
export OPENAI_API_KEY=your-openai-key
export SNOWLEOPARD_API_KEY=your-snowleopard-key
export SNOWLEOPARD_DATAFILE_ID=your-datafile-id
```

Run the example:

```bash theme={null}
python langgraph_quickstart.py
```

## Bring your own agent

Already have a LangGraph workflow? Add Snow Leopard data retrieval with these steps.

### 1. Install dependencies

```bash theme={null}
pip install snowleopard
```

### 2. Add Snow Leopard fields to your state

Add fields to your graph state to store query results:

```python theme={null}
from typing_extensions import TypedDict

class GraphState(TypedDict):
    user_question: str
    query_result: str  # Add this field for Snow Leopard results
    # ... your other state fields
```

### 3. Create a Snow Leopard query node

Create a node that calls Snow Leopard to retrieve data:

```python theme={null}
from snowleopard import SnowLeopardClient

client = SnowLeopardClient(api_key="{your-snowleopard-api-key}")

def query_database(state: GraphState) -> GraphState:
    """Query the database using Snow Leopard."""
    response = client.retrieve(
        datafile_id="{your-datafile-id}",
        user_query=state["user_question"]
    )
    state["query_result"] = str(response)
    return state
```

### 4. Add the node to your workflow

Add the query node and connect it to your existing workflow:

```python theme={null}
from langgraph.graph import StateGraph

workflow = StateGraph(GraphState)

# Add the Snow Leopard query node
workflow.add_node("query", query_database)

# Connect it to your workflow
workflow.set_entry_point("query")
workflow.add_edge("query", "your_next_node")
```

## Next steps

* View the [full example on GitHub](https://github.com/SnowLeopard-AI/snowy-examples/tree/main/quickstart/langgraph)
* See our full [API documentation](https://docs.snowleopard.ai/) to learn about the [Retrieve](/playground/endpoints/retrieve) and [Response](/playground/endpoints/response) endpoints
* See this quickstart in action with the [Financial Coach recipe](/recipes/financial-coach)
