DEVOPS

Agent rewrites an over-budget BigQuery query and opens a tuning PR

When a query is flagged over budget, an agent inspects the SQL and table partitioning, drafts a cheaper rewrite, opens a GitHub PR with the proposed diff, and links it in Linear.

CategoryDevOps
Enginepaperclip
Difficultyadvanced
Triggerevent
Steps5
Setup~25 min

How it runs

The automated pipeline, trigger to output.

  • TriggerOver-budget query flagged
  • ActionRead query and table partitioning in BigQueryGoogle BigQueryBigQuery
  • LogicDraft rewrite and dry-run to confirm savings
  • ActionOpen GitHub PR with proposed diffGitHubGitHub
  • OutputLink the PR on the Linear taskLinearLinear

What it does

This goes beyond flagging. When a query is identified as over budget, an agent reviews the SQL alongside the referenced tables' partitioning and clustering, then drafts a lower-cost rewrite, for example adding a partition filter or pruning a SELECT *. It opens a GitHub pull request with the proposed change and a dry-run cost comparison, then links the PR on the originating Linear task.

When to use it

Use it when your team has more flagged queries than time to fix them and you want a reviewable first draft of the optimization rather than just a ticket. A human still approves the PR.

How it works

  1. 1A flagged over-budget query event triggers the flow.
  2. 2The agent reads the query and the referenced tables' schema and partitioning in BigQuery.
  3. 3The agent drafts a cheaper rewrite and dry-runs it to confirm the savings.
  4. 4A GitHub PR is opened with the rewrite and a before/after cost note.
  5. 5The agent comments the PR link on the related Linear task for review.

Set it up

What you configure once, before turning it on.

  1. 1
    Connect BigQueryDatasets, queries, schemas.
  2. 2
    Connect GitHubRepos, issues, pull requests, actions.
  3. 3
    Connect LinearIssues, projects, cycles, triage.
  4. 4
    Set each agent's modelWe leave models unset so you pick the tier — fast + cheap, or top-quality.
  5. 5
    Tune it to your dataEdit the prompts, filters, and field mappings so it matches how your team works.
  6. 6
    Test, then turn it onRun once against a sample, confirm the output, then enable the trigger.

Run this workflow in your colony.

14-day trial. No DevOps. No Sales call. Provisioned in under a minute.