Skip to content

feat(cli): seed adk web sessions from initial_state.json - #7465

Open
BichengWang wants to merge 2 commits into
google:mainfrom
BichengWang:feat/dev-server-initial-session-state
Open

BichengWang wants to merge 2 commits into
google:mainfrom
BichengWang:feat/dev-server-initial-session-state

Conversation

@BichengWang

Copy link
Copy Markdown
Contributor

Closes #4961

Problem

adk run --replay can preload session state from a JSON file, but adk web has no equivalent. Anyone iterating on an agent that depends on session state has to re-enter the same values in the UI for every new session.

Change

If <agents_dir>/<app_name>/initial_state.json exists, adk web merges it into the state of each session created through the session endpoints.

  • State sent by the client wins, key by key: {**file_state, **client_state}.
  • The file is read on each session creation, so edits apply without restarting the server.
  • A missing file changes nothing. An unreadable, malformed or non-object file is ignored with a warning.
  • The change lives in DevServer._create_session. ApiServer (adk api_server) is untouched.
  • The path goes through the existing _get_agent_dir validation.

Not covered: sessions the runner creates itself under --auto_create_session are not seeded, since they never go through _create_session. app: and user: keys in the file follow the normal state scoping, so they write to shared state.

Testing plan

Unit tests in tests/unittests/cli/test_fast_api.py:

  • the file seeds a new session
  • client state overrides file values, and other file keys are kept
  • no file: behavior unchanged
  • invalid JSON, a list and a string are ignored
  • ApiServer ignores the file

The two seeding tests fail without the change. pytest tests/unittests/cli/test_fast_api.py gives 231 passed, 5 skipped, 1 xfailed. pyink and isort are clean.

When an agent directory contains initial_state.json, the dev server merges
it into the state of each session created through the session endpoints.
State sent by the client takes precedence. The file is read per request, and
a missing or malformed file leaves behavior unchanged. ApiServer is not
affected.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature Request: Declarative initial session state for adk web

2 participants