Skip to main content
The BigQuery query cost optimizer is a DinoAI agent that finds your most expensive dbt™ models, diagnoses SQL anti-patterns, rewrites the model files, opens a pull request, and posts a cost summary to Slack. The agent discovers the costly models itself using the dbt Discovery tools (get_model_performance) and BigQuery’s INFORMATION_SCHEMA.JOBS, 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 cost summary to #finops).
  • An active BigQuery connection with permission to read job metadata (the agent calls get_bigquery_query_performance_stats and queries INFORMATION_SCHEMA.JOBS).
  • 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: bigquery-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_bigquery_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/bigquery-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 BigQuery cost — <models> and posts a cost summary with the PR link to #finops. When nothing exceeds the 10 GB 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 INFORMATION_SCHEMA.JOBS permissions on the BigQuery 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 job ID and bytes processed from INFORMATION_SCHEMA.JOBS, pulls the full query plan with get_bigquery_query_performance_stats, checks downstream usage with get_lineage, then rewrites the model files, opens the PR, and posts the summary. BigQuery is ranked by bytes processed because that is the direct driver of on-demand query cost. Anti-patterns it detects and fixes:
Prefer to pick the targets yourself? Pass BigQuery job IDs directly in the Bolt Task message (“Optimise these job 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 (Snowflake)

The same recipe for Snowflake, filtered by execution time and credits.

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.