google-adk 1.4.1__py3-none-any.whl → 1.5.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- google/adk/a2a/converters/event_converter.py +382 -0
- google/adk/a2a/converters/part_converter.py +4 -2
- google/adk/a2a/converters/request_converter.py +90 -0
- google/adk/a2a/converters/utils.py +71 -0
- google/adk/agents/llm_agent.py +5 -3
- google/adk/artifacts/gcs_artifact_service.py +3 -2
- google/adk/auth/auth_tool.py +2 -2
- google/adk/auth/credential_service/session_state_credential_service.py +83 -0
- google/adk/cli/cli_deploy.py +9 -2
- google/adk/cli/cli_tools_click.py +110 -52
- google/adk/cli/fast_api.py +26 -2
- google/adk/cli/utils/evals.py +53 -0
- google/adk/evaluation/final_response_match_v1.py +110 -0
- google/adk/evaluation/gcs_eval_sets_manager.py +8 -5
- google/adk/evaluation/response_evaluator.py +12 -1
- google/adk/events/event.py +5 -5
- google/adk/flows/llm_flows/contents.py +49 -4
- google/adk/flows/llm_flows/functions.py +32 -0
- google/adk/memory/__init__.py +3 -1
- google/adk/memory/vertex_ai_memory_bank_service.py +150 -0
- google/adk/models/lite_llm.py +9 -1
- google/adk/runners.py +10 -0
- google/adk/sessions/vertex_ai_session_service.py +70 -19
- google/adk/telemetry.py +10 -0
- google/adk/tools/bigquery/bigquery_credentials.py +28 -11
- google/adk/tools/bigquery/bigquery_tool.py +1 -1
- google/adk/tools/bigquery/client.py +1 -1
- google/adk/tools/bigquery/metadata_tool.py +1 -1
- google/adk/tools/bigquery/query_tool.py +1 -1
- google/adk/version.py +1 -1
- {google_adk-1.4.1.dist-info → google_adk-1.5.0.dist-info}/METADATA +6 -5
- {google_adk-1.4.1.dist-info → google_adk-1.5.0.dist-info}/RECORD +35 -29
- {google_adk-1.4.1.dist-info → google_adk-1.5.0.dist-info}/WHEEL +0 -0
- {google_adk-1.4.1.dist-info → google_adk-1.5.0.dist-info}/entry_points.txt +0 -0
- {google_adk-1.4.1.dist-info → google_adk-1.5.0.dist-info}/licenses/LICENSE +0 -0
@@ -0,0 +1,83 @@
|
|
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 __future__ import annotations
|
16
|
+
|
17
|
+
from typing import Optional
|
18
|
+
|
19
|
+
from typing_extensions import override
|
20
|
+
|
21
|
+
from ...tools.tool_context import ToolContext
|
22
|
+
from ...utils.feature_decorator import experimental
|
23
|
+
from ..auth_credential import AuthCredential
|
24
|
+
from ..auth_tool import AuthConfig
|
25
|
+
from .base_credential_service import BaseCredentialService
|
26
|
+
|
27
|
+
|
28
|
+
@experimental
|
29
|
+
class SessionStateCredentialService(BaseCredentialService):
|
30
|
+
"""Class for implementation of credential service using session state as the
|
31
|
+
store.
|
32
|
+
Note: store credential in session may not be secure, use at your own risk.
|
33
|
+
"""
|
34
|
+
|
35
|
+
@override
|
36
|
+
async def load_credential(
|
37
|
+
self,
|
38
|
+
auth_config: AuthConfig,
|
39
|
+
tool_context: ToolContext,
|
40
|
+
) -> Optional[AuthCredential]:
|
41
|
+
"""
|
42
|
+
Loads the credential by auth config and current tool context from the
|
43
|
+
backend credential store.
|
44
|
+
|
45
|
+
Args:
|
46
|
+
auth_config: The auth config which contains the auth scheme and auth
|
47
|
+
credential information. auth_config.get_credential_key will be used to
|
48
|
+
build the key to load the credential.
|
49
|
+
|
50
|
+
tool_context: The context of the current invocation when the tool is
|
51
|
+
trying to load the credential.
|
52
|
+
|
53
|
+
Returns:
|
54
|
+
Optional[AuthCredential]: the credential saved in the store.
|
55
|
+
|
56
|
+
"""
|
57
|
+
return tool_context.state.get(auth_config.credential_key)
|
58
|
+
|
59
|
+
@override
|
60
|
+
async def save_credential(
|
61
|
+
self,
|
62
|
+
auth_config: AuthConfig,
|
63
|
+
tool_context: ToolContext,
|
64
|
+
) -> None:
|
65
|
+
"""
|
66
|
+
Saves the exchanged_auth_credential in auth config to the backend credential
|
67
|
+
store.
|
68
|
+
|
69
|
+
Args:
|
70
|
+
auth_config: The auth config which contains the auth scheme and auth
|
71
|
+
credential information. auth_config.get_credential_key will be used to
|
72
|
+
build the key to save the credential.
|
73
|
+
|
74
|
+
tool_context: The context of the current invocation when the tool is
|
75
|
+
trying to save the credential.
|
76
|
+
|
77
|
+
Returns:
|
78
|
+
None
|
79
|
+
"""
|
80
|
+
|
81
|
+
tool_context.state[auth_config.credential_key] = (
|
82
|
+
auth_config.exchanged_auth_credential
|
83
|
+
)
|
google/adk/cli/cli_deploy.py
CHANGED
@@ -55,7 +55,7 @@ COPY "agents/{app_name}/" "/app/agents/{app_name}/"
|
|
55
55
|
|
56
56
|
EXPOSE {port}
|
57
57
|
|
58
|
-
CMD adk {command} --port={port} {host_option} {service_option} {trace_to_cloud_option} "/app/agents"
|
58
|
+
CMD adk {command} --port={port} {host_option} {service_option} {trace_to_cloud_option} {allow_origins_option} "/app/agents"
|
59
59
|
"""
|
60
60
|
|
61
61
|
_AGENT_ENGINE_APP_TEMPLATE = """
|
@@ -121,8 +121,10 @@ def to_cloud_run(
|
|
121
121
|
port: int,
|
122
122
|
trace_to_cloud: bool,
|
123
123
|
with_ui: bool,
|
124
|
+
log_level: str,
|
124
125
|
verbosity: str,
|
125
126
|
adk_version: str,
|
127
|
+
allow_origins: Optional[list[str]] = None,
|
126
128
|
session_service_uri: Optional[str] = None,
|
127
129
|
artifact_service_uri: Optional[str] = None,
|
128
130
|
memory_service_uri: Optional[str] = None,
|
@@ -150,6 +152,7 @@ def to_cloud_run(
|
|
150
152
|
app_name: The name of the app, by default, it's basename of `agent_folder`.
|
151
153
|
temp_folder: The temp folder for the generated Cloud Run source files.
|
152
154
|
port: The port of the ADK api server.
|
155
|
+
allow_origins: The list of allowed origins for the ADK api server.
|
153
156
|
trace_to_cloud: Whether to enable Cloud Trace.
|
154
157
|
with_ui: Whether to deploy with UI.
|
155
158
|
verbosity: The verbosity level of the CLI.
|
@@ -183,6 +186,9 @@ def to_cloud_run(
|
|
183
186
|
# create Dockerfile
|
184
187
|
click.echo('Creating Dockerfile...')
|
185
188
|
host_option = '--host=0.0.0.0' if adk_version > '0.5.0' else ''
|
189
|
+
allow_origins_option = (
|
190
|
+
f'--allow_origins={",".join(allow_origins)}' if allow_origins else ''
|
191
|
+
)
|
186
192
|
dockerfile_content = _DOCKERFILE_TEMPLATE.format(
|
187
193
|
gcp_project_id=project,
|
188
194
|
gcp_region=region,
|
@@ -197,6 +203,7 @@ def to_cloud_run(
|
|
197
203
|
memory_service_uri,
|
198
204
|
),
|
199
205
|
trace_to_cloud_option='--trace_to_cloud' if trace_to_cloud else '',
|
206
|
+
allow_origins_option=allow_origins_option,
|
200
207
|
adk_version=adk_version,
|
201
208
|
host_option=host_option,
|
202
209
|
)
|
@@ -226,7 +233,7 @@ def to_cloud_run(
|
|
226
233
|
'--port',
|
227
234
|
str(port),
|
228
235
|
'--verbosity',
|
229
|
-
verbosity,
|
236
|
+
log_level.lower() if log_level else verbosity,
|
230
237
|
'--labels',
|
231
238
|
'created-by=adk',
|
232
239
|
],
|
@@ -31,14 +31,22 @@ import uvicorn
|
|
31
31
|
from . import cli_create
|
32
32
|
from . import cli_deploy
|
33
33
|
from .. import version
|
34
|
+
from ..evaluation.gcs_eval_set_results_manager import GcsEvalSetResultsManager
|
35
|
+
from ..evaluation.gcs_eval_sets_manager import GcsEvalSetsManager
|
34
36
|
from ..evaluation.local_eval_set_results_manager import LocalEvalSetResultsManager
|
35
37
|
from ..sessions.in_memory_session_service import InMemorySessionService
|
36
38
|
from .cli import run_cli
|
37
39
|
from .cli_eval import MISSING_EVAL_DEPENDENCIES_MESSAGE
|
38
40
|
from .fast_api import get_fast_api_app
|
39
41
|
from .utils import envs
|
42
|
+
from .utils import evals
|
40
43
|
from .utils import logs
|
41
44
|
|
45
|
+
LOG_LEVELS = click.Choice(
|
46
|
+
["DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"],
|
47
|
+
case_sensitive=False,
|
48
|
+
)
|
49
|
+
|
42
50
|
|
43
51
|
class HelpfulCommand(click.Command):
|
44
52
|
"""Command that shows full help on error instead of just the error message.
|
@@ -277,11 +285,21 @@ def cli_run(
|
|
277
285
|
default=False,
|
278
286
|
help="Optional. Whether to print detailed results on console or not.",
|
279
287
|
)
|
288
|
+
@click.option(
|
289
|
+
"--eval_storage_uri",
|
290
|
+
type=str,
|
291
|
+
help=(
|
292
|
+
"Optional. The evals storage URI to store agent evals,"
|
293
|
+
" supported URIs: gs://<bucket name>."
|
294
|
+
),
|
295
|
+
default=None,
|
296
|
+
)
|
280
297
|
def cli_eval(
|
281
298
|
agent_module_file_path: str,
|
282
|
-
eval_set_file_path:
|
299
|
+
eval_set_file_path: list[str],
|
283
300
|
config_file_path: str,
|
284
301
|
print_detailed_results: bool,
|
302
|
+
eval_storage_uri: Optional[str] = None,
|
285
303
|
):
|
286
304
|
"""Evaluates an agent given the eval sets.
|
287
305
|
|
@@ -333,12 +351,33 @@ def cli_eval(
|
|
333
351
|
root_agent = get_root_agent(agent_module_file_path)
|
334
352
|
reset_func = try_get_reset_func(agent_module_file_path)
|
335
353
|
|
354
|
+
gcs_eval_sets_manager = None
|
355
|
+
eval_set_results_manager = None
|
356
|
+
if eval_storage_uri:
|
357
|
+
gcs_eval_managers = evals.create_gcs_eval_managers_from_uri(
|
358
|
+
eval_storage_uri
|
359
|
+
)
|
360
|
+
gcs_eval_sets_manager = gcs_eval_managers.eval_sets_manager
|
361
|
+
eval_set_results_manager = gcs_eval_managers.eval_set_results_manager
|
362
|
+
else:
|
363
|
+
eval_set_results_manager = LocalEvalSetResultsManager(
|
364
|
+
agents_dir=os.path.dirname(agent_module_file_path)
|
365
|
+
)
|
336
366
|
eval_set_file_path_to_evals = parse_and_get_evals_to_run(eval_set_file_path)
|
337
367
|
eval_set_id_to_eval_cases = {}
|
338
368
|
|
339
369
|
# Read the eval_set files and get the cases.
|
340
370
|
for eval_set_file_path, eval_case_ids in eval_set_file_path_to_evals.items():
|
341
|
-
|
371
|
+
if gcs_eval_sets_manager:
|
372
|
+
eval_set = gcs_eval_sets_manager._load_eval_set_from_blob(
|
373
|
+
eval_set_file_path
|
374
|
+
)
|
375
|
+
if not eval_set:
|
376
|
+
raise click.ClickException(
|
377
|
+
f"Eval set {eval_set_file_path} not found in GCS."
|
378
|
+
)
|
379
|
+
else:
|
380
|
+
eval_set = load_eval_set_from_file(eval_set_file_path, eval_set_file_path)
|
342
381
|
eval_cases = eval_set.eval_cases
|
343
382
|
|
344
383
|
if eval_case_ids:
|
@@ -373,16 +412,13 @@ def cli_eval(
|
|
373
412
|
raise click.ClickException(MISSING_EVAL_DEPENDENCIES_MESSAGE)
|
374
413
|
|
375
414
|
# Write eval set results.
|
376
|
-
local_eval_set_results_manager = LocalEvalSetResultsManager(
|
377
|
-
agents_dir=os.path.dirname(agent_module_file_path)
|
378
|
-
)
|
379
415
|
eval_set_id_to_eval_results = collections.defaultdict(list)
|
380
416
|
for eval_case_result in eval_results:
|
381
417
|
eval_set_id = eval_case_result.eval_set_id
|
382
418
|
eval_set_id_to_eval_results[eval_set_id].append(eval_case_result)
|
383
419
|
|
384
420
|
for eval_set_id, eval_case_results in eval_set_id_to_eval_results.items():
|
385
|
-
|
421
|
+
eval_set_results_manager.save_eval_set_result(
|
386
422
|
app_name=os.path.basename(agent_module_file_path),
|
387
423
|
eval_set_id=eval_set_id,
|
388
424
|
eval_case_results=eval_case_results,
|
@@ -439,12 +475,22 @@ def adk_services_options():
|
|
439
475
|
),
|
440
476
|
default=None,
|
441
477
|
)
|
478
|
+
@click.option(
|
479
|
+
"--eval_storage_uri",
|
480
|
+
type=str,
|
481
|
+
help=(
|
482
|
+
"Optional. The evals storage URI to store agent evals,"
|
483
|
+
" supported URIs: gs://<bucket name>."
|
484
|
+
),
|
485
|
+
default=None,
|
486
|
+
)
|
442
487
|
@click.option(
|
443
488
|
"--memory_service_uri",
|
444
489
|
type=str,
|
445
490
|
help=(
|
446
491
|
"""Optional. The URI of the memory service.
|
447
|
-
- Use 'rag://<rag_corpus_id>' to connect to Vertex AI Rag Memory Service.
|
492
|
+
- Use 'rag://<rag_corpus_id>' to connect to Vertex AI Rag Memory Service.
|
493
|
+
- Use 'agentengine://<agent_engine_resource_id>' to connect to Vertex AI Memory Bank Service. e.g. agentengine://12345"""
|
448
494
|
),
|
449
495
|
default=None,
|
450
496
|
)
|
@@ -498,13 +544,6 @@ def fast_api_common_options():
|
|
498
544
|
"""Decorator to add common fast api options to click commands."""
|
499
545
|
|
500
546
|
def decorator(func):
|
501
|
-
@click.option(
|
502
|
-
"--host",
|
503
|
-
type=str,
|
504
|
-
help="Optional. The binding host of the server",
|
505
|
-
default="127.0.0.1",
|
506
|
-
show_default=True,
|
507
|
-
)
|
508
547
|
@click.option(
|
509
548
|
"--port",
|
510
549
|
type=int,
|
@@ -518,10 +557,7 @@ def fast_api_common_options():
|
|
518
557
|
)
|
519
558
|
@click.option(
|
520
559
|
"--log_level",
|
521
|
-
type=
|
522
|
-
["DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"],
|
523
|
-
case_sensitive=False,
|
524
|
-
),
|
560
|
+
type=LOG_LEVELS,
|
525
561
|
default="INFO",
|
526
562
|
help="Optional. Set the logging level",
|
527
563
|
)
|
@@ -535,7 +571,10 @@ def fast_api_common_options():
|
|
535
571
|
@click.option(
|
536
572
|
"--reload/--no-reload",
|
537
573
|
default=True,
|
538
|
-
help=
|
574
|
+
help=(
|
575
|
+
"Optional. Whether to enable auto reload for server. Not supported"
|
576
|
+
" for Cloud Run."
|
577
|
+
),
|
539
578
|
)
|
540
579
|
@functools.wraps(func)
|
541
580
|
def wrapper(*args, **kwargs):
|
@@ -547,6 +586,13 @@ def fast_api_common_options():
|
|
547
586
|
|
548
587
|
|
549
588
|
@main.command("web")
|
589
|
+
@click.option(
|
590
|
+
"--host",
|
591
|
+
type=str,
|
592
|
+
help="Optional. The binding host of the server",
|
593
|
+
default="127.0.0.1",
|
594
|
+
show_default=True,
|
595
|
+
)
|
550
596
|
@fast_api_common_options()
|
551
597
|
@adk_services_options()
|
552
598
|
@deprecated_adk_services_options()
|
@@ -559,6 +605,7 @@ def fast_api_common_options():
|
|
559
605
|
)
|
560
606
|
def cli_web(
|
561
607
|
agents_dir: str,
|
608
|
+
eval_storage_uri: Optional[str] = None,
|
562
609
|
log_level: str = "INFO",
|
563
610
|
allow_origins: Optional[list[str]] = None,
|
564
611
|
host: str = "127.0.0.1",
|
@@ -578,7 +625,7 @@ def cli_web(
|
|
578
625
|
|
579
626
|
Example:
|
580
627
|
|
581
|
-
adk web --
|
628
|
+
adk web --port=[port] path/to/agents_dir
|
582
629
|
"""
|
583
630
|
logs.setup_adk_logger(getattr(logging, log_level.upper()))
|
584
631
|
|
@@ -611,6 +658,7 @@ def cli_web(
|
|
611
658
|
session_service_uri=session_service_uri,
|
612
659
|
artifact_service_uri=artifact_service_uri,
|
613
660
|
memory_service_uri=memory_service_uri,
|
661
|
+
eval_storage_uri=eval_storage_uri,
|
614
662
|
allow_origins=allow_origins,
|
615
663
|
web=True,
|
616
664
|
trace_to_cloud=trace_to_cloud,
|
@@ -628,6 +676,16 @@ def cli_web(
|
|
628
676
|
|
629
677
|
|
630
678
|
@main.command("api_server")
|
679
|
+
@click.option(
|
680
|
+
"--host",
|
681
|
+
type=str,
|
682
|
+
help="Optional. The binding host of the server",
|
683
|
+
default="127.0.0.1",
|
684
|
+
show_default=True,
|
685
|
+
)
|
686
|
+
@fast_api_common_options()
|
687
|
+
@adk_services_options()
|
688
|
+
@deprecated_adk_services_options()
|
631
689
|
# The directory of agents, where each sub-directory is a single agent.
|
632
690
|
# By default, it is the current working directory
|
633
691
|
@click.argument(
|
@@ -637,11 +695,9 @@ def cli_web(
|
|
637
695
|
),
|
638
696
|
default=os.getcwd(),
|
639
697
|
)
|
640
|
-
@fast_api_common_options()
|
641
|
-
@adk_services_options()
|
642
|
-
@deprecated_adk_services_options()
|
643
698
|
def cli_api_server(
|
644
699
|
agents_dir: str,
|
700
|
+
eval_storage_uri: Optional[str] = None,
|
645
701
|
log_level: str = "INFO",
|
646
702
|
allow_origins: Optional[list[str]] = None,
|
647
703
|
host: str = "127.0.0.1",
|
@@ -661,7 +717,7 @@ def cli_api_server(
|
|
661
717
|
|
662
718
|
Example:
|
663
719
|
|
664
|
-
adk api_server --
|
720
|
+
adk api_server --port=[port] path/to/agents_dir
|
665
721
|
"""
|
666
722
|
logs.setup_adk_logger(getattr(logging, log_level.upper()))
|
667
723
|
|
@@ -673,6 +729,7 @@ def cli_api_server(
|
|
673
729
|
session_service_uri=session_service_uri,
|
674
730
|
artifact_service_uri=artifact_service_uri,
|
675
731
|
memory_service_uri=memory_service_uri,
|
732
|
+
eval_storage_uri=eval_storage_uri,
|
676
733
|
allow_origins=allow_origins,
|
677
734
|
web=False,
|
678
735
|
trace_to_cloud=trace_to_cloud,
|
@@ -720,19 +777,7 @@ def cli_api_server(
|
|
720
777
|
" of the AGENT source code)."
|
721
778
|
),
|
722
779
|
)
|
723
|
-
@
|
724
|
-
"--port",
|
725
|
-
type=int,
|
726
|
-
default=8000,
|
727
|
-
help="Optional. The port of the ADK API server (default: 8000).",
|
728
|
-
)
|
729
|
-
@click.option(
|
730
|
-
"--trace_to_cloud",
|
731
|
-
is_flag=True,
|
732
|
-
show_default=True,
|
733
|
-
default=False,
|
734
|
-
help="Optional. Whether to enable Cloud Trace for cloud run.",
|
735
|
-
)
|
780
|
+
@fast_api_common_options()
|
736
781
|
@click.option(
|
737
782
|
"--with_ui",
|
738
783
|
is_flag=True,
|
@@ -743,6 +788,11 @@ def cli_api_server(
|
|
743
788
|
" only)"
|
744
789
|
),
|
745
790
|
)
|
791
|
+
@click.option(
|
792
|
+
"--verbosity",
|
793
|
+
type=LOG_LEVELS,
|
794
|
+
help="Deprecated. Use --log_level instead.",
|
795
|
+
)
|
746
796
|
@click.option(
|
747
797
|
"--temp_folder",
|
748
798
|
type=str,
|
@@ -756,20 +806,6 @@ def cli_api_server(
|
|
756
806
|
" (default: a timestamped folder in the system temp directory)."
|
757
807
|
),
|
758
808
|
)
|
759
|
-
@click.option(
|
760
|
-
"--verbosity",
|
761
|
-
type=click.Choice(
|
762
|
-
["debug", "info", "warning", "error", "critical"], case_sensitive=False
|
763
|
-
),
|
764
|
-
default="WARNING",
|
765
|
-
help="Optional. Override the default verbosity level.",
|
766
|
-
)
|
767
|
-
@click.argument(
|
768
|
-
"agent",
|
769
|
-
type=click.Path(
|
770
|
-
exists=True, dir_okay=True, file_okay=False, resolve_path=True
|
771
|
-
),
|
772
|
-
)
|
773
809
|
@click.option(
|
774
810
|
"--adk_version",
|
775
811
|
type=str,
|
@@ -780,8 +816,23 @@ def cli_api_server(
|
|
780
816
|
" version in the dev environment)"
|
781
817
|
),
|
782
818
|
)
|
819
|
+
@click.option(
|
820
|
+
"--eval_storage_uri",
|
821
|
+
type=str,
|
822
|
+
help=(
|
823
|
+
"Optional. The evals storage URI to store agent evals,"
|
824
|
+
" supported URIs: gs://<bucket name>."
|
825
|
+
),
|
826
|
+
default=None,
|
827
|
+
)
|
783
828
|
@adk_services_options()
|
784
829
|
@deprecated_adk_services_options()
|
830
|
+
@click.argument(
|
831
|
+
"agent",
|
832
|
+
type=click.Path(
|
833
|
+
exists=True, dir_okay=True, file_okay=False, resolve_path=True
|
834
|
+
),
|
835
|
+
)
|
785
836
|
def cli_deploy_cloud_run(
|
786
837
|
agent: str,
|
787
838
|
project: Optional[str],
|
@@ -792,11 +843,15 @@ def cli_deploy_cloud_run(
|
|
792
843
|
port: int,
|
793
844
|
trace_to_cloud: bool,
|
794
845
|
with_ui: bool,
|
795
|
-
verbosity: str,
|
796
846
|
adk_version: str,
|
847
|
+
log_level: Optional[str] = None,
|
848
|
+
verbosity: str = "WARNING",
|
849
|
+
reload: bool = True,
|
850
|
+
allow_origins: Optional[list[str]] = None,
|
797
851
|
session_service_uri: Optional[str] = None,
|
798
852
|
artifact_service_uri: Optional[str] = None,
|
799
853
|
memory_service_uri: Optional[str] = None,
|
854
|
+
eval_storage_uri: Optional[str] = None,
|
800
855
|
session_db_url: Optional[str] = None, # Deprecated
|
801
856
|
artifact_storage_uri: Optional[str] = None, # Deprecated
|
802
857
|
):
|
@@ -808,6 +863,7 @@ def cli_deploy_cloud_run(
|
|
808
863
|
|
809
864
|
adk deploy cloud_run --project=[project] --region=[region] path/to/my_agent
|
810
865
|
"""
|
866
|
+
log_level = log_level or verbosity
|
811
867
|
session_service_uri = session_service_uri or session_db_url
|
812
868
|
artifact_service_uri = artifact_service_uri or artifact_storage_uri
|
813
869
|
try:
|
@@ -820,7 +876,9 @@ def cli_deploy_cloud_run(
|
|
820
876
|
temp_folder=temp_folder,
|
821
877
|
port=port,
|
822
878
|
trace_to_cloud=trace_to_cloud,
|
879
|
+
allow_origins=allow_origins,
|
823
880
|
with_ui=with_ui,
|
881
|
+
log_level=log_level,
|
824
882
|
verbosity=verbosity,
|
825
883
|
adk_version=adk_version,
|
826
884
|
session_service_uri=session_service_uri,
|
google/adk/cli/fast_api.py
CHANGED
@@ -65,10 +65,13 @@ from ..evaluation.eval_metrics import EvalMetric
|
|
65
65
|
from ..evaluation.eval_metrics import EvalMetricResult
|
66
66
|
from ..evaluation.eval_metrics import EvalMetricResultPerInvocation
|
67
67
|
from ..evaluation.eval_result import EvalSetResult
|
68
|
+
from ..evaluation.gcs_eval_set_results_manager import GcsEvalSetResultsManager
|
69
|
+
from ..evaluation.gcs_eval_sets_manager import GcsEvalSetsManager
|
68
70
|
from ..evaluation.local_eval_set_results_manager import LocalEvalSetResultsManager
|
69
71
|
from ..evaluation.local_eval_sets_manager import LocalEvalSetsManager
|
70
72
|
from ..events.event import Event
|
71
73
|
from ..memory.in_memory_memory_service import InMemoryMemoryService
|
74
|
+
from ..memory.vertex_ai_memory_bank_service import VertexAiMemoryBankService
|
72
75
|
from ..memory.vertex_ai_rag_memory_service import VertexAiRagMemoryService
|
73
76
|
from ..runners import Runner
|
74
77
|
from ..sessions.database_session_service import DatabaseSessionService
|
@@ -198,6 +201,7 @@ def get_fast_api_app(
|
|
198
201
|
session_service_uri: Optional[str] = None,
|
199
202
|
artifact_service_uri: Optional[str] = None,
|
200
203
|
memory_service_uri: Optional[str] = None,
|
204
|
+
eval_storage_uri: Optional[str] = None,
|
201
205
|
allow_origins: Optional[list[str]] = None,
|
202
206
|
web: bool,
|
203
207
|
trace_to_cloud: bool = False,
|
@@ -256,8 +260,18 @@ def get_fast_api_app(
|
|
256
260
|
|
257
261
|
runner_dict = {}
|
258
262
|
|
259
|
-
|
260
|
-
|
263
|
+
# Set up eval managers.
|
264
|
+
eval_sets_manager = None
|
265
|
+
eval_set_results_manager = None
|
266
|
+
if eval_storage_uri:
|
267
|
+
gcs_eval_managers = evals.create_gcs_eval_managers_from_uri(
|
268
|
+
eval_storage_uri
|
269
|
+
)
|
270
|
+
eval_sets_manager = gcs_eval_managers.eval_sets_manager
|
271
|
+
eval_set_results_manager = gcs_eval_managers.eval_set_results_manager
|
272
|
+
else:
|
273
|
+
eval_sets_manager = LocalEvalSetsManager(agents_dir=agents_dir)
|
274
|
+
eval_set_results_manager = LocalEvalSetResultsManager(agents_dir=agents_dir)
|
261
275
|
|
262
276
|
# Build the Memory service
|
263
277
|
if memory_service_uri:
|
@@ -269,6 +283,16 @@ def get_fast_api_app(
|
|
269
283
|
memory_service = VertexAiRagMemoryService(
|
270
284
|
rag_corpus=f'projects/{os.environ["GOOGLE_CLOUD_PROJECT"]}/locations/{os.environ["GOOGLE_CLOUD_LOCATION"]}/ragCorpora/{rag_corpus}'
|
271
285
|
)
|
286
|
+
elif memory_service_uri.startswith("agentengine://"):
|
287
|
+
agent_engine_id = memory_service_uri.split("://")[1]
|
288
|
+
if not agent_engine_id:
|
289
|
+
raise click.ClickException("Agent engine id can not be empty.")
|
290
|
+
envs.load_dotenv_for_agent("", agents_dir)
|
291
|
+
memory_service = VertexAiMemoryBankService(
|
292
|
+
project=os.environ["GOOGLE_CLOUD_PROJECT"],
|
293
|
+
location=os.environ["GOOGLE_CLOUD_LOCATION"],
|
294
|
+
agent_engine_id=agent_engine_id,
|
295
|
+
)
|
272
296
|
else:
|
273
297
|
raise click.ClickException(
|
274
298
|
"Unsupported memory service URI: %s" % memory_service_uri
|
google/adk/cli/utils/evals.py
CHANGED
@@ -14,17 +14,36 @@
|
|
14
14
|
|
15
15
|
from __future__ import annotations
|
16
16
|
|
17
|
+
import dataclasses
|
18
|
+
import os
|
17
19
|
from typing import Any
|
18
20
|
from typing import Tuple
|
19
21
|
|
20
22
|
from google.genai import types as genai_types
|
23
|
+
from pydantic import alias_generators
|
24
|
+
from pydantic import BaseModel
|
25
|
+
from pydantic import ConfigDict
|
21
26
|
from typing_extensions import deprecated
|
22
27
|
|
23
28
|
from ...evaluation.eval_case import IntermediateData
|
24
29
|
from ...evaluation.eval_case import Invocation
|
30
|
+
from ...evaluation.gcs_eval_set_results_manager import GcsEvalSetResultsManager
|
31
|
+
from ...evaluation.gcs_eval_sets_manager import GcsEvalSetsManager
|
25
32
|
from ...sessions.session import Session
|
26
33
|
|
27
34
|
|
35
|
+
class GcsEvalManagers(BaseModel):
|
36
|
+
model_config = ConfigDict(
|
37
|
+
alias_generator=alias_generators.to_camel,
|
38
|
+
populate_by_name=True,
|
39
|
+
arbitrary_types_allowed=True,
|
40
|
+
)
|
41
|
+
|
42
|
+
eval_sets_manager: GcsEvalSetsManager
|
43
|
+
|
44
|
+
eval_set_results_manager: GcsEvalSetResultsManager
|
45
|
+
|
46
|
+
|
28
47
|
@deprecated('Use convert_session_to_eval_invocations instead.')
|
29
48
|
def convert_session_to_eval_format(session: Session) -> list[dict[str, Any]]:
|
30
49
|
"""Converts a session data into eval format.
|
@@ -176,3 +195,37 @@ def convert_session_to_eval_invocations(session: Session) -> list[Invocation]:
|
|
176
195
|
)
|
177
196
|
|
178
197
|
return invocations
|
198
|
+
|
199
|
+
|
200
|
+
def create_gcs_eval_managers_from_uri(
|
201
|
+
eval_storage_uri: str,
|
202
|
+
) -> GcsEvalManagers:
|
203
|
+
"""Creates GcsEvalManagers from eval_storage_uri.
|
204
|
+
|
205
|
+
Args:
|
206
|
+
eval_storage_uri: The evals storage URI to use. Supported URIs:
|
207
|
+
gs://<bucket name>. If a path is provided, the bucket will be extracted.
|
208
|
+
|
209
|
+
Returns:
|
210
|
+
GcsEvalManagers: The GcsEvalManagers object.
|
211
|
+
|
212
|
+
Raises:
|
213
|
+
ValueError: If the eval_storage_uri is not supported.
|
214
|
+
"""
|
215
|
+
if eval_storage_uri.startswith('gs://'):
|
216
|
+
gcs_bucket = eval_storage_uri.split('://')[1]
|
217
|
+
eval_sets_manager = GcsEvalSetsManager(
|
218
|
+
bucket_name=gcs_bucket, project=os.environ['GOOGLE_CLOUD_PROJECT']
|
219
|
+
)
|
220
|
+
eval_set_results_manager = GcsEvalSetResultsManager(
|
221
|
+
bucket_name=gcs_bucket, project=os.environ['GOOGLE_CLOUD_PROJECT']
|
222
|
+
)
|
223
|
+
return GcsEvalManagers(
|
224
|
+
eval_sets_manager=eval_sets_manager,
|
225
|
+
eval_set_results_manager=eval_set_results_manager,
|
226
|
+
)
|
227
|
+
else:
|
228
|
+
raise ValueError(
|
229
|
+
f'Unsupported evals storage URI: {eval_storage_uri}. Supported URIs:'
|
230
|
+
' gs://<bucket name>'
|
231
|
+
)
|