google / google/adk-python

Feature Request: Runtime Configurations with Env Vars

Đang mở
#3,854 3 bình luận 0 reaction 1 người được giao Được @klateefa nhận Xem trên GitHub
core needs review
Ngôn ngữ chính
Python
Star
21.5k
Fork
4k
Merge trung bình
1 ngày 14 giờ
Pull request đã merge (30 ngày)
37

Mô tả

**Problem**

Developers configure applications at runtime in a variety of ways. Using command-line arguments is a common way; but in some contexts, altering command-line entrypoints to programs can be difficult or impossible. For such scenarios where we cannot alter a program entrypoint, we often use environmental variables to alter program behavior. Often in deployment environments, env-vars can be changed without releases. This flexibility in configuration allows developers to use frameworks in a wider array of contexts, and can generally ease their adoption into existing deployment systems.

ADK provides powerful configuration options through command-line arguments, but so far as I can tell is limited in which values can be set via environmental variables. I'm proposing the solution that modern server frameworks such as `uvicorn` provide, where configurations can be made both by command-line and by environmental variables. This will provide greater flexibility in runtime possibilities to users.

**Solution**

The solution should be relatively simple. For command-line arguments such as `--session_service_uri` or `--artifact_service_uri`, or other options, users should be able to set an environmental variable such as `ADK_SESSION_SERVICE_URI` or `ADK_ARTIFACT_SERVICE_URI`.

This solution should be relatively simple to implement in the ADK python library. [Uvicorn implements this](https://github.com/Kludex/uvicorn/blob/8ae0bcbecb0a655789abf0c2dd4200848fc68a30/uvicorn/main.py#L61) through a context_setting map variable in the command implementation:

```python
@click.command(context_settings={"auto_envvar_prefix": "UVICORN"})
```

This allows users to set variables such as port or host by adding variables with the prefix "UVICORN" to their environment (`UVICORN_PORT=...`). ADK could take a similar strategy using the prefix "ADK".

```python
@click.group(context_settings={"max_content_width": 240, "auto_envvar_prefix": "ADK"})
@click.version_option(version.__version__)
def main():
"""Agent Development Kit CLI tools."""
pass
```

**Additional context**

1) **Solution Scope**. This solution is relatively targeted toward configurations on the `adk web` and `adk api_server` entrypoints. The solution provided will not resolve other configuration issues, such as how the Uvicorn server picks up configurations. It would be good to extend the solution to cover these extended cases.

2) **Potential side-effects**. In layered frameworks such as ADK, there can sometimes be conflicting variables that are taken in at different parts of the program. Thus targeting a change in configuration to one part of the app can have an unintended effect on another part of the application. This should not be an issue, as the prefix of the variables should not cause a collision with other frameworks the user may also have in play.

If this solution is good, I'm more than happy to implement a PR here and build some testing for it. Thanks!

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.