Skip to main content
1

Create a Python file

Create a Python file and add the code below.
touch redshift_tools.py
2

Add the following code to your Python file

redshift_tools.py
from agno.agent import Agent
from agno.models.openai import OpenAIChat
from agno.tools.redshift import RedshiftTools

agent = Agent(
    model=OpenAIChat(id="gpt-4o"),
    tools=[
        RedshiftTools(
            iam=True,
            table_schema="public",
        )
    ],
    name="Redshift Agent",
    description="An agent that can query and analyze data in Amazon Redshift.",
    instructions=[
        "You are a data analyst assistant with access to a Redshift data warehouse.",
        "Use the available tools to list tables, describe schemas, and run SQL queries.",
        "Always inspect queries before running them to ensure they are optimized.",
        "Provide clear explanations of your findings.",
    ],
    markdown=True,
)

# List tables and describe one
response = agent.run(
    "List all tables in the database and describe the schema of the sales table."
)
print(f"Agent Response:\n{response.content}\n")

# Run a query
response = agent.run(
    "Write and run a query to get the top 10 customers by total revenue."
)
print(f"Agent Response:\n{response.content}")
3

Create a virtual environment

Open the Terminal and create a python virtual environment.
python3 -m venv .venv
source .venv/bin/activate
4

Install libraries

pip install -U agno openai redshift-connector
5

Export your OpenAI API key

  export OPENAI_API_KEY="your_openai_api_key_here"
6

Set your Redshift connection details

Set your AWS credentials and Redshift connection details:
  export REDSHIFT_HOST="your-cluster.abc123.us-east-1.redshift.amazonaws.com"
  export REDSHIFT_DATABASE="dev"
  export AWS_ACCESS_KEY_ID="your-access-key"
  export AWS_SECRET_ACCESS_KEY="your-secret-key"
  export AWS_SESSION_TOKEN="your-session-token"
7

Run Agent

python redshift_tools.py
8

Find All Cookbooks

Explore all the available cookbooks in the Agno repository. Click the link below to view the code on GitHub:Agno Tools Cookbooks on GitHub