Giving LangChain Agents a Database with Hotdata

LangChain is a popular framework for building agents and chains on top of language models. With hotdata-langchain, a LangChain agent can work with Hotdata directly: it can run SQL, look up tables, create and load instant databases, and search indexed columns. The package also includes a VectorStore, so Hotdata can sit behind any LangChain retriever.
Tools for agents
make_hotdata_tools gives you a set of LangChain StructuredTool objects that you can hand to any agent:
| Tool | What it does |
|---|---|
hotdata_execute_sql | Run SQL and return JSON rows |
hotdata_describe_tables | List tables, or one table's columns and types |
hotdata_list_managed_databases | List instant databases, with the id of each |
hotdata_create_managed_database | Create a database and declare tables |
hotdata_load_managed_table | Load a parquet file, local or by URL, into a table |
Search is optional. If you point it at a table and column, the agent also gets a search tool, either text or semantic depending on how that column is indexed.
You decide which tools each agent gets. If an agent only needs to read from one database, management_tools=False leaves out the tools for creating and loading databases. And for the tools that can overwrite data, the package lists their names in DESTRUCTIVE_TOOL_NAMES, which makes it easy to require human approval before they run using LangChain's human-in-the-loop middleware.
Retrieval with a vector store
HotdataVectorStore implements LangChain's VectorStore interface, so any retriever or chain that uses it can run on Hotdata. Documents and their embeddings live in a single table in an instant database, and each search is one SQL query. It works right away, even before you've built an index.
Building an agent
Install the package with the agents extra and set your API key:
pip install "hotdata-langchain[agents]" langchain-openai
export HOTDATA_API_KEY="your_api_key"
Then create the tools and an agent:
from hotdata_langchain import from_env, make_hotdata_tools
from langchain.agents import create_agent
client = from_env()
tools = make_hotdata_tools(client, database_id="dbid...")
agent = create_agent(
model="openai:gpt-4o",
tools=tools,
system_prompt="You are a data analyst.",
)
result = agent.invoke(
{"messages": [{"role": "user", "content": "How many orders are in the database?"}]}
)
print(result["messages"][-1].content)
database_id limits the agent's queries to one instant database. To find the right id, client.list_managed_databases() lists the databases in your workspace.
Try it out
We'd suggest starting small, with one database and management_tools=False so the agent only has the SQL and describe tools. Ask it a question, look at the SQL it writes, and add more tools once you're comfortable.
For more, see the LangChain guide for the full tool reference, and the repository for search and vector store examples.