|
|
Testing ADK Agents with BigQuery Data Connector
Author: Venkata Sudhakar
ShopMax India uses ADK agents with a BigQuery data connector to answer analytical queries: total orders by city this month, top-selling products in Bangalore, and average order value by customer tier. Testing agents that query BigQuery requires mocking the BigQuery client so tests run without cloud credentials, billing, or network access, while still verifying that the agent constructs correct SQL, handles empty result sets, and formats query results for the customer.
Mock the BigQuery client by injecting a fake query executor that accepts a SQL string and returns a list of row dicts. Assert that the agent sends a query containing the expected table name, filters, and aggregation. Test edge cases: an empty result set, a query error, and a result set that exceeds the maximum rows the agent is allowed to return to the customer. Keep the mock stateless so each test is independent.
The example below mocks the BigQuery connector for ShopMax India's sales analytics agent. Tests verify SQL construction, result formatting, empty result handling, and query error recovery.
It gives the following output,
... (3 passed in 0.01s)
In production, ShopMax India should enforce a maximum LIMIT clause on all agent-generated BigQuery queries to prevent runaway scans that process terabytes of data. Use parameterised queries rather than string interpolation to prevent SQL injection from adversarial inputs. Cache frequent analytics queries for 5 minutes using Memorystore so the agent does not hit BigQuery on every customer conversation during the Diwali sale when thousands of support agents query the same city sales figures simultaneously.
|
|