Amazon Redshift Tools Example

Use Amazon Redshift tools with Agno agents.

redshift_tools.py
"""
Amazon Redshift Tools Example

For IAM authentication with environment variables, set:
export AWS_ACCESS_KEY_ID="your-access-key"
export AWS_SECRET_ACCESS_KEY="your-secret-key"
export AWS_SESSION_TOKEN="your-session-token"
export REDSHIFT_HOST="your-workgroup.123456789.us-east-1.redshift-serverless.amazonaws.com"
export REDSHIFT_DATABASE="dev"
"""

from agno.agent import Agent
from agno.tools.redshift import RedshiftTools

# ---------------------------------------------------------------------------
# Create Agent
# ---------------------------------------------------------------------------


# Example 1: Standard username/password authentication
agent = Agent(
    tools=[
        RedshiftTools(
            user="your-username",
            password="your-password",
        )
    ]
)

# Example 2: IAM authentication with environment variables (Serverless)
agent_iam = Agent(
    tools=[
        RedshiftTools(
            iam=True,
        )
    ]
)

# ---------------------------------------------------------------------------
# Run Agent
# ---------------------------------------------------------------------------
if __name__ == "__main__":
    agent.print_response(
        "List the tables in the database and describe one of the tables", markdown=True
    )

    agent_iam.print_response("Run a query to select 1 + 1 as result", markdown=True)

Choose an authentication method

Use an existing Redshift database reachable from the machine running the example. Set its endpoint and database name, and change port or table_schema if they differ from the defaults (5439 and public). The script currently runs both agents. Keep only the constructor and run call for the authentication method you intend to use.

For standard authentication, replace user and password in the constructor. For IAM, set AWS_REGION to the database's region and supply credentials authorized to connect. Temporary credentials also require AWS_SESSION_TOKEN. An AWS_PROFILE, when set, takes precedence over explicit access-key fields. For a provisioned cluster, also supply cluster_identifier and db_user; the shown IAM configuration targets Serverless.

The toolkit forwards run_query SQL to the connector; its read-only docstring does not enforce a read-only database transaction. Use a database role with the intended permissions. See the Redshift connector configuration for connection requirements.

Run the Example

Set up your virtual environment

uv venv --python 3.12
source .venv/bin/activate

Install dependencies

uv pip install -U agno openai redshift-connector

Export environment variables

export AWS_ACCESS_KEY_ID="your_aws_access_key_id_here"
export AWS_SECRET_ACCESS_KEY="your_aws_secret_access_key_here"
export OPENAI_API_KEY="your_openai_api_key_here"
export REDSHIFT_DATABASE="your_redshift_database_here"
export REDSHIFT_HOST="your_redshift_host_here"

Run the example

Save the code above as redshift_tools.py, then run:

python redshift_tools.py

Full source: cookbook/91_tools/redshift_tools.py