From 85ccacbf2d2849fe668fe3c259db4ace72cd654d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=AD=8F=E8=B6=85?= Date: Thu, 8 May 2025 10:12:21 -0700 Subject: [PATCH] fix(cli): Add auto-reload flag Copybara import of the project: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit -- a4a998d5418af47a4f263823810e8ab85a9ae4d6 by 魏超 : fix(cli): Disable auto-reload feature on Windows system Fixed the issue caused by the auto-reload feature when running the CLI tool on Windows system. By detecting the operating system type, the auto-reload is disabled on Windows system to avoid potential errors: When mcp is asynchronously loaded, it will enter the _make_subprocess_transport NotImplementedError logic due to uvicorn reload=True in fastapi. -- 46c9bb600e4530d3f9c22369c4a99774efa024c9 by 魏超 : add an option in the CLI to enable or disable the reload feature. So users(esp. windows) can disable this if they come across the '_make_subprocess_transport NotImplementedError' bug on windows. COPYBARA_INTEGRATE_REVIEW=https://github.com/google/adk-python/pull/415 from nneverwei:win-subprocess-NotImplError-with-mcp fbb9ab03350bb0a98769cf1a4cf930983ba9fa78 PiperOrigin-RevId: 756360981 --- src/google/adk/cli/cli_tools_click.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/google/adk/cli/cli_tools_click.py b/src/google/adk/cli/cli_tools_click.py index ee59b5f..540f532 100644 --- a/src/google/adk/cli/cli_tools_click.py +++ b/src/google/adk/cli/cli_tools_click.py @@ -352,6 +352,11 @@ def cli_eval( default=False, help="Optional. Whether to enable cloud trace for telemetry.", ) +@click.option( + "--reload/--no-reload", + default=True, + help="Optional. Whether to enable auto reload for server.", +) @click.argument( "agents_dir", type=click.Path( @@ -367,6 +372,7 @@ def cli_web( allow_origins: Optional[list[str]] = None, port: int = 8000, trace_to_cloud: bool = False, + reload: bool = True, ): """Starts a FastAPI server with Web UI for agents. @@ -418,7 +424,7 @@ def cli_web( app, host="0.0.0.0", port=port, - reload=True, + reload=reload, ) server = uvicorn.Server(config) @@ -474,6 +480,11 @@ def cli_web( default=False, help="Optional. Whether to enable cloud trace for telemetry.", ) +@click.option( + "--reload/--no-reload", + default=True, + help="Optional. Whether to enable auto reload for server.", +) # The directory of agents, where each sub-directory is a single agent. # By default, it is the current working directory @click.argument( @@ -491,6 +502,7 @@ def cli_api_server( allow_origins: Optional[list[str]] = None, port: int = 8000, trace_to_cloud: bool = False, + reload: bool = True, ): """Starts a FastAPI server for agents. @@ -518,7 +530,7 @@ def cli_api_server( ), host="0.0.0.0", port=port, - reload=True, + reload=reload, ) server = uvicorn.Server(config) server.run()