Back to articles
Injecting Initial State into ADK Web UI with ASGI Middleware

Injecting Initial State into ADK Web UI with ASGI Middleware

via Dev.toKoichi

If you're using Google's ADK Web UI for agent development, you've probably run into this: every time you create a new session, you have to manually set up the state your agent needs. Here's a clean way to automate that with a preset file and ASGI middleware. The Problem ADK's Web UI is great for testing agents, but injecting initial state into a session is a bit of a hassle. The current options are: Add state via the 3-dot menu in the UI → You have to manually enter values every time you create a session Use before_agent_callback with a first-run check → Extra code to write and maintain Instead, I built a setup where you define initial state in a preset.yaml file, and a custom ASGI middleware automatically merges it into the session when you click "New Session" in the Web UI. How It Works When you click "New Session" in the Web UI, it internally calls POST /apps/{app_name}/users/{user_id}/sessions . The middleware intercepts this request, reads preset.yaml , and merges its initial_stat

Continue reading on Dev.to

Opens in a new tab

Read Full Article
6 views

Related Articles