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

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/langchain
Install dependencies:
pip install langchain 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 langchain_quickstart.py

Bring your own agent

Already have a LangChain agent? Add Snow Leopard data retrieval with these steps.

1. Install dependencies

pip install snowleopard

2. Create the Snow Leopard tool

Create a LangChain Tool that calls Snow Leopard to retrieve data:
from langchain_core.tools import Tool
from snowleopard import SnowLeopardClient

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

def query_data(natural_language_query: str) -> str:
    """Query your database using natural language."""
    response = client.retrieve(
        datafile_id="{your-datafile-id}",
        user_query=natural_language_query
    )
    return str(response)

snowleopard_tool = Tool(
    name="query_database",
    func=query_data,
    description="Query your database with natural language questions. "
                "Describe your data here - this becomes part of the agent's context."
)

3. Add the tool to your agent

Add the Snow Leopard tool to your agent’s tool list:
from langchain_openai import ChatOpenAI
from langchain.agents import create_tool_calling_agent, AgentExecutor
from langchain_core.prompts import ChatPromptTemplate

llm = ChatOpenAI(model="gpt-4o")
tools = [snowleopard_tool]  # Add to your existing tools

prompt = ChatPromptTemplate.from_messages([
    ("system", "You are a helpful assistant that can query databases."),
    ("human", "{input}"),
    ("placeholder", "{agent_scratchpad}"),
])

agent = create_tool_calling_agent(llm, tools, prompt)
agent_executor = AgentExecutor(agent=agent, tools=tools)

Next steps