Skip to main content
The Snowflake query cost optimizer is a DinoAI agent that finds your most expensive dbt™ models, diagnoses Snowflake-specific SQL anti-patterns, rewrites the model files, opens a pull request, and posts a credit summary to Slack. The agent discovers the costly models itself using the dbt Discovery tools (get_model_performance) and Snowflake query history, so there is no trigger script or artifact parsing to maintain: one agent, one Bolt schedule.
Prerequisites
  • Slack connected (the agent posts the PR link and credit summary to #finops).
  • An active Snowflake connection with permission to read query history (the agent calls get_snowflake_query_performance_stats and queries snowflake.account_usage).
  • Bolt runs producing dbt™ artifacts, which power the dbt Discovery tools the agent uses to rank models by run time.
  • Familiarity with programmable agents and running an agent with Bolt.
Estimated time: 20 minutes.

Steps

1

Create the agent

In the Agent app, open Agents, select New agent, and start from the warehouse-cost-optimizer template (or Start from scratch). Fill in the builder fields with the content below. See Build an agent in the UI for a tour of the builder.Name: snowflake-query-optimizerRole:
Goal:
Backstory:
Model: leave Auto selected.Allowed tools (everything else is refused, see the Tools Reference):
  • get_model_performance, get_all_models, get_lineage, get_node_details
  • get_snowflake_query_performance_stats
  • run_sql_query
  • read_file, write_file, search_files_and_directories, ripgrep_search
  • run_terminal_command
  • post_slack_message
Output: set the Slack channel to #finops (or wherever your team routes cost alerts, updating the channel in the Goal to match).
2

Deploy the agent

Select Deploy and choose where the agent lives: Just here saves it to the workspace and makes it live immediately, Open a pull request commits it to your repo as .dinoai/agents/snowflake-query-optimizer.yml so it is governed as code. Both appear in the Bolt agent picker. See Creating Agents in the App.
3

Run it from Bolt

On the Agents page, hover the agent card and select Schedule. This opens a new Bolt schedule with the Run Paradime DinoAI Agent command already added and the agent pre-selected. The command runs natively, so no API keys or environment variables are needed. Set the Task:
A sensible cadence is weekdays at 8 AM (0 8 * * 1-5), after overnight production models complete so the latest run data is available. See Run an agent with Bolt for the full walkthrough.
On a run with costly models, the agent opens a PR titled perf: optimise Snowflake credit usage — <models> and posts a credit summary with the PR link to #finops. When nothing exceeds the 30-second threshold, it says so and exits cleanly, so scheduling it daily costs nothing on quiet days. If no PR appears, check the run transcript in the agent sessions panel: the most common cause is missing query-history permissions on the Snowflake connection.

How it works

The agent works through five phases in one session: it ranks models by recent execution time with get_model_performance (backed by your Bolt runs’ dbt™ artifacts), resolves each model’s recent query ID and credit usage from Snowflake query history, pulls the full query profile with get_snowflake_query_performance_stats, checks downstream usage with get_lineage, then rewrites the model files, opens the PR, and posts the summary. Snowflake anti-patterns it detects and fixes:
Prefer to pick the targets yourself? Pass Snowflake query IDs directly in the Bolt Task message (“Optimise these query IDs: …”) and the agent skips Phase 1 discovery. To orchestrate the run from outside Paradime (Airflow, a webhook), trigger it through the API with triggerDinoaiAgentRun; see the API and SDK reference.

Next steps

Query cost optimizer (BigQuery)

The same recipe for BigQuery, filtered by bytes processed.

Run an agent with Bolt

Cron, run-on-merge, and Turbo CI triggers for this agent.

dbt Discovery tools

The model performance and lineage tools this agent uses.

Programmable Agents reference

The agent schema, tools, and API.