[Feature] Add --state_file to adk run for loading initial session state from JSON
@sanketpatil06 がすでに取り組んでいます。
2026年9月11日 から。
評価
この issue はまだ評価されていません。
説明
🔴 Required Information
Is your feature request related to a specific problem?
adk run currently supports initial session state through --state, but the state must be passed as an inline JSON string:
adk run path/to/agent --state '{"customer_id": "123", "region": "us"}'
For realistic state payloads this becomes hard to use:
- Shell quoting differs across bash, zsh, PowerShell, and cmd.
- Larger state payloads are difficult to read, edit, and reuse.
- Sensitive or environment-specific values can end up in shell history.
- Generated state fixtures cannot be reused directly without wrapping them into a command-line string.
This is especially painful when testing agents that depend on session state, dynamic instructions, or state-backed tools.
I searched for existing issues/PRs targeting this specific CLI feature and did not find one for --state_file / --state-file. Related but distinct: #4961 proposes declarative initial state for adk web; this request is specifically for the adk run CLI path.
Describe the Solution You'd Like
Add a --state_file option to adk run that loads initial session state from a JSON file:
adk run path/to/agent --state_file state.json
adk run path/to/agent "hello" --state_file state.json
The file should contain a JSON object used as the initial session state.
Expected behavior:
--state_fileworks in both interactive mode and single-query mode.--stateand--state_fileare mutually exclusive.- Invalid JSON should surface the same style of error as invalid
--stateJSON. - Missing/unreadable files should be reported by Click as a normal CLI input error.
Impact on your work
This would make local agent development and repeatable testing much smoother for stateful agents. Instead of copying JSON into a shell command, developers could keep reusable fixtures like:
state.customer-a.json
state.debug.json
state.empty-cart.json
and run the same agent against each state file.
It also reduces quoting friction on Windows/PowerShell, where inline JSON can be particularly awkward.
Willingness to contribute
Yes. I can open a small PR if this direction looks reasonable.
🟡 Recommended Information
Describe Alternatives You've Considered
- Use
--statewith inline JSON. This works for tiny examples but becomes brittle for realistic payloads and varies by shell. - Use
--replay. This creates a session from an input file with queries, but it is a different workflow and not ideal when I only want to seed state and continue interactively or run a single query. - Add initialization logic in callbacks. This works, but puts local testing/setup state into agent code.
Proposed API / Implementation
The CLI already forwards --state as state_str into run_cli / run_once_cli, where the JSON parsing path already exists.
A minimal implementation could:
- Add a Click option on
adk run:
@click.option(
"--state_file",
type=click.Path(exists=True, dir_okay=False, file_okay=True, resolve_path=True),
help="Optional. Path to a JSON file containing initial state for the run.",
)
- Enforce that
--stateand--state_filecannot be used together. - Read the file as UTF-8 in
cli_runand pass the contents asstate_strto the existingrun_cli/run_once_clicalls. - Add unit tests under
tests/unittests/cli/utils/test_cli_tools_click.pycovering interactive mode, single-query mode, mutual exclusion, and bad/missing file behavior.
Additional Context
This is intentionally smaller than a broader declarative state feature. It only makes the existing adk run --state capability easier and safer to use with real JSON files.
- 主要言語
- Python
- スター
- 21.6k
- フォーク
- 4k
- 平均マージ
- 7時間 10分
- マージ済み PR(30日)
- 7
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
google/adk-python のほかの issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
google/adk-python#7266 · コメント 1 件 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
google/adk-python#7265 · コメント 1 件 ·
-
mcp
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
google/adk-python#7217 · コメント 3 件 · 担当者 1 名 ·
-
tools
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
google/adk-python#7206 · コメント 1 件 · 担当者 1 名 ·
-
request clarification tools
難易度 2/5 1〜3時間 初心者へのやさしさ 86/100
google/adk-python#7205 · コメント 2 件 · 担当者 1 名 ·
google/adk-python の issue をすべて見る
似ている issue
-
agent-ready documentation needs-triage
難易度 1/5 1〜3時間 初心者へのやさしさ 88/100
-
documentation
難易度 1/5 1時間未満 初心者へのやさしさ 91/100
-
workflow-status page template still says reusable workflows are "triggered only by workflow_call:" オープン
難易度 1/5 1時間未満 初心者へのやさしさ 92/100
-
instance instance add
難易度 1/5 1時間未満 初心者へのやさしさ 72/100
searxng/searx-instances#939 · コメント 1 件 ·
-
area-deployment area-integrations triage:bot-seen
難易度 2/5 半日 初心者へのやさしさ 86/100