Skip to content

Commit 69be3e7

Browse files
authored
Merge branch 'main' into cli-pass-plugin
2 parents b52dbca + 54ed079 commit 69be3e7

File tree

18 files changed

+561
-154
lines changed

18 files changed

+561
-154
lines changed
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
# Bigtable Tools Sample
2+
3+
## Introduction
4+
5+
This sample agent demonstrates the Bigtable first-party tools in ADK,
6+
distributed via the `google.adk.tools.bigtable` module. These tools include:
7+
8+
1. `bigtable_list_instances`
9+
10+
Fetches Bigtable instance ids in a Google Cloud project.
11+
12+
1. `bigtable_get_instance_info`
13+
14+
Fetches metadata information about a Bigtable instance.
15+
16+
1. `bigtable_list_tables`
17+
18+
Fetches table ids in a Bigtable instance.
19+
20+
1. `bigtable_get_table_info`
21+
22+
Fetches metadata information about a Bigtable table.
23+
24+
1. `bigtable_execute_sql`
25+
26+
Runs a DQL SQL query in Bigtable database.
27+
28+
## How to use
29+
30+
Set up environment variables in your `.env` file for using
31+
[Google AI Studio](https://google.github.io/adk-docs/get-started/quickstart/#gemini---google-ai-studio)
32+
or
33+
[Google Cloud Vertex AI](https://google.github.io/adk-docs/get-started/quickstart/#gemini---google-cloud-vertex-ai)
34+
for the LLM service for your agent. For example, for using Google AI Studio you
35+
would set:
36+
37+
* GOOGLE_GENAI_USE_VERTEXAI=FALSE
38+
* GOOGLE_API_KEY={your api key}
39+
40+
### With Application Default Credentials
41+
42+
This mode is useful for quick development when the agent builder is the only
43+
user interacting with the agent. The tools are run with these credentials.
44+
45+
1. Create application default credentials on the machine where the agent would
46+
be running by following https://cloud.google.com/docs/authentication/provide-credentials-adc.
47+
48+
1. Set `CREDENTIALS_TYPE=None` in `agent.py`
49+
50+
1. Run the agent
51+
52+
### With Service Account Keys
53+
54+
This mode is useful for quick development when the agent builder wants to run
55+
the agent with service account credentials. The tools are run with these
56+
credentials.
57+
58+
1. Create service account key by following https://cloud.google.com/iam/docs/service-account-creds#user-managed-keys.
59+
60+
1. Set `CREDENTIALS_TYPE=AuthCredentialTypes.SERVICE_ACCOUNT` in `agent.py`
61+
62+
1. Download the key file and replace `"service_account_key.json"` with the path
63+
64+
1. Run the agent
65+
66+
### With Interactive OAuth
67+
68+
1. Follow
69+
https://developers.google.com/identity/protocols/oauth2#1.-obtain-oauth-2.0-credentials-from-the-dynamic_data.setvar.console_name.
70+
to get your client id and client secret. Be sure to choose "web" as your client
71+
type.
72+
73+
1. Follow https://developers.google.com/workspace/guides/configure-oauth-consent
74+
to add scope "https://www.googleapis.com/auth/bigtable.admin" and
75+
"https://www.googleapis.com/auth/bigtable.data" as declaration, this is used
76+
for review purpose.
77+
78+
1. Follow
79+
https://developers.google.com/identity/protocols/oauth2/web-server#creatingcred
80+
to add http://localhost/dev-ui/ to "Authorized redirect URIs".
81+
82+
Note: localhost here is just a hostname that you use to access the dev ui,
83+
replace it with the actual hostname you use to access the dev ui.
84+
85+
1. For 1st run, allow popup for localhost in Chrome.
86+
87+
1. Configure your `.env` file to add two more variables before running the
88+
agent:
89+
90+
* OAUTH_CLIENT_ID={your client id}
91+
* OAUTH_CLIENT_SECRET={your client secret}
92+
93+
Note: don't create a separate .env, instead put it to the same .env file that
94+
stores your Vertex AI or Dev ML credentials
95+
96+
1. Set `CREDENTIALS_TYPE=AuthCredentialTypes.OAUTH2` in `agent.py` and run the
97+
agent
98+
99+
## Sample prompts
100+
101+
* Show me all instances in the my-project.
102+
* Show me all tables in the my-instance instance in my-project.
103+
* Describe the schema of the my-table table in the my-instance instance in my-project.
104+
* Show me the first 10 rows of data from the my-table table in the my-instance instance in my-project.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Copyright 2025 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
from . import agent
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
# Copyright 2025 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
import os
16+
17+
from google.adk.agents.llm_agent import LlmAgent
18+
from google.adk.auth.auth_credential import AuthCredentialTypes
19+
from google.adk.tools.bigtable.bigtable_credentials import BigtableCredentialsConfig
20+
from google.adk.tools.bigtable.bigtable_toolset import BigtableToolset
21+
from google.adk.tools.bigtable.settings import BigtableToolSettings
22+
import google.auth
23+
24+
# Define an appropriate credential type
25+
CREDENTIALS_TYPE = AuthCredentialTypes.OAUTH2
26+
27+
28+
# Define Bigtable tool config with read capability set to allowed.
29+
tool_settings = BigtableToolSettings()
30+
31+
if CREDENTIALS_TYPE == AuthCredentialTypes.OAUTH2:
32+
# Initiaze the tools to do interactive OAuth
33+
# The environment variables OAUTH_CLIENT_ID and OAUTH_CLIENT_SECRET
34+
# must be set
35+
credentials_config = BigtableCredentialsConfig(
36+
client_id=os.getenv("OAUTH_CLIENT_ID"),
37+
client_secret=os.getenv("OAUTH_CLIENT_SECRET"),
38+
scopes=[
39+
"https://www.googleapis.com/auth/bigtable.admin",
40+
"https://www.googleapis.com/auth/bigtable.data",
41+
],
42+
)
43+
elif CREDENTIALS_TYPE == AuthCredentialTypes.SERVICE_ACCOUNT:
44+
# Initialize the tools to use the credentials in the service account key.
45+
# If this flow is enabled, make sure to replace the file path with your own
46+
# service account key file
47+
# https://cloud.google.com/iam/docs/service-account-creds#user-managed-keys
48+
creds, _ = google.auth.load_credentials_from_file("service_account_key.json")
49+
credentials_config = BigtableCredentialsConfig(credentials=creds)
50+
else:
51+
# Initialize the tools to use the application default credentials.
52+
# https://cloud.google.com/docs/authentication/provide-credentials-adc
53+
application_default_credentials, _ = google.auth.default()
54+
credentials_config = BigtableCredentialsConfig(
55+
credentials=application_default_credentials
56+
)
57+
58+
bigtable_toolset = BigtableToolset(
59+
credentials_config=credentials_config, bigtable_tool_settings=tool_settings
60+
)
61+
62+
# The variable name `root_agent` determines what your root agent is for the
63+
# debug CLI
64+
root_agent = LlmAgent(
65+
model="gemini-1.5-flash",
66+
name="bigtable_agent",
67+
description=(
68+
"Agent to answer questions about Bigtable database tables and"
69+
" execute SQL queries."
70+
), # TODO(b/360128447): Update description
71+
instruction="""\
72+
You are a data agent with access to several Bigtable tools.
73+
Make use of those tools to answer the user's questions.
74+
""",
75+
tools=[bigtable_toolset],
76+
)

pyproject.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ dependencies = [
4848
"python-dateutil>=2.9.0.post0, <3.0.0", # For Vertext AI Session Service
4949
"python-dotenv>=1.0.0, <2.0.0", # To manage environment variables
5050
"requests>=2.32.4, <3.0.0",
51+
"sqlalchemy-spanner>=1.14.0", # Spanner database session service
5152
"sqlalchemy>=2.0, <3.0.0", # SQL database ORM
5253
"starlette>=0.46.2, <1.0.0", # For FastAPI CLI
5354
"tenacity>=8.0.0, <9.0.0", # For Retry management
@@ -104,7 +105,7 @@ test = [
104105
"langgraph>=0.2.60, <= 0.4.10", # For LangGraphAgent
105106
"litellm>=1.75.5, <2.0.0", # For LiteLLM tests
106107
"llama-index-readers-file>=0.4.0", # For retrieval tests
107-
"openai<=1.99.9", # For LiteLLM
108+
"openai>=1.100.2", # For LiteLLM
108109
"pytest-asyncio>=0.25.0",
109110
"pytest-mock>=3.14.0",
110111
"pytest-xdist>=3.6.1",

src/google/adk/agents/base_agent_config.py

Lines changed: 29 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
from pydantic import BaseModel
2626
from pydantic import ConfigDict
27+
from pydantic import Field
2728

2829
from ..utils.feature_decorator import experimental
2930
from .common_configs import AgentRefConfig
@@ -43,32 +44,41 @@ class BaseAgentConfig(BaseModel):
4344
extra='allow',
4445
)
4546

46-
agent_class: Union[Literal['BaseAgent'], str] = 'BaseAgent'
47-
"""Required. The class of the agent. The value is used to differentiate
48-
among different agent classes."""
47+
agent_class: Union[Literal['BaseAgent'], str] = Field(
48+
default='BaseAgent',
49+
description=(
50+
'Required. The class of the agent. The value is used to differentiate'
51+
' among different agent classes.'
52+
),
53+
)
4954

50-
name: str
51-
"""Required. The name of the agent."""
55+
name: str = Field(description='Required. The name of the agent.')
5256

53-
description: str = ''
54-
"""Optional. The description of the agent."""
57+
description: str = Field(
58+
default='', description='Optional. The description of the agent.'
59+
)
5560

56-
sub_agents: Optional[List[AgentRefConfig]] = None
57-
"""Optional. The sub-agents of the agent."""
61+
sub_agents: Optional[List[AgentRefConfig]] = Field(
62+
default=None, description='Optional. The sub-agents of the agent.'
63+
)
5864

59-
before_agent_callbacks: Optional[List[CodeConfig]] = None
60-
"""Optional. The before_agent_callbacks of the agent.
65+
before_agent_callbacks: Optional[List[CodeConfig]] = Field(
66+
default=None,
67+
description="""\
68+
Optional. The before_agent_callbacks of the agent.
6169
62-
Example:
70+
Example:
6371
64-
```
65-
before_agent_callbacks:
66-
- name: my_library.security_callbacks.before_agent_callback
67-
```
68-
"""
72+
```
73+
before_agent_callbacks:
74+
- name: my_library.security_callbacks.before_agent_callback
75+
```""",
76+
)
6977

70-
after_agent_callbacks: Optional[List[CodeConfig]] = None
71-
"""Optional. The after_agent_callbacks of the agent."""
78+
after_agent_callbacks: Optional[List[CodeConfig]] = Field(
79+
default=None,
80+
description='Optional. The after_agent_callbacks of the agent.',
81+
)
7282

7383
def to_agent_config(
7484
self, custom_agent_config_cls: Type[TBaseAgentConfig]

0 commit comments

Comments
 (0)