Skip to content

feat(cli): add --lifespan option to api_server command#5938

Open
kemurayama wants to merge 1 commit into
google:v2from
kemurayama:feat/api-server-lifespan
Open

feat(cli): add --lifespan option to api_server command#5938
kemurayama wants to merge 1 commit into
google:v2from
kemurayama:feat/api-server-lifespan

Conversation

@kemurayama
Copy link
Copy Markdown

Please ensure you have read the contribution guide before creating a pull request.

Link to Issue or Description of Change

1. Link to an existing issue (if applicable):

(Note: If there is no specific issue, please leave the above blank or remove them, and fill in section 2 below.)

2. Or, if no issue exists, describe the change:

Problem:
Currently, there is no way to register a lifespan handler (startup and shutdown logic) directly from the adk api_server CLI command in v1 and v2. While the underlying get_fast_api_app function accepts a lifespan argument, the CLI command does not expose it, preventing users from running custom setup or teardown logic for their agents.

Solution:
This PR introduces a --lifespan option to the adk api_server CLI command. This allows users to specify a lifespan context manager dynamically via its import path (e.g., path.to.module.lifespan_handler).

  • Added --lifespan option to the api_server command definition.
  • Implemented _load_lifespan_handler helper to dynamically import the lifespan handler using its string module path.
  • Updated cli_api_server to dynamically load the lifespan handler and pass it down to get_fast_api_app.

Testing Plan

Unit Tests:

  • I have added or updated unit tests for my change.
  • All unit tests pass locally.

Summary of passed pytest results:
Added test_cli_api_server_passes_lifespan in tests/unittests/cli/utils/test_cli_tools_click.py to verify that the CLI correctly parses --lifespan, loads the module, and passes the handler to get_fast_api_app.

Command:

pytest tests/unittests/cli/utils/test_cli_tools_click.py -k test_cli_api_server_passes_lifespan

@adk-bot adk-bot added the core [Component] This issue is related to the core interface and implementation label Jun 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core [Component] This issue is related to the core interface and implementation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants