18
18
import collections
19
19
from contextlib import asynccontextmanager
20
20
from datetime import datetime
21
+ import functools
21
22
import logging
22
23
import os
23
24
import tempfile
@@ -416,57 +417,69 @@ async def _collect_eval_results() -> list[EvalCaseResult]:
416
417
print (eval_result .model_dump_json (indent = 2 ))
417
418
418
419
419
- @main .command ("web" )
420
- @click .option (
421
- "--session_db_url" ,
422
- help = (
423
- """Optional. The database URL to store the session.
420
+ def fast_api_common_options ():
421
+ """Decorator to add common fast api options to click commands."""
424
422
425
- - Use 'agentengine://<agent_engine_resource_id>' to connect to Agent Engine sessions.
423
+ def decorator (func ):
424
+ @click .option (
425
+ "--session_db_url" ,
426
+ help = (
427
+ """Optional. The database URL to store the session.
428
+ - Use 'agentengine://<agent_engine_resource_id>' to connect to Agent Engine sessions.
429
+ - Use 'sqlite://<path_to_sqlite_file>' to connect to a SQLite DB.
430
+ - See https://docs.sqlalchemy.org/en/20/core/engines.html#backend-specific-urls for more details on supported DB URLs."""
431
+ ),
432
+ )
433
+ @click .option (
434
+ "--host" ,
435
+ type = str ,
436
+ help = "Optional. The binding host of the server" ,
437
+ default = "127.0.0.1" ,
438
+ show_default = True ,
439
+ )
440
+ @click .option (
441
+ "--port" ,
442
+ type = int ,
443
+ help = "Optional. The port of the server" ,
444
+ default = 8000 ,
445
+ )
446
+ @click .option (
447
+ "--allow_origins" ,
448
+ help = "Optional. Any additional origins to allow for CORS." ,
449
+ multiple = True ,
450
+ )
451
+ @click .option (
452
+ "--log_level" ,
453
+ type = click .Choice (
454
+ ["DEBUG" , "INFO" , "WARNING" , "ERROR" , "CRITICAL" ],
455
+ case_sensitive = False ,
456
+ ),
457
+ default = "INFO" ,
458
+ help = "Optional. Set the logging level" ,
459
+ )
460
+ @click .option (
461
+ "--trace_to_cloud" ,
462
+ is_flag = True ,
463
+ show_default = True ,
464
+ default = False ,
465
+ help = "Optional. Whether to enable cloud trace for telemetry." ,
466
+ )
467
+ @click .option (
468
+ "--reload/--no-reload" ,
469
+ default = True ,
470
+ help = "Optional. Whether to enable auto reload for server." ,
471
+ )
472
+ @functools .wraps (func )
473
+ def wrapper (* args , ** kwargs ):
474
+ return func (* args , ** kwargs )
426
475
427
- - Use 'sqlite://<path_to_sqlite_file>' to connect to a SQLite DB.
476
+ return wrapper
428
477
429
- - See https://docs.sqlalchemy.org/en/20/core/engines.html#backend-specific-urls for more details on supported DB URLs."""
430
- ),
431
- )
432
- @click .option (
433
- "--host" ,
434
- type = str ,
435
- help = "Optional. The binding host of the server" ,
436
- default = "127.0.0.1" ,
437
- show_default = True ,
438
- )
439
- @click .option (
440
- "--port" ,
441
- type = int ,
442
- help = "Optional. The port of the server" ,
443
- default = 8000 ,
444
- )
445
- @click .option (
446
- "--allow_origins" ,
447
- help = "Optional. Any additional origins to allow for CORS." ,
448
- multiple = True ,
449
- )
450
- @click .option (
451
- "--log_level" ,
452
- type = click .Choice (
453
- ["DEBUG" , "INFO" , "WARNING" , "ERROR" , "CRITICAL" ], case_sensitive = False
454
- ),
455
- default = "INFO" ,
456
- help = "Optional. Set the logging level" ,
457
- )
458
- @click .option (
459
- "--trace_to_cloud" ,
460
- is_flag = True ,
461
- show_default = True ,
462
- default = False ,
463
- help = "Optional. Whether to enable cloud trace for telemetry." ,
464
- )
465
- @click .option (
466
- "--reload/--no-reload" ,
467
- default = True ,
468
- help = "Optional. Whether to enable auto reload for server." ,
469
- )
478
+ return decorator
479
+
480
+
481
+ @main .command ("web" )
482
+ @fast_api_common_options ()
470
483
@click .argument (
471
484
"agents_dir" ,
472
485
type = click .Path (
@@ -537,56 +550,6 @@ async def _lifespan(app: FastAPI):
537
550
538
551
539
552
@main .command ("api_server" )
540
- @click .option (
541
- "--session_db_url" ,
542
- help = (
543
- """Optional. The database URL to store the session.
544
-
545
- - Use 'agentengine://<agent_engine_resource_id>' to connect to Agent Engine sessions.
546
-
547
- - Use 'sqlite://<path_to_sqlite_file>' to connect to a SQLite DB.
548
-
549
- - See https://docs.sqlalchemy.org/en/20/core/engines.html#backend-specific-urls for more details on supported DB URLs."""
550
- ),
551
- )
552
- @click .option (
553
- "--host" ,
554
- type = str ,
555
- help = "Optional. The binding host of the server" ,
556
- default = "127.0.0.1" ,
557
- show_default = True ,
558
- )
559
- @click .option (
560
- "--port" ,
561
- type = int ,
562
- help = "Optional. The port of the server" ,
563
- default = 8000 ,
564
- )
565
- @click .option (
566
- "--allow_origins" ,
567
- help = "Optional. Any additional origins to allow for CORS." ,
568
- multiple = True ,
569
- )
570
- @click .option (
571
- "--log_level" ,
572
- type = click .Choice (
573
- ["DEBUG" , "INFO" , "WARNING" , "ERROR" , "CRITICAL" ], case_sensitive = False
574
- ),
575
- default = "INFO" ,
576
- help = "Optional. Set the logging level" ,
577
- )
578
- @click .option (
579
- "--trace_to_cloud" ,
580
- is_flag = True ,
581
- show_default = True ,
582
- default = False ,
583
- help = "Optional. Whether to enable cloud trace for telemetry." ,
584
- )
585
- @click .option (
586
- "--reload/--no-reload" ,
587
- default = True ,
588
- help = "Optional. Whether to enable auto reload for server." ,
589
- )
590
553
# The directory of agents, where each sub-directory is a single agent.
591
554
# By default, it is the current working directory
592
555
@click .argument (
@@ -596,6 +559,7 @@ async def _lifespan(app: FastAPI):
596
559
),
597
560
default = os .getcwd (),
598
561
)
562
+ @fast_api_common_options ()
599
563
def cli_api_server (
600
564
agents_dir : str ,
601
565
session_db_url : str = "" ,
0 commit comments