feat(cli): add --lifespan option to api_server command#5938
Open
kemurayama wants to merge 1 commit into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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_serverCLI command in v1 and v2. While the underlyingget_fast_api_appfunction accepts alifespanargument, the CLI command does not expose it, preventing users from running custom setup or teardown logic for their agents.Solution:
This PR introduces a
--lifespanoption to theadk api_serverCLI command. This allows users to specify a lifespan context manager dynamically via its import path (e.g.,path.to.module.lifespan_handler).--lifespanoption to theapi_servercommand definition._load_lifespan_handlerhelper to dynamically import the lifespan handler using its string module path.cli_api_serverto dynamically load the lifespan handler and pass it down toget_fast_api_app.Testing Plan
Unit Tests:
Summary of passed
pytestresults:Added
test_cli_api_server_passes_lifespanintests/unittests/cli/utils/test_cli_tools_click.pyto verify that the CLI correctly parses--lifespan, loads the module, and passes the handler toget_fast_api_app.Command: