mirror of
https://github.com/crewAIInc/crewAI.git
synced 2026-01-11 00:58:30 +00:00
git-subtree-dir: packages/tools git-subtree-split: 78317b9c127f18bd040c1d77e3c0840cdc9a5b38
Databricks Query Tool
Description
This tool allows AI agents to execute SQL queries against Databricks workspace tables and retrieve the results. It provides a simple interface for querying data from Databricks tables using SQL, making it easy for agents to access and analyze data stored in Databricks.
Installation
Install the crewai_tools package with the databricks extra:
pip install 'crewai[tools]' 'databricks-sdk'
Authentication
The tool requires Databricks authentication credentials. You can provide these in two ways:
-
Using Databricks CLI profile:
- Set the
DATABRICKS_CONFIG_PROFILEenvironment variable to your profile name.
- Set the
-
Using direct credentials:
- Set both
DATABRICKS_HOSTandDATABRICKS_TOKENenvironment variables.
- Set both
Example:
export DATABRICKS_HOST="https://your-workspace.cloud.databricks.com"
export DATABRICKS_TOKEN="dapi1234567890abcdef"
Usage
from crewai_tools import DatabricksQueryTool
# Basic usage
databricks_tool = DatabricksQueryTool()
# With default parameters for catalog, schema, and warehouse
databricks_tool = DatabricksQueryTool(
default_catalog="my_catalog",
default_schema="my_schema",
default_warehouse_id="warehouse_id"
)
# Example in a CrewAI agent
@agent
def data_analyst(self) -> Agent:
return Agent(
config=self.agents_config["data_analyst"],
allow_delegation=False,
tools=[databricks_tool]
)
Parameters
When executing queries, you can provide the following parameters:
query(required): SQL query to execute against the Databricks workspacecatalog(optional): Databricks catalog nameschema(optional): Databricks schema namewarehouse_id(optional): Databricks SQL warehouse IDrow_limit(optional): Maximum number of rows to return (default: 1000)
If not provided, the tool will use the default values set during initialization.