Skip to content

Commit dc43d51

Browse files
google-genai-botcopybara-github
authored andcommitted
feat: Support protected write in BigQuery execute_sql tool
This change adds a new enum value which the agent builder can pass in the `BigQueryToolConfig` to allow limited writes to the `execute_sql` tool. PiperOrigin-RevId: 776661744
1 parent e2748b3 commit dc43d51

File tree

4 files changed

+786
-29
lines changed

4 files changed

+786
-29
lines changed

contributing/samples/bigquery/agent.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,11 @@
2626
CREDENTIALS_TYPE = AuthCredentialTypes.OAUTH2
2727

2828

29-
# Define BigQuery tool config
29+
# Define BigQuery tool config with write mode set to allowed. Note that this is
30+
# only to demonstrate the full capability of the BigQuery tools. In production
31+
# you may want to change to BLOCKED (default write mode, effectively makes the
32+
# tool read-only) or PROTECTED (only allows writes in the anonymous dataset of a
33+
# BigQuery session) write mode.
3034
tool_config = BigQueryToolConfig(write_mode=WriteMode.ALLOWED)
3135

3236
if CREDENTIALS_TYPE == AuthCredentialTypes.OAUTH2:

src/google/adk/tools/bigquery/config.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,20 @@ class WriteMode(Enum):
2626

2727
BLOCKED = 'blocked'
2828
"""No write operations are allowed.
29-
29+
3030
This mode implies that only read (i.e. SELECT query) operations are allowed.
3131
"""
3232

33+
PROTECTED = 'protected'
34+
"""Only protected write operations are allowed in a BigQuery session.
35+
36+
In this mode write operations in the anonymous dataset of a BigQuery session
37+
are allowed. For example, a temporaray table can be created, manipulated and
38+
deleted in the anonymous dataset during Agent interaction, while protecting
39+
permanent tables from being modified or deleted. To learn more about BigQuery
40+
sessions, see https://cloud.google.com/bigquery/docs/sessions-intro.
41+
"""
42+
3343
ALLOWED = 'allowed'
3444
"""All write operations are allowed."""
3545

0 commit comments

Comments
 (0)