google / google/adk-python

[Feature Request] Do not generate `__init__.py` for config-based agents

オープン
#6,753 コメント 3 件 リアクション 0 件 担当者 1 名 @sanketpatil06 が担当を希望しています GitHub で見る
agent config needs review
主要言語
Python
スター
21.5k
フォーク
4k
平均マージ
1日 14時間
マージ済み PR(30日)
37

説明

## 🔴 Required Information

### Is your feature request related to a specific problem?

Running `adk create --type=config` generates an empty `__init__.py` alongside `root_agent.yaml`.

However, config-based agents are loaded directly from `root_agent.yaml` and do not appear to require the agent directory to be a Python package.

https://github.com/google/adk-python/blob/25e8ea6dea82713fdac9bc4117ec425386582b1f/src/google/adk/cli/utils/agent_loader.py#L217

Existing config-based samples, such as `contributing/samples/mcp/tool_mcp_stdio_notion_config`, also work without an `__init__.py`.
https://github.com/google/adk-python/tree/v2.7.0/contributing/samples/mcp/tool_mcp_stdio_notion_config

The YAML agent loader tests similarly create fixtures containing only `root_agent.yaml` and load them successfully.
https://github.com/google/adk-python/blob/v2.7.0/tests/unittests/cli/utils/test_agent_loader.py#L514

This makes the generated `__init__.py` appear unnecessary and creates an inconsistency between newly generated agents and existing samples.

### Describe the Solution You'd Like

When creating a config-based agent with `adk create --type=config `, ADK should generate:

- `.env`
- `.gitignore`
- `root_agent.yaml`

It should not generate an empty `__init__.py` unless the file is required for a documented compatibility reason.

The success message and corresponding CLI tests should be updated accordingly.

### Impact on your work

This would make generated config-based projects simpler and consistent with the repository's existing config samples.

It would also clarify whether a YAML-configured agent directory is expected to be a Python package.

### Willingness to contribute

Yes.

---

## 🟡 Recommended Information

### Describe Alternatives You've Considered

The empty `__init__.py` can be deleted manually after running `adk create`.

It can also be left in place because it does not prevent the YAML configuration from loading.
However, keeping an apparently unused generated file makes it unclear whether it is part of the required config-agent structure.

### Proposed API / Implementation

In `src/google/adk/cli/cli_create.py`:

- Do not create `__init__.py` when `type == "config"`.
- Remove `__init__.py` from `_SUCCESS_MSG_CONFIG`.
- Update `test_run_cmd_with_type_config` to assert that `__init__.py` is not generated.

Before making this change, it may be worth confirming whether the empty file intentionally prevents a collision with a Python package of the same name elsewhere on `sys.path`, such as one installed under `site-packages`.

The loader attempts to import the agent name as a Python module or package before falling back to `root_agent.yaml`.
Without `__init__.py`, the local directory may be treated as a namespace-package candidate, while a regular package with the same name elsewhere on `sys.path` may be imported instead.

This does not make `__init__.py` necessary for loading the YAML file itself, but it may provide defensive package-resolution behavior.

### Additional Context

The current loader checks Python module and package forms first, then loads `/root_agent.yaml`. Therefore, the YAML-loading path itself does not directly use `__init__.py`.

コントリビューションガイド

コントリビューションガイドを開く

評価

この issue はまだ評価されていません。

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。