8000 [pull] main from google:main by pull[bot] · Pull Request #100 · Stars1233/adk-python · GitHub
[go: up one dir, main page]

Skip to content

[pull] main from google:main #100

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 197 commits into from
Jul 7, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
197 commits
Select commit Hold shift + click to select a range
d052e8f
chore: Update agent.py
hangfei Jun 4, 2025
552e42f
Merge pull request #1154 from google:hangfei-patch-2
copybara-github Jun 4, 2025
984c1d6
test: Added unit test coverage for local_eval_set_results_manager.py
ankursharmas Jun 4, 2025
54ed031
feat: support None as return type, such as def func() -> None:
google-genai-bot Jun 4, 2025
c6e1e82
chore: Minor improvement to session service
DeanChensj Jun 4, 2025
92e7a4a
chore: bump version number to 1.2.0
selcukgun Jun 4, 2025
86e15ca
chore: Make ArtifactService transparent to AgentTools
google-genai-bot Jun 4, 2025
068df04
fix: import deprecated from typing_extensions
google-genai-bot Jun 4, 2025
78bfce4
chore: bump version number to 1.2.1
selcukgun Jun 4, 2025
cf689fd
chore: Create agent.py
hangfei Jun 5, 2025
0d23258
chore: Update agent.py
hangfei Jun 5, 2025
1d8d1e0
Update agent.py
hangfei Jun 5, 2025
c224626
fix: handle the case when agent loading error doesn't have msg attrib…
seanzhougoogle Jun 5, 2025
19dbe24
Merge branch 'main' into hangfei-patch-3
hangfei Jun 5, 2025
4269cac
chore: change import path to import directly from module instead of p…
seanzhougoogle Jun 5, 2025
b7ebb69
Merge pull request #1171 from google:hangfei-patch-3
copybara-github Jun 5, 2025
7dbd8c6
chore: add file contents check in a GitHub action
wuliang229 Jun 5, 2025
4b1c218
fix: Prevent agent_graph.py throwing when workflow agent is root agent
Jacksunwei Jun 5, 2025
078ac84
chore: replace print with logger.info
seanzhougoogle Jun 5, 2025
fe1de7b
feat: Add url_context_tool
google-genai-bot Jun 5, 2025
54367dc
feat: support to customize timeout for mcpstdio connections
google-genai-bot Jun 5, 2025
d1b0587
feat: use threshold from the eval config dialog to run eval
google-genai-bot Jun 6, 2025
6ed6351
feat: show the used metric in evaluation history
google-genai-bot Jun 6, 2025
3b1f2ae
fix: Fix broken agent graphs
selcukgun Jun 6, 2025
9abb841
fix: Forwards `__annotations__` to the fake func for FunctionTool ins…
Jacksunwei Jun 6, 2025
309a656
refactor: extract credentail key building logic to auth_config
seanzhougoogle Jun 6, 2025
a097811
chore: Removes `LlmAgent.examples` field, which was already abandoned…
Jacksunwei Jun 6, 2025
8488ff0
feat: save and last run threshold and use it in next run evaluation
google-genai-bot Jun 6, 2025
4942f19
chore: Remove duplicated `model_config` attribute in EvalMetric class
jsondai Jun 6, 2025
be71208
chore: Adds apache headers for samples
Jacksunwei Jun 7, 2025
13f98c3
fix: Correct help text formatting for `adk deploy agent_engine`
hangfei Jun 9, 2025
3ae6ce1
docs: Update code example in tool declaration to reflect BigQuery art…
google-genai-bot Jun 9, 2025
f38c08b
feat: Add DeepWiki badge to README
takashikik Jun 9, 2025
cf5d701
fix: Remove display_name for non-Vertex file uploads
ystory Jun 9, 2025
bf47a8b
fix: hide new eval metric behind flag
abchang123 Jun 9, 2025
0882000
chore: Adds decorators to mark classes or fucntions as working_in_pro…
Jacksunwei Jun 10, 2025
fa110c2
chore: refine doc string of global_instruction
seanzhougoogle Jun 10, 2025
8e438f2
refactor: Extract out platform specific code like threading
google-genai-bot Jun 10, 2025
aaf1f9b
feat: Add support for display_name and description when deploying to …
yeesian Jun 10, 2025
484b33e
chore: add rag agent for testing
abchang123 Jun 10, 2025
77f44a4
refactor: remove the examples filed of LlmAgent which are no longer n…
seanzhougoogle Jun 10, 2025
6c999ca
feat: Introduce write protected mode to BigQuery tools
google-genai-bot Jun 10, 2025
9df3f72
chore: update adk-web to use latest
wyf7107 Jun 11, 2025
416dc6f
feat: add memory_service option to CLI
DeanChensj Jun 11, 2025
c9e2655
test: add assert statements in hello_world agent main.py
wuliang229 Jun 11, 2025
0c40542
fix: Handle project and location in the .env properly when deploying …
yeesian Jun 11, 2025
b2f319f
chore: move README to parent folder contributing/
wuliang229 Jun 11, 2025
f46b73b
chore: Bump version number and update changelog for 1.3.0 release
Jacksunwei Jun 11, 2025
a7ea374
chore: Update isort config to prevent vscode flickering
Jacksunwei Jun 12, 2025
fc65873
chore: Set agent_engine_id in the service constructor, also use the a…
DeanChensj Jun 12, 2025
b08bdbc
chore: Fixes the sample of example_tool
Jacksunwei Jun 12, 2025
bbceb4f
fix: remove unnecessary double quote on Claude docstring
zchee Jun 12, 2025
1551bd4
feat: Re-factor some eval sets manager logic, and implement GcsEvalSe…
google-genai-bot Jun 12, 2025
0a5cf45
feat: Implement GcsEvalSetResultsManager to handle storage of eval se…
google-genai-bot Jun 12, 2025
2ff9b1f
test: Add unit tests for `execute_sql` tool
google-genai-bot Jun 12, 2025
d22920b
feat: support realtime input config
ammmr Jun 12, 2025
4ccda99
fix: Merge custom http options with adk specific http options in mode…
seanzhougoogle Jun 12, 2025
29e4ca9
chore: Add empty a2a package
seanzhougoogle Jun 13, 2025
b2fc774
fix: Support project-based gemini model path to use google_search_tool
google-genai-bot Jun 13, 2025
313f1b0
chore: Add all missing direct deps to pyproject.toml
google-genai-bot Jun 13, 2025
c5b063f
feat: Add an Oauth2 credential fetcher to exchange and refresh oauth2…
seanzhougoogle Jun 13, 2025
1779801
feat: Support refresh access token automatically for rest_api_tool
seanzhougoogle Jun 13, 2025
dbdeb49
chore: Add a2a-sdk to pyproject.toml
seanzhougoogle Jun 13, 2025
40b15ad
refactor: enhance mcp tool session management
seanzhougoogle Jun 13, 2025
cb55970
refactor: Simplify agent_tool.py
google-genai-bot Jun 13, 2025
8e28587
feat: Add integration tests for litellm with and without turn on add_…
google-genai-bot Jun 13, 2025
131957c
chore: Triaging agent improvements & github workflow
selcukgun Jun 13, 2025
d129fd6
chore: Update the comments of MCPTool
seanzhougoogle Jun 13, 2025
233fd20
feat: Add import session API in the fast API
google-genai-bot Jun 14, 2025
8932106
chore: Raise error when using features decorated by working_in_progre…
seanzhougoogle Jun 14, 2025
b51a1f4
chore: support @working_in_progress and @expremental without calling …
seanzhougoogle Jun 14, 2025
8ebf229
chore: Add base credential service interface (WIP)
seanzhougoogle Jun 14, 2025
a19d617
chore: Add experimental decorator to BigQuery tools
seanzhougoogle Jun 14, 2025
d1bda9d
chore: Allow working_in_progress feature for unittests
seanzhougoogle Jun 14, 2025
a4d432a
chore: Add Service Account Credential Exchanger (Experimental)
seanzhougoogle Jun 14, 2025
675faef
feat: Allow data_store_specs pass into ADK VAIS built-in tool
google-genai-bot Jun 16, 2025
badbcbd
fix: agent generate config err (#1305)
simonwei97 Jun 16, 2025
1cfc555
ADK changes
xuanyang15 Jun 16, 2025
8201f9a
chore: Added live-streaming sample agent
hangfei Jun 16, 2025
fe1d5aa
feat: add enable_affective_dialog and proactivity to run_config and l…
hangfei Jun 16, 2025
fef8778
fix: liteLLM test failures
google-genai-bot Jun 16, 2025
31b81a3
chore: Update streamable http mcp example agent
seanzhougoogle Jun 16, 2025
4bda245
chore: fix oauth_calendar_agent example
seanzhougoogle Jun 16, 2025
aafa80b
fix: stream in litellm + adk and add corresponding integration tests
google-genai-bot Jun 16, 2025
e384fa4
chore: fix previously skipped isort issue
wuliang229 Jun 16, 2025
a6b1baa
chore: Add base credential exchanger (Experimental)
seanzhougoogle Jun 17, 2025
28dfcd2
chore: Add experimental decorator to Oauth2 credential fethcer
seanzhougoogle Jun 17, 2025
e2a8136
chore: Add a base credential refresher interface
seanzhougoogle Jun 17, 2025
476805d
chore: Add a2a extra dependency for github UT workflows
seanzhougoogle Jun 17, 2025
94caccc
refactor: Extract util method from OAuth2 credential fetcher for reuse
seanzhougoogle Jun 17, 2025
c755cf2
chore: Ignore a2a ut tests for python 3.9 given a2a-sdk only supports…
seanzhougoogle Jun 17, 2025
e181279
chore: Add A2A Part converter (WIP)
seanzhougoogle Jun 17, 2025
694b712
fix: agent generate config error (#1450)
simonwei97 Jun 17, 2025
1ae176a
fix: update conversion between Celsius and Fahrenheit
google-genai-bot Jun 17, 2025
c04adaa
chore: Add in memory credential service (Experimental)
seanzhougoogle Jun 17, 2025
6d174eb
fix: Set explicit project in the BigQuery client
google-genai-bot Jun 18, 2025
5f89a46
chore: Add credential service to runner and invocation context
seanzhougoogle Jun 18, 2025
f9fa784
chore: add google-adk/{version} to bigquery user agent
google-genai-bot Jun 18, 2025 10000
0a96253
refactor: Adapt service account credential exchanger to base credenti…
seanzhougoogle Jun 18, 2025
55201cb
chore: Add credential exchanger registry (Experimentals)
seanzhougoogle Jun 18, 2025
a17ebe6
chore: Add a credential refresher registry
seanzhougoogle Jun 18, 2025
9a207cb
refactor: Refactor oauth2_credential_exchanger to exchanger and refre…
seanzhougoogle Jun 18, 2025
2c739ab
chore: Add Credential Manager for managing tools credential (Experime…
seanzhougoogle Jun 18, 2025
dcea776
feat: Add Authenticated Tool (Experimental)
seanzhougoogle Jun 18, 2025
18a541c
chore: Ignore mcp_tool ut tests for python 3.9 given mcp sdk only sup…
seanzhougoogle Jun 18, 2025
157d9be
feat: Enable MCP Tool Auth (Experimental)
seanzhougoogle Jun 18, 2025
58e07ca
fix: Fix tracing for live
hangfei Jun 18, 2025
913d771
chore: Raise meaningful errors when importing a2a modules for python 3.9
seanzhougoogle Jun 19, 2025
9a1115c
chore: Remove service account support
seanzhougoogle Jun 19, 2025
7f8dc89
chore: fix the mcp_sse_agent
seanzhougoogle Jun 19, 2025
17beb32
chore: Bump version number and update changelog for 1.4.1 release
DeanChensj Jun 19, 2025
2f716ad
fix: Allow more credentials types for BigQuery tools
google-genai-bot Jun 19, 2025
ffcba70
chore: skip mcp and a2a tests for python 3.9
seanzhougoogle Jun 20, 2025
742478f
chore: Add event converters to convert adk event to a2a event (WIP)
seanzhougoogle Jun 20, 2025
4d72d31
fix: Add type checking to handle different response type of genai API…
DeanChensj Jun 20, 2025
8677d5c
chore: bump version number to 1.4.2
DeanChensj Jun 20, 2025
2fd8feb
chore: Support `allow_origins` in cloud_run deployment
DeanChensj Jun 20, 2025
fb13963
chore: Add request converter to convert a2a request to ADK request
seanzhougoogle Jun 21, 2025
7c670f6
chore: Send user message to the agent that returned a corresponding f…
seanzhougoogle Jun 21, 2025
3b1d9a8
fix: Use starred tuple unpacking on GCS artifact blob names
bck-ob-gh Jun 23, 2025
f033e40
chore: Clarify the behavior of Event.invocation_id
DeanChensj Jun 23, 2025
ea69c90
feat: add usage span attributes to telemetry (#356)
soundTricker Jun 23, 2025
bd67e84
fix: make LiteLLM streaming truly asynchronous
avidelatm Jun 23, 2025
29cd183
chore: Add credential service backed by session state
seanzhougoogle Jun 23, 2025
120cbab
refactor: Rename long util function name in runner.py and move it to …
seanzhougoogle Jun 23, 2025
fa025d7
feat: Add a new option `eval_storage_uri` in adk web & adk eval to sp…
jcpagadora737 Jun 23, 2025
9597a44
feat: Add rouge_score library to ADK eval dependencies, and implement…
jcpagadora737 Jun 23, 2025
00cc8cd
feat: Add Vertex Express mode compatibility for VertexAiSessionService
google-genai-bot Jun 24, 2025
abc89d2
feat: Add implementation of VertexAiMemoryBankService and support in …
DeanChensj Jun 24, 2025
f33e090
feat: Add ADK examples for litellm with add_function_to_prompt
genquan9 Jun 24, 2025
a1e1441
fix: update contributing links
wuliang229 Jun 24, 2025
ed7a21e
chore: Update google-genai package and related deps to latest
google-genai-bot Jun 24, 2025
acbdca0
fix: Make raw_auth_credential and exchanged_auth_credential optional …
seanzhougoogle Jun 24, 2025
9e473e0
fix: Include current turn context when include_contents='none'
google-genai-bot Jun 24, 2025
09f1269
ci(tests): leverage official uv action for install
d33bs Jun 24, 2025
88a4402
chore: Do not send api request when session does not have events
DeanChensj Jun 24, 2025
ef3c745
fix: typo fix in sample agent instruction
adityamulik Jun 24, 2025
917a8a1
chore: Adapt oauth calendar agent to use authenticated tool
seanzhougoogle Jun 24, 2025
6729edd
refactor: Rename the Google API based bigquery sample agent
google-genai-bot Jun 25, 2025
f54b9b6
chore: Add unit tests for contents.py
seanzhougoogle Jun 25, 2025
a623467
chore: Enhance a2a context id parsing and construction logic
seanzhougoogle Jun 25, 2025
5306dda
chore: Release 1.5.0
hangfei Jun 25, 2025
738d1a8
chore: create an agent to check issue format and content for bugs and…
xuanyang15 Jun 25, 2025
832a633
chore: Enhance a2a part converters
seanzhougoogle Jun 25, 2025
a71dbdf
chore: Enhance a2a event converter
seanzhougoogle Jun 25, 2025
3901fad
fix: converts litellm generate config err
simonwei97 Jun 26, 2025
04de3e1
fix: Adding detailed information on each metric evaluation
ankursharmas Jun 26, 2025
77b869f
fix: Update google_search_tool.py to support updated Gemini LIVE mode…
rayira Jun 26, 2025
2f55de6
chore: Add a2a task result aggregator
seanzhougoogle Jun 26, 2025
630f167
chore: Add a2a agent executor
seanzhougoogle Jun 26, 2025
ed09cd8
chore: Add enable_a2a option to adk command line
seanzhougoogle Jun 26, 2025
5356f20
chore: Add a2a log utils for formatting a2a reqeust/response logs
seanzhougoogle Jun 26, 2025
22629a1
chore: update adk web
wyf7107 Jun 26, 2025
e79651c
feat: Add A2A endpoints to fast api server when --a2a option is speci…
seanzhougoogle Jun 26, 2025
e153d07
chore: updating CONTRIBUTING.md with missing extra
jackwotherspoon Jun 27, 2025
9029b8a
fix: Lock LangGraph version to <= 0.4.10
hangfei Jun 27, 2025
31e41bd
chore: Enhance part_converter module to only import sys when needed a…
seanzhougoogle Jun 27, 2025
1fe9c47
chore: Enhance a2a_agent_executor module to raise error with meaningf…
seanzhougoogle Jun 27, 2025
51a559e
chore: Adding PR commit check github workflow
hangfei Jun 27, 2025
09e487d
chore: Use context_id as session_id and construct temp user_id from c…
seanzhougoogle Jun 27, 2025
20279d9
fix: Save output in state via output_key only when the event is autho…
seanzhougoogle Jun 27, 2025
045aea9
fix: Support API-Key for MCP Tool authentication
seanzhougoogle Jun 27, 2025
c13c987
feat: Add remote a2a agent
seanzhougoogle Jun 27, 2025
4e765ae
fix: raise ValueError when sessionId and userId are incorrect combina…
soundTricker Jun 27, 2025
3f621ae
fix: treat SQLite database update time as UTC for session's last upda…
xuanyang15 Jun 27, 2025
f0183a9
feat: Enable A2A features as experimental
seanzhougoogle Jun 27, 2025
1cf5cf0
chore: Add a basic a2a agent demo sample
seanzhougoogle Jun 27, 2025
379810d
chore: Add a human in the loop a2a agent demo sample
seanzhougoogle Jun 27, 2025
e2748b3
chore: Add an a2a agent to demo oauth flow
seanzhougoogle Jun 27, 2025
dc43d51
feat: Support protected write in BigQuery `execute_sql` tool
google-genai-bot Jun 27, 2025
ffa9b36
docs: Update CONTRIBUTING.md
hangfei Jun 27, 2025
b6c7b5b
chore: refactor the ADK Triaging Agent to make the code easier to read
xuanyang15 Jun 27, 2025
37108be
docs: Add AGENTS.md to provide relevant project context for the Gemin…
google-genai-bot Jun 28, 2025
a58cc3d
chore: Create an example for multi agent live streaming
hangfei Jun 30, 2025
9b75e24
fix: Avoid pydantic.ValidationError when the model stream returns emp…
hangfei Jun 30, 2025
43083ba
chore: update adk web
Jun 30, 2025
17d6042
fix: Make sure each partial event has different timestamp
DeanChensj Jul 1, 2025
b0d88bf
feat: BaseEvalService declaration and surrounding data models
ankursharmas Jul 1, 2025
a903c54
chore: Add util to build our llms.txt and llms-full.txt files
hangfei Jun 28, 2025
873beca
Merge pull request #1709 from google:my-feature-branch-llmstxt
copybara-github Jul 1, 2025
9af2394
fix: continue the action when `grep -L` returns exit status 1
wuliang229 Jul 1, 2025
0959b06
Fix: Handle unexpected 'parameters' argument in FunctionTool.run_async
google-labs-jules[bot] Jun 26, 2025
d0fdfb8
doc: Update README.md
hangfei Jul 2, 2025
3d2f13c
chore: Update the retry logic of create session polling
DeanChensj Jul 2, 2025
9bd539e
Merge pull request #1656 from google:fix-transfer-to-agent-parameters…
copybara-github Jul 2, 2025
df141db
chore: Add tenacity into project.toml
DeanChensj Jul 2, 2025
08869cc
Merge pull request #1744 from google:hangfei-patch-3
copybara-github Jul 2, 2025
62c4a85
chore: Update ResponseEvaluator to use newer version of Eval SDK
ankursharmas Jul 2, 2025
0bd05df
feat: Add Safety evaluator metric
ankursharmas Jul 2, 2025
362fb3f
fix: scenario where a user can access another users events given the …
sindrigunnars Jun 25, 2025
b04a5ce
Merge pull request #1644 from sindrigunnars:fix-issue-1641-database-s…
copybara-github Jul 2, 2025
6a39c85
chore: update agents.md to include versioning strategy
hangfei Jul 2, 2025
3fa2ea7
fix: Remove duplicate options from `adk deploy`
DeanChensj Jul 3, 2025
e437c7a
fix: Replace Event ID generation with UUID4 to prevent SQLite integri…
rahulsamant37 Jul 3, 2025
4442167
Merge pull request #1778 from rahulsamant37:fix/event-id-uuid4-collis…
copybara-github Jul 4, 2025
a021222
feat: Add `custom_metadata` to VertexAiSessionService event handling
DeanChensj Jul 4, 2025
dc414cb
chore: Add docstring to clarify that inmemory service are not suitabl…
DeanChensj Jul 7, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix: Allow more credentials types for BigQuery tools
This change accepts the `google.auth.credentials.Credentials` type for `BigQueryCredentialsConfig`, so any subclass of that, including `google.oauth2.credentials.Credentials` would work to integrate with BigQuery service. This opens up a whole range of possibilities, such as using service account credentials to deploy an agent using these tools.

PiperOrigin-RevId: 773190440
  • Loading branch information
google-genai-bot authored and copybara-github committed Jun 19, 2025
commit 2f716ada7fbcf8e03ff5ae16ce26a80ca6fd7bf6
23 changes: 19 additions & 4 deletions contributing/samples/bigquery/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,28 @@ would set:
### With Application Default Credentials

This mode is useful for quick development when the agent builder is the only
user interacting with the agent. The tools are initialized with the default
credentials present on the machine running the agent.
user interacting with the agent. The tools are run with these credentials.

1. Create application default credentials on the machine where the agent would
be running by following https://cloud.google.com/docs/authentication/provide-credentials-adc.

1. Set `RUN_WITH_ADC=True` in `agent.py` and run the agent
1. Set `CREDENTIALS_TYPE=None` in `agent.py`

1. Run the agent

### With Service Account Keys

This mode is useful for quick development when the agent builder wants to run
the agent with service account credentials. The tools are run with these
credentials.

1. Create service account key by following https://cloud.google.com/iam/docs/service-account-creds#user-managed-keys.

1. Set `CREDENTIALS_TYPE=AuthCredentialTypes.SERVICE_ACCOUNT` in `agent.py`

1. Download the key file and replace `"service_account_key.json"` with the path

1. Run the agent

### With Interactive OAuth

Expand All @@ -72,7 +87,7 @@ type.
Note: don't create a separate .env, instead put it to the same .env file that
stores your Vertex AI or Dev ML credentials

1. Set `RUN_WITH_ADC=False` in `agent.py` and run the agent
1. Set `CREDENTIALS_TYPE=AuthCredentialTypes.OAUTH2` in `agent.py` and run the agent

## Sample prompts

Expand Down
27 changes: 19 additions & 8 deletions contributing/samples/bigquery/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,31 +15,42 @@
import os

from google.adk.agents import llm_agent
from google.adk.auth import AuthCredentialTypes
from google.adk.tools.bigquery import BigQueryCredentialsConfig
from google.adk.tools.bigquery import BigQueryToolset
from google.adk.tools.bigquery.config import BigQueryToolConfig
from google.adk.tools.bigquery.config import WriteMode
import google.auth

RUN_WITH_ADC = False
# Define an appropriate credential type
CREDENTIALS_TYPE = AuthCredentialTypes.OAUTH2


# Define BigQuery tool config
tool_config = BigQueryToolConfig(write_mode=WriteMode.ALLOWED)

if RUN_WITH_ADC:
# Initialize the tools to use the application default credentials.
application_default_credentials, _ = google.auth.default()
credentials_config = BigQueryCredentialsConfig(
credentials=application_default_credentials
)
else:
if CREDENTIALS_TYPE == AuthCredentialTypes.OAUTH2:
# Initiaze the tools to do interactive OAuth
# The environment variables OAUTH_CLIENT_ID and OAUTH_CLIENT_SECRET
# must be set
credentials_config = BigQueryCredentialsConfig(
client_id=os.getenv("OAUTH_CLIENT_ID"),
client_secret=os.getenv("OAUTH_CLIENT_SECRET"),
)
elif CREDENTIALS_TYPE == AuthCredentialTypes.SERVICE_ACCOUNT:
# Initialize the tools to use the credentials in the service account key.
# If this flow is enabled, make sure to replace the file path with your own
# service account key file
# https://cloud.google.com/iam/docs/service-account-creds#user-managed-keys
creds, _ = google.auth.load_credentials_from_file("service_account_key.json")
credentials_config = BigQueryCredentialsConfig(credentials=creds)
else:
# Initialize the tools to use the application default credentials.
# https://cloud.google.com/docs/authentication/provide-credentials-adc
application_default_credentials, _ = google.auth.default()
credentials_config = BigQueryCredentialsConfig(
credentials=application_default_credentials
)

bigquery_toolset = BigQueryToolset(
credentials_config=credentials_config, bigquery_tool_config=tool_config
Expand Down
39 changes: 28 additions & 11 deletions src/google/adk/tools/bigquery/bigquery_credentials.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@
from fastapi.openapi.models import OAuth2
from fastapi.openapi.models import OAuthFlowAuthorizationCode
from fastapi.openapi.models import OAuthFlows
import google.auth.credentials
from google.auth.exceptions import RefreshError
from google.auth.transport.requests import Request
from google.oauth2.credentials import Credentials
import google.oauth2.credentials
from pydantic import BaseModel
from pydantic import model_validator

Expand All @@ -40,26 +41,35 @@

@experimental
class BigQueryCredentialsConfig(BaseModel):
"""Configuration for Google API tools. (Experimental)"""
"""Configuration for Google API tools (Experimental).

Please do not use this in production, as it may be deprecated later.
"""

# Configure the model to allow arbitrary types like Credentials
model_config = {"arbitrary_types_allowed": True}

credentials: Optional[Credentials] = None
"""the existing oauth credentials to use. If set,this credential will be used
credentials: Optional[google.auth.credentials.Credentials] = None
"""The existing auth credentials to use. If set, this credential will be used
for every end user, end users don't need to be involved in the oauthflow. This
field is mutually exclusive with client_id, client_secret and scopes.
Don't set this field unless you are sure this credential has the permission to
access every end user's data.

Example usage: when the agent is deployed in Google Cloud environment and
Example usage 1: When the agent is deployed in Google Cloud environment and
the service account (used as application default credentials) has access to
all the required BigQuery resource. Setting this credential to allow user to
access the BigQuery resource without end users going through oauth flow.

To get application default credential: `google.auth.default(...)`. See more
To get application default credential, use: `google.auth.default(...)`. See more
details in https://cloud.google.com/docs/authentication/application-default-credentials.

Example usage 2: When the agent wants to access the user's BigQuery resources
using the service account key credentials.

To load service account key credentials, use: `google.auth.load_credentials_from_file(...)`.
See more details in https://cloud.google.com/iam/docs/service-account-creds#user-managed-keys.

When the deployed environment cannot provide a pre-existing credential,
consider setting below client_id, client_secret and scope for end users to go
through oauth flow, so that agent can access the user data.
Expand All @@ -86,7 +96,9 @@ def __post_init__(self) -> BigQueryCredentialsConfig:
" client_id/client_secret/scopes."
)

if self.credentials:
if self.credentials and isinstance(
self.credentials, google.oauth2.credentials.Credentials
):
self.client_id = self.credentials.client_id
self.client_secret = self.credentials.client_secret
self.scopes = self.credentials.scopes
Expand Down Expand Up @@ -115,7 +127,7 @@ def __init__(self, credentials_config: BigQueryCredentialsConfig):

async def get_valid_credentials(
self, tool_context: ToolContext
) -> Optional[Credentials]:
) -> Optional[google.auth.credentials.Credentials]:
"""Get valid credentials, handling refresh and OAuth flow as needed.

Args:
Expand All @@ -127,7 +139,7 @@ async def get_valid_credentials(
# First, try to get credentials from the tool context
creds_json = tool_context.state.get(BIGQUERY_TOKEN_CACHE_KEY, None)
creds = (
Credentials.from_authorized_user_info(
google.oauth2.credentials.Credentials.from_authorized_user_info(
json.loads(creds_json), self.credentials_config.scopes
)
if creds_json
Expand All @@ -138,6 +150,11 @@ async def get_valid_credentials(
if not creds:
creds = self.credentials_config.credentials

# If non-oauth credentials are provided then use them as is. This helps
# in flows such as service account keys
if creds and not isinstance(creds, google.oauth2.credentials.Credentials):
return creds

# Check if we have valid credentials
if creds and creds.valid:
return creds
Expand All @@ -159,7 +176,7 @@ async def get_valid_credentials(

async def _perform_oauth_flow(
self, tool_context: ToolContext
) -> Optional[Credentials]:
) -> Optional[google.oauth2.credentials.Credentials]:
"""Perform OAuth flow to get new credentials.

Args:
Expand Down Expand Up @@ -199,7 +216,7 @@ async def _perform_oauth_flow(

if auth_response:
# OAuth flow completed, create credentials
creds = Credentials(
creds = google.oauth2.credentials.Credentials(
token=auth_response.oauth2.access_token,
refresh_token=auth_response.oauth2.refresh_token,
token_uri=auth_scheme.flows.authorizationCode.tokenUrl,
Expand Down
2 changes: 1 addition & 1 deletion src/google/adk/tools/bigquery/bigquery_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from typing import Callable
from typing import Optional

from google.oauth2.credentials import Credentials
from google.auth.credentials import Credentials
from typing_extensions import override

from ...utils.feature_decorator import experimental
Expand Down
2 changes: 1 addition & 1 deletion src/google/adk/tools/bigquery/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
from __future__ import annotations

import google.api_core.client_info
from google.auth.credentials import Credentials
from google.cloud import bigquery
from google.oauth2.credentials import Credentials

from ... import version

Expand Down
2 changes: 1 addition & 1 deletion src/google/adk/tools/bigquery/metadata_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from google.auth.credentials import Credentials
from google.cloud import bigquery
from google.oauth2.credentials import Credentials

from . import client

Expand Down
2 changes: 1 addition & 1 deletion src/google/adk/tools/bigquery/query_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
import types
from typing import Callable

from google.auth.credentials import Credentials
from google.cloud import bigquery
from google.oauth2.credentials import Credentials

from . import client
from .config import BigQueryToolConfig
Expand Down
47 changes: 36 additions & 11 deletions tests/unittests/tools/bigquery/test_bigquery_credentials.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from unittest.mock import Mock
from unittest import mock

from google.adk.tools.bigquery.bigquery_credentials import BigQueryCredentialsConfig
# Mock the Google OAuth and API dependencies
from google.oauth2.credentials import Credentials
import google.auth.credentials
import google.oauth2.credentials
import pytest


Expand All @@ -27,22 +28,46 @@ class TestBigQueryCredentials:
either existing credentials or client ID/secret pairs are provided.
"""

def test_valid_credentials_object(self):
"""Test that providing valid Credentials object works correctly.
def test_valid_credentials_object_auth_credentials(self):
"""Test that providing valid Credentials object works correctly with
google.auth.credentials.Credentials.

When a user already has valid OAuth credentials, they should be able
to pass them directly without needing to provide client ID/secret.
"""
# Create a mock credentials object with the expected attributes
mock_creds = Mock(spec=Credentials)
mock_creds.client_id = "test_client_id"
mock_creds.client_secret = "test_client_secret"
mock_creds.scopes = ["https://www.googleapis.com/auth/calendar"]
# Create a mock auth credentials object
# auth_creds = google.auth.credentials.Credentials()
auth_creds = mock.create_autospec(
google.auth.credentials.Credentials, instance=True
)

config = BigQueryCredentialsConfig(credentials=auth_creds)

# Verify that the credentials are properly stored and attributes are extracted
assert config.credentials == auth_creds
assert config.client_id is None
assert config.client_secret is None
assert config.scopes == ["https://www.googleapis.com/auth/bigquery"]

def test_valid_credentials_object_oauth2_credentials(self):
"""Test that providing valid Credentials object works correctly with
google.oauth2.credentials.Credentials.

When a user already has valid OAuth credentials, they should be able
to pass them directly without needing to provide client ID/secret.
"""
# Create a mock oauth2 credentials object
oauth2_creds = google.oauth2.credentials.Credentials(
"test_token",
client_id="test_client_id",
client_secret="test_client_secret",
scopes=["https://www.googleapis.com/auth/calendar"],
)

config = BigQueryCredentialsConfig(credentials=mock_creds)
config = BigQueryCredentialsConfig(credentials=oauth2_creds)

# Verify that the credentials are properly stored and attributes are extracted
assert config.credentia 5569 ls == mock_creds
assert config.credentials == oauth2_creds
assert config.client_id == "test_client_id"
assert config.client_secret == "test_client_secret"
assert config.scopes == ["https://www.googleapis.com/auth/calendar"]
Expand Down
Loading
0