Skip to main content
This guide shows you how to add Snow Leopard data retrieval to a LangGraph workflow.

Prerequisites

Don’t have data? Use our sample superheroes dataset to get started, or choose from our other sample datasets.

Start from scratch

Clone and run the complete working example:
git clone https://github.com/SnowLeopard-AI/snowy-examples.git
cd snowy-examples/quickstart/langgraph
Install dependencies:
pip install langgraph langchain-openai snowleopard
Set your environment variables:
export OPENAI_API_KEY=your-openai-key
export SNOWLEOPARD_API_KEY=your-snowleopard-key
export SNOWLEOPARD_DATAFILE_ID=your-datafile-id
Run the example:
python langgraph_quickstart.py

Bring your own agent

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

1. Install dependencies

pip install snowleopard

2. Add Snow Leopard fields to your state

Add fields to your graph state to store query results:
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:
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:
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