Redshift
The RedshiftTools toolkit enables an Agent to interact with Amazon Redshift data warehouses.
RedshiftTools enable an Agent to interact with Amazon Redshift data warehouses.
Prerequisites
The following example requires the redshift_connector library.
1uv pip install -U redshift-connectorYou will also need an Amazon Redshift cluster or Redshift Serverless endpoint. For IAM authentication, ensure your AWS credentials are configured.
Example
The following agent will list all tables in the database.
1from kern.agent import Agent2from kern.tools.redshift import RedshiftTools34# Initialize RedshiftTools with connection details5redshift_tools = RedshiftTools(6 host="your-cluster.abc123.us-east-1.redshift.amazonaws.com",7 database="dev",8 user="your-username",9 password="your-password",10 table_schema="public",11)1213# Create an agent with the RedshiftTools14agent = Agent(tools=[redshift_tools])1516# Example: Ask the agent to list tables17agent.print_response(18 "List the tables in the database and describe the sales table"19)Toolkit Params
| Parameter | Type | Default | Description |
|---|---|---|---|
host | Optional[str] | None | Redshift cluster endpoint. Uses REDSHIFT_HOST. |
port | int | 5439 | Port for the database connection. |
database | Optional[str] | None | Database name. Uses REDSHIFT_DATABASE. |
user | Optional[str] | None | Username for standard authentication. |
password | Optional[str] | None | Password for standard authentication. |
iam | bool | False | Enable IAM authentication. |
cluster_identifier | Optional[str] | None | Cluster identifier for IAM auth. Uses REDSHIFT_CLUSTER_IDENTIFIER. |
region | Optional[str] | None | AWS region for IAM auth. Uses AWS_REGION. |
db_user | Optional[str] | None | Database user for IAM auth. Uses REDSHIFT_DB_USER. |
access_key_id | Optional[str] | None | AWS access key for IAM auth. Uses AWS_ACCESS_KEY_ID. |
secret_access_key | Optional[str] | None | AWS secret key for IAM auth. Uses AWS_SECRET_ACCESS_KEY. |
session_token | Optional[str] | None | AWS session token for IAM auth. Uses AWS_SESSION_TOKEN. |
profile | Optional[str] | None | AWS profile for IAM auth. Uses AWS_PROFILE. |
ssl | bool | True | Enable SSL for the connection. |
table_schema | str | public | Schema name to search for tables. |
Toolkit Functions
| Function | Description |
|---|---|
show_tables | Retrieves and displays a list of tables in the configured schema. Returns the list of tables. |
describe_table | Describes the structure of a specified table by returning its columns, data types, and nullability. Parameters include table (str) to specify the table name. Returns the table description. |
summarize_table | Summarizes a table by computing aggregates such as min, max, average, standard deviation, and non-null counts for numeric columns, or unique values and average length for text columns. Parameters include table (str) to specify the table name. Returns the summary of the table. |
inspect_query | Inspects an SQL query by returning the query plan using EXPLAIN. Parameters include query (str) to specify the SQL query. Returns the query plan. |
run_query | Executes a read-only SQL query and returns the result. Parameters include query (str) to specify the SQL query. Returns the result of the query execution. |
export_table_to_path | Exports a specified table in CSV format to a given path. Parameters include table (str) to specify the table name and path (str) to specify where to save the file. Returns the result of the export operation. |
You can use include_tools or exclude_tools to modify the list of tools the agent has access to. Learn more about selecting tools.
Developer Resources
- View Example