← Guides·BigQuery Data Agents

BigQuery Data Agents

BigQuery Data Science Agent: analysis in a notebook

Use the Data Science Agent in BigQuery Studio notebooks to explore GA4 data, forecast revenue, and segment sessions, with a plan you approve step by step.

David PombarSwiss army knife at Trackingplan
6 min read · 1387 words

A data agent answers “what was revenue by channel?” in a sentence. It is the wrong tool for “which kinds of sessions convert, and what does next month look like?” That is an analysis: several steps, a model, charts, and choices someone should be able to inspect later. In BigQuery, the agent for that is the Data Science Agent, and it works in a notebook.

This guide runs three analyses on your agent layer with it: an exploration, a forecast, and a segmentation. The point is not the results, since the public sample is obfuscated. It is learning how to direct the agent and check its work.

A round-bottom flask with an amber liquid held by a clamp in a chemistry laboratory, with tubing above it
An experiment you can repeat beats a result you can’t explain. Image: National Center for Advancing Translational Sciences, Wikimedia Commons, public domain

Goal of this guide: three analyses in a notebook, written by the agent, reviewed and rerun by you. You need: the agent_layer tables from guide 4, or the pipeline from guide 9.

Open the agent

The Data Science Agent runs in Colab Enterprise notebooks. Your project needs four APIs enabled: BigQuery, Gemini for Google Cloud, Dataform, and Compute Engine.

In BigQuery, open your project, go to Notebooks > New notebook > Empty notebook, and click the spark button, Toggle Gemini in Colab. A side panel opens where you write prompts.

To give it data, select a BigQuery table with the table selector, type its name as project_id:dataset.table, or mention it with @, which searches the tables in the current project. You can also upload a CSV file.

How it works: plan, accept, run

Diagram of the Data Science Agent loop: a prompt produces a plan of steps, you refine it and click Accept and run, the agent writes and runs code cells in the notebook, and asks again before later steps.
Nothing runs until you accept the plan, and later steps ask again.

You describe the analysis; the agent writes a plan of steps. You can refine the plan before anything runs. When you click Accept & run, it writes code and text cells into the notebook and runs them on the notebook’s runtime. Later steps can ask for another Accept & run, and Cancel stops it at any point.

The result is an ordinary notebook. The code stays when the agent is done: you can read it, change it, rerun it, and share it. That is the main difference from a data agent’s answer, and the main reason to use this agent for anything you will present.

Choose the engine with the prompt

By default the agent writes Python with open-source libraries such as scikit-learn, pulling data into the notebook. A keyword in the prompt changes that:

Say in the promptIt uses
nothingPython with open-source libraries
“SQL” or “BigQuery ML”BigQuery ML, inside BigQuery
“BigQuery DataFrames” or “BigFrames”BigQuery DataFrames
“Apache Spark” or “PySpark”PySpark

For GA4 data at any real scale, prefer BigQuery ML or BigQuery DataFrames: the work runs in BigQuery instead of copying the table into the notebook.

Analysis 1: explore the sessions

Explore @agent_layer.sessions: row count, date range, share of missing values
per column, sessions and conversion rate by device_category and medium, and
a chart of daily sessions. Point out anything that looks unusual.

Read the plan before you accept it. Check that it computes conversion rate as converted sessions over all sessions, not something else. When it runs, look at the missing values first: on the public sample, some columns hold placeholder values, and on your own data a column that is 40% empty is a tracking question before it is an analysis question.

Analysis 2: forecast daily revenue

Using BigQuery ML, build a daily revenue series from @agent_layer.purchases
and forecast the next 30 days. Show the forecast with its prediction
interval on a chart, and evaluate the model on the last 14 days of history.

Saying “BigQuery ML” makes the agent build the series and the model in SQL. Check three things in the code: that every day appears in the series, including days with no purchases; that the evaluation holds out the last days rather than random ones; and that the chart shows the interval, not only the line. Three months of obfuscated sample data won’t produce a forecast worth trusting; the exercise is to read how it was built.

Analysis 3: segment the sessions

Cluster the sessions in @agent_layer.sessions into four to six segments using
device_category, medium, page_views and converted. Describe each segment in
plain language with its size and conversion rate, and explain how you chose
the number of segments.

Clustering always finds segments, whether or not they mean anything. Ask the agent to justify the number it chose, and read the description of each segment against the numbers in the notebook, not only its summary.

Check its work

Everything from guide 6 applies, with more code to read. For any analysis you will share:

Bring the results back to your data agent

An analysis is most useful when its results become something people can ask about. Three ways to close that loop:

Each of these turns a one-off notebook into context the whole team uses, and each one needs a test case in your set from guide 8.

When to use which agent

You wantUse
A number, now, in a chatA data agent (guides 5 to 8)
A pipeline that rebuilds tables every dayThe Data Engineering Agent (guide 9)
An analysis with steps, charts, or a model, that someone can rerunThe Data Science Agent

Exercise

Run the three analyses. For each one, write down every choice the agent made that you didn’t specify: a filter, a parameter, a definition. Then rerun the notebook from the top and confirm it reproduces.

How to know you got it right

Resources

FAQ

What is the BigQuery Data Science Agent? An agent inside Colab Enterprise notebooks in BigQuery Studio. You describe an analysis, it writes a plan, and after you accept it, it writes and runs the code in the notebook: exploration, charts, forecasting, and machine learning, on BigQuery tables or CSV files.

How is the Data Science Agent different from a data agent? A data agent answers a question with a query and a number, in a chat. The Data Science Agent runs a multi-step analysis in a notebook, with Python or BigQuery ML, and leaves you the code. Use the data agent for questions, and the Data Science Agent for analysis you want to inspect, rerun, or hand over.

Can the Data Science Agent use BigQuery ML? Yes. By default it writes Python with open-source libraries; mention SQL or BigQuery ML in the prompt and it uses BigQuery ML instead. Mentioning BigQuery DataFrames or Spark selects those libraries.

Next: Build your own: the Conversational Analytics API, ADK, and MCP.

David PombarSwiss army knife at Trackingplan

Read more from David, a Senior Product Strategist with 18+ years in digital product development and an atypical error detection knack.

Trackingplan

See everything. Miss nothing.

Your implementations audited around the clock with real-time, real-user data. Real-time alerts about errors or changes in your data, campaigns, pixels, privacy and consent. Let AI flag issues before they cost you.