2424import os
2525from pathlib import Path
2626import tempfile
27+ import textwrap
2728from typing import Optional
2829
2930import click
@@ -354,7 +355,62 @@ def validate_exclusive(ctx, param, value):
354355 return value
355356
356357
358+ def adk_services_options ():
359+ """Decorator to add ADK services options to click commands."""
360+
361+ def decorator (func ):
362+ @click .option (
363+ "--session_service_uri" ,
364+ help = textwrap .dedent (
365+ """\
366+ Optional. The URI of the session service.
367+ - Leave unset to use the in-memory session service (default).
368+ - Use 'agentengine://<agent_engine>' to connect to Agent Engine
369+ sessions. <agent_engine> can either be the full qualified resource
370+ name 'projects/abc/locations/us-central1/reasoningEngines/123' or
371+ the resource id '123'.
372+ - Use 'memory://' to run with the in-memory session service.
373+ - Use 'sqlite://<path_to_sqlite_file>' to connect to a SQLite DB.
374+ - See https://docs.sqlalchemy.org/en/20/core/engines.html#backend-specific-urls for more details on supported database URIs."""
375+ ),
376+ )
377+ @click .option (
378+ "--artifact_service_uri" ,
379+ type = str ,
380+ help = textwrap .dedent (
381+ """\
382+ Optional. The URI of the artifact service.
383+ - Leave unset to store artifacts under '.adk/artifacts' locally.
384+ - Use 'gs://<bucket_name>' to connect to the GCS artifact service.
385+ - Use 'memory://' to force the in-memory artifact service.
386+ - Use 'file://<path>' to store artifacts in a custom local directory."""
387+ ),
388+ default = None ,
389+ )
390+ @click .option (
391+ "--memory_service_uri" ,
392+ type = str ,
393+ help = textwrap .dedent ("""\
394+ Optional. The URI of the memory service.
395+ - Use 'rag://<rag_corpus_id>' to connect to Vertex AI Rag Memory Service.
396+ - Use 'agentengine://<agent_engine>' to connect to Agent Engine
397+ sessions. <agent_engine> can either be the full qualified resource
398+ name 'projects/abc/locations/us-central1/reasoningEngines/123' or
399+ the resource id '123'.
400+ - Use 'memory://' to force the in-memory memory service.""" ),
401+ default = None ,
402+ )
403+ @functools .wraps (func )
404+ def wrapper (* args , ** kwargs ):
405+ return func (* args , ** kwargs )
406+
407+ return wrapper
408+
409+ return decorator
410+
411+
357412@main .command ("run" , cls = HelpfulCommand )
413+ @adk_services_options ()
358414@click .option (
359415 "--save_session" ,
360416 type = bool ,
@@ -409,6 +465,9 @@ def cli_run(
409465 session_id : Optional [str ],
410466 replay : Optional [str ],
411467 resume : Optional [str ],
468+ session_service_uri : Optional [str ] = None ,
469+ artifact_service_uri : Optional [str ] = None ,
470+ memory_service_uri : Optional [str ] = None ,
412471):
413472 """Runs an interactive CLI for a certain agent.
414473
@@ -420,6 +479,14 @@ def cli_run(
420479 """
421480 logs .log_to_tmp_folder ()
422481
482+ # Validation warning for memory_service_uri (not supported for adk run)
483+ if memory_service_uri :
484+ click .secho (
485+ "WARNING: --memory_service_uri is not supported for adk run." ,
486+ fg = "yellow" ,
487+ err = True ,
488+ )
489+
423490 agent_parent_folder = os .path .dirname (agent )
424491 agent_folder_name = os .path .basename (agent )
425492
@@ -431,6 +498,8 @@ def cli_run(
431498 saved_session_file = resume ,
432499 save_session = save_session ,
433500 session_id = session_id ,
501+ session_service_uri = session_service_uri ,
502+ artifact_service_uri = artifact_service_uri ,
434503 )
435504 )
436505
@@ -865,63 +934,14 @@ def wrapper(*args, **kwargs):
865934 return decorator
866935
867936
868- def adk_services_options ():
869- """Decorator to add ADK services options to click commands."""
870-
871- def decorator (func ):
872- @click .option (
873- "--session_service_uri" ,
874- help = (
875- """Optional. The URI of the session service.
876- - Use 'agentengine://<agent_engine>' to connect to Agent Engine
877- sessions. <agent_engine> can either be the full qualified resource
878- name 'projects/abc/locations/us-central1/reasoningEngines/123' or
879- the resource id '123'.
880- - Use 'sqlite://<path_to_sqlite_file>' to connect to an aio-sqlite
881- based session service, which is good for local development.
882- - Use 'postgresql://<user>:<password>@<host>:<port>/<database_name>'
883- to connect to a PostgreSQL DB.
884- - See https://docs.sqlalchemy.org/en/20/core/engines.html#backend-specific-urls
885- for more details on other database URIs supported by SQLAlchemy."""
886- ),
887- )
888- @click .option (
889- "--artifact_service_uri" ,
890- type = str ,
891- help = (
892- "Optional. The URI of the artifact service,"
893- " supported URIs: gs://<bucket name> for GCS artifact service."
894- ),
895- default = None ,
896- )
897- @click .option (
898- "--memory_service_uri" ,
899- type = str ,
900- help = ("""Optional. The URI of the memory service.
901- - Use 'rag://<rag_corpus_id>' to connect to Vertex AI Rag Memory Service.
902- - Use 'agentengine://<agent_engine>' to connect to Agent Engine
903- sessions. <agent_engine> can either be the full qualified resource
904- name 'projects/abc/locations/us-central1/reasoningEngines/123' or
905- the resource id '123'.""" ),
906- default = None ,
907- )
908- @functools .wraps (func )
909- def wrapper (* args , ** kwargs ):
910- return func (* args , ** kwargs )
911-
912- return wrapper
913-
914- return decorator
915-
916-
917937def deprecated_adk_services_options ():
918938 """Deprecated ADK services options."""
919939
920940 def warn (alternative_param , ctx , param , value ):
921941 if value :
922942 click .echo (
923943 click .style (
924- f"WARNING: Deprecated option { param .name } is used. Please use"
944+ f"WARNING: Deprecated option -- { param .name } is used. Please use"
925945 f" { alternative_param } instead." ,
926946 fg = "yellow" ,
927947 ),
@@ -1116,6 +1136,8 @@ def cli_web(
11161136
11171137 adk web --session_service_uri=[uri] --port=[port] path/to/agents_dir
11181138 """
1139+ session_service_uri = session_service_uri or session_db_url
1140+ artifact_service_uri = artifact_service_uri or artifact_storage_uri
11191141 logs .setup_adk_logger (getattr (logging , log_level .upper ()))
11201142
11211143 @asynccontextmanager
@@ -1140,8 +1162,6 @@ async def _lifespan(app: FastAPI):
11401162 fg = "green" ,
11411163 )
11421164
1143- session_service_uri = session_service_uri or session_db_url
1144- artifact_service_uri = artifact_service_uri or artifact_storage_uri
11451165 app = get_fast_api_app (
11461166 agents_dir = agents_dir ,
11471167 session_service_uri = session_service_uri ,
@@ -1215,10 +1235,10 @@ def cli_api_server(
12151235
12161236 adk api_server --session_service_uri=[uri] --port=[port] path/to/agents_dir
12171237 """
1218- logs .setup_adk_logger (getattr (logging , log_level .upper ()))
1219-
12201238 session_service_uri = session_service_uri or session_db_url
12211239 artifact_service_uri = artifact_service_uri or artifact_storage_uri
1240+ logs .setup_adk_logger (getattr (logging , log_level .upper ()))
1241+
12221242 config = uvicorn .Config (
12231243 get_fast_api_app (
12241244 agents_dir = agents_dir ,
0 commit comments