AI agents that work with data can make analytics applications easier to use, but they also introduce a new monitoring problem.
A traditional application may have a predictable sequence of API calls:
Request
|
v
Application
|
v
Database Query
|
v
ResponseA data agent can behave differently:
User Question
|
v
AI Agent
|
+----> Interpret request
|
+----> Select data source
|
+----> Generate SQL
|
+----> Run BigQuery query
|
+----> Inspect result
|
+----> Generate another query
|
v
Final AnswerA single user question can therefore result in multiple model operations, multiple BigQuery queries, different query sizes, and different execution times.
This makes observability important.
For an AI-powered BigQuery application, developers should be able to answer questions such as:
How long did the agent take to respond?
How many BigQuery queries did it execute?
How much data did those queries process?
Which queries were slow?
Which requests generated unexpected query costs?
Did the agent repeatedly query the same data?
Where did latency occur: model processing, SQL generation, BigQuery execution, or application code?
Without these metrics, optimizing an AI data application becomes difficult.
What Is a BigQuery Data Agent?
A data agent is an AI-powered application that can understand natural-language requests and interact with data systems.
For example, a user might ask:
"Which products had the highest sales last quarter?"Instead of requiring the user to write SQL, the agent can interpret the request and generate a query:
SELECT
product_name,
SUM(revenue) AS total_revenue
FROM sales
WHERE order_date >= DATE_SUB(CURRENT_DATE(), INTERVAL 3 MONTH)
GROUP BY product_name
ORDER BY total_revenue DESC
LIMIT 10;The agent then executes the query and converts the result into a human-readable response.
The important difference is that the application is now controlling a data workflow dynamically.
That workflow needs observability at every important stage.
Why Traditional Application Monitoring Is Not Enough
Traditional application monitoring often focuses on:
Request latency
Error rate
CPU
Memory
Database latencyThese metrics are still useful, but they do not provide the full picture for an AI data agent.
Consider two requests:
Request A
1 AI operation
1 BigQuery query
500 MB processed
2 seconds
Request B
4 AI operations
7 BigQuery queries
120 GB processed
18 secondsBoth may return a successful HTTP response.
A conventional success-rate dashboard would consider both requests healthy.
From a cost and performance perspective, they are very different.
Agent observability therefore needs to connect application-level requests with model activity and BigQuery execution.
The Observability Model
A useful architecture is:
User Request
|
v
Agent Application
|
+---- Agent latency
|
+---- Model operations
|
+---- Tool calls
|
v
BigQuery
|
+---- Query latency
+---- Bytes processed
+---- Slot usage
+---- Query errorsThe goal is to correlate these events.
For example:
Request ID: 8f42
Agent duration: 9.8 seconds
Model calls: 3
BigQuery queries: 2
Query 1
Bytes processed: 42 MB
Duration: 1.2 seconds
Query 2
Bytes processed: 8.4 GB
Duration: 6.7 secondsNow the team can identify where most of the request time and data processing occurred.
Track End-to-End Agent Latency
The first metric should be the total time required to answer a request.
A simple application-level measurement can look like:
import time
start = time.perf_counter()
response = agent.run(user_question)
duration = time.perf_counter() - start
logger.info(
"agent_request_completed",
extra={
"duration_seconds": duration
}
)This metric gives you the overall latency.
However, it should not be the only latency measurement.
If an agent takes 10 seconds, developers need to know why.
Break the request into stages.
Total latency
|
+-- Agent planning
+-- Model calls
+-- SQL generation
+-- BigQuery execution
+-- Result processing
+-- Final response generationThis makes optimization much more practical.
Track BigQuery Query Latency
Every query executed by the agent should be associated with the originating request.
For example:
query_start = time.perf_counter()
job = client.query(sql)
result = job.result()
query_duration = time.perf_counter() - query_start
logger.info(
"bigquery_query_completed",
extra={
"request_id": request_id,
"query_duration_seconds": query_duration
}
)This allows the application to distinguish agent latency from database latency.
Suppose:
Total request: 12 seconds
BigQuery: 9 seconds
Model work: 2 seconds
Application: 1 secondThe obvious optimization target is BigQuery.
Without stage-level metrics, developers might incorrectly spend time optimizing the model layer.
Track Bytes Processed
Query duration alone does not tell you the cost of a query.
BigQuery workloads should also be monitored for the amount of data processed.
A query that takes two seconds and processes several gigabytes may require more attention than a query that takes three seconds and processes a few megabytes.
For an agent application, track information such as:
Request ID
Query ID
Bytes processed
Bytes billed
Duration
StatusThe BigQuery job metadata provides useful information for this type of monitoring.
A logging record could look conceptually like:
{
"request_id": "8f42",
"query_id": "job_123",
"duration_seconds": 2.4,
"bytes_processed": 52428800,
"status": "success"
}This creates a connection between the user request and the underlying data operation.
Track Query Count Per Agent Request
Query count is another useful metric.
An agent that normally executes one or two queries may suddenly start executing ten queries for the same type of request.
That can indicate:
Poor prompt or tool design
Inefficient SQL generation
Missing schema information
Repeated tool calls
Incorrect agent reasoning
Poor result handling
Track the relationship:
User Request
|
+-- Query 1
+-- Query 2
+-- Query 3Then calculate:
queries_per_requestA useful dashboard might show:
Average queries/request: 2.3
P95 queries/request: 5
Maximum: 14The maximum value is particularly useful during debugging.
Monitor Generated SQL
The SQL generated by an AI agent should be observable, but logging needs to be handled carefully.
For internal debugging, storing the generated SQL can help identify inefficient queries.
For example:
SELECT *
FROM customer_transactions
WHERE customer_id IN (
SELECT customer_id
FROM customers
);A monitoring system can then identify patterns such as:
SELECT *Missing filters
Large table scans
Unnecessary joins
Repeated queries
Missing partition filters
However, SQL logs may contain sensitive information depending on how queries are generated.
Do not automatically log user data simply because the SQL is useful for debugging.
Use appropriate redaction and access controls.
Track Query Errors
A successful agent response should not be the only success signal.
An agent may recover from a failed query by generating another SQL statement.
For example:
Query 1
|
+-- Error
|
v
Agent retries
|
v
Query 2
|
v
SuccessFrom the user's perspective, the request succeeded.
From an engineering perspective, the first failure is important.
Track:
query_errors
query_retries
agent_recoveries
final_request_statusThis can reveal hidden reliability problems.
If 20 percent of successful agent requests require query retries, the system may appear healthy while carrying unnecessary latency and cost.

Join the conversation! Your thoughts help the community grow.