Agent Integrations
HatiData provides official integrations for popular AI agent frameworks. Each integration identifies the agent's framework via startup parameters, enabling per-framework billing, audit, and scheduling.
Why Agent-Aware Integrations?
Standard database drivers treat every connection the same. HatiData's agent integrations pass agent_id and framework metadata to the proxy via PostgreSQL startup parameters, which unlocks:
- Per-agent billing -- credit tracking and quota enforcement per agent identity
- Per-framework scheduling -- query prioritization based on framework type
- Agent-aware audit trails -- every query is attributed to a specific agent and framework
- Framework-specific policies -- ABAC rules can target specific agent frameworks (e.g., block DDL from LangChain agents)
- Reasoning chain tracking -- chain-of-thought integration for agent observability
LangChain
Installation
pip install langchain-hatidata
This installs the langchain_hatidata package, which depends on hatidata-agent and langchain-core.
SQL Database Wrapper
Use HatiDataSQLDatabase as a drop-in replacement for LangChain's SQLDatabase:
from hatidata_agent.langchain import HatiDataSQLDatabase
from langchain.agents import create_sql_agent
from langchain_openai import ChatOpenAI
# Create the database wrapper
db = HatiDataSQLDatabase(
host="your-org.proxy.hatidata.com",
port=5439,
agent_id="sql-agent-1",
database="hatidata",
password="hd_live_your_api_key",
)
# Create a LangChain SQL agent
llm = ChatOpenAI(model="gpt-4o", temperature=0)
agent = create_sql_agent(llm=llm, db=db, verbose=True)
# Ask questions in natural language
result = agent.run("How many active enterprise customers do we have?")
print(result)
The wrapper automatically sets framework="langchain" and implements the LangChain SQLDatabase interface:
| Method | Description |
|---|---|
run(command) | Execute SQL and return string result |
run_no_throw(command) | Execute SQL, return error message on failure |
get_usable_table_names() | List available tables |
get_table_info(table_names) | Get DDL and sample rows |
dialect | Returns "postgresql" |
Toolkit (Tools-Based)
For more control, use the HatiDataToolkit which provides individual tools:
from langchain_hatidata import HatiDataToolkit
from langchain.agents import AgentExecutor, create_react_agent
toolkit = HatiDataToolkit(
host="your-org.proxy.hatidata.com",
agent_id="react-agent",
password="hd_live_your_api_key",
)
# Get individual tools
tools = toolkit.get_tools()
# Returns: [HatiDataQueryTool, HatiDataListTablesTool,
# HatiDataDescribeTableTool, HatiDataContextSearchTool]
agent = create_react_agent(llm=llm, tools=tools, prompt=prompt)
executor = AgentExecutor(agent=agent, tools=tools)
result = executor.invoke({"input": "What were our top 5 products last quarter?"})
Available tools:
| Tool | Input | Description |
|---|---|---|
hatidata_query | SQL string | Execute SQL and return results |
hatidata_list_tables | (none) | List available tables |
hatidata_describe_table | Table name | Get column schema |
hatidata_context_search | Table + query | RAG full-text search |
See the dedicated LangChain page for full details on Memory, VectorStore, and Toolkit components.
CrewAI
Installation
pip install crewai-hatidata
Usage
from crewai import Agent, Task, Crew
from crewai_hatidata import (
HatiDataQueryTool,
HatiDataListTablesTool,
HatiDataDescribeTableTool,
HatiDataContextSearchTool,
)
# Create tools pointing to your HatiData instance
query_tool = HatiDataQueryTool(
host="your-org.proxy.hatidata.com",
agent_id="crewai-analyst",
password="hd_live_your_api_key",
)
list_tool = HatiDataListTablesTool(
host="your-org.proxy.hatidata.com",
agent_id="crewai-analyst",
password="hd_live_your_api_key",
)
# Create an agent with HatiData tools
analyst = Agent(
role="Data Analyst",
goal="Analyze customer data to find growth opportunities",
backstory="You are a senior data analyst with SQL expertise.",
tools=[query_tool, list_tool],
)
# Create and run a task
task = Task(
description="Find the top 10 customers by revenue this quarter",
agent=analyst,
expected_output="A table of top 10 customers with their revenue",
)
crew = Crew(agents=[analyst], tasks=[task])
result = crew.kickoff()
Each CrewAI tool accepts the same connection parameters:
| Parameter | Default | Description |
|---|---|---|
host | "localhost" | Proxy hostname |
port | 5439 | Proxy port |
agent_id | "crewai-agent" | Agent identifier |
database | "hatidata" | Database name |
user | "agent" | Username |
password | "" | Password or API key |
See the dedicated CrewAI page for full details on Memory integration and multi-agent workflows.
Autogen
HatiData works with Microsoft Autogen through the standard Python SDK:
import autogen
from hatidata_agent import HatiDataAgent
# HatiData client
agent_client = HatiDataAgent(
host="your-org.proxy.hatidata.com",
port=5439,
agent_id="autogen-analyst",
framework="autogen",
password="hd_live_your_api_key",
)
# Define a function the Autogen agent can call
def query_database(sql: str) -> str:
"""Execute a SQL query against the data warehouse."""
try:
rows = agent_client.query(sql)
return str(rows) if rows else "No results."
except Exception as e:
return f"Error: {e}"
# Register with Autogen
assistant = autogen.AssistantAgent(
name="data_analyst",
system_message="You are a data analyst. Use the query_database function to answer questions.",
llm_config={"config_list": [{"model": "gpt-4o"}]},
)
user_proxy = autogen.UserProxyAgent(
name="user",
human_input_mode="NEVER",
function_map={"query_database": query_database},
)
user_proxy.initiate_chat(
assistant,
message="What is the average order value by customer segment?",
)
Autogen Connection Parameters
| Parameter | Description |
|---|---|
host | Proxy hostname |
port | Proxy port (default 5439) |
agent_id | Unique identifier for this agent instance |
framework | Must be set to "autogen" for proper tracking |
password | HatiData API key |
Generic Agent Pattern
For any agent framework, use the HatiDataAgent class directly:
from hatidata_agent import HatiDataAgent
class MyCustomAgent:
def __init__(self):
self.db = HatiDataAgent(
host="your-org.proxy.hatidata.com",
port=5439,
agent_id="custom-agent",
framework="custom",
password="hd_live_your_api_key",
)
def answer_question(self, question: str, llm) -> str:
# Step 1: Discover available tables
tables = self.db.query(
"SELECT table_name FROM information_schema.tables WHERE table_schema = 'main'"
)
# Step 2: Get schema for relevant tables
schemas = []
for table in tables:
cols = self.db.query(
f"SELECT column_name, data_type FROM information_schema.columns "
f"WHERE table_name = '{table['table_name']}'"
)
schemas.append({"table": table["table_name"], "columns": cols})
# Step 3: Generate SQL with LLM
sql = llm.generate_sql(question, schemas)
# Step 4: Execute and return
with self.db.reasoning_chain() as chain:
results = chain.query(sql, step=0)
return llm.summarize(question, results)
HatiDataAgent Constructor Parameters
| Parameter | Default | Description |
|---|---|---|
host | "localhost" | Proxy hostname |
port | 5439 | Proxy port |
agent_id | "agent" | Unique agent identifier |
framework | "custom" | Framework name for tracking |
database | "hatidata" | Target database |
user | "agent" | PostgreSQL username |
password | "" | API key (hd_live_* or hd_test_*) |
More Integrations
| Framework | Description | Page |
|---|---|---|
| AutoGen | Microsoft AutoGen GroupChat with shared HatiData state | AutoGen |
| LlamaIndex | FunctionTool + ReActAgent with semantic_rank() | LlamaIndex |
| OpenAI Agents SDK | OpenAI Agents SDK tools and multi-agent handoffs | OpenAI |
| Vertex AI | GCP Reasoning Engines with HatiMemoryTool | Vertex AI |
| Ollama | Local LLM + local HatiData for air-gapped deployments | Ollama |
Source Code
Next Steps
- MCP Server -- Expose HatiData to Claude and Cursor
- MCP Tools Reference -- All 24 MCP tools
- Python SDK -- Full SDK reference
- Security -- RBAC, ABAC, and agent policies