Bug
adk web . --reload_agents crashes on google-adk==2.0.0:
File ".../google/adk/cli/fast_api.py", line 582, in get_fast_api_app
def setup_observer(observer: Observer, adk_web_server: ApiServer):
UnboundLocalError: cannot access local variable 'ApiServer' where it is not associated with a value
Bare adk web . is fine (--reload_agents is opt-in).
Cause
fast_api.py imports ApiServer at the module top (line 42) and re-imports it inside get_fast_api_app at lines 529 and 533. The nested imports make ApiServer function-local. On the web=True happy path, DevServer imports successfully so neither nested import runs, leaving the local ApiServer unbound. The setup_observer annotation at line 582 then triggers the error (annotations are evaluated eagerly — no from __future__ import annotations in this file).
Fix
Delete the two redundant nested imports — the module-level import already provides ApiServer:
except ImportError:
logger.warning(...)
- from .api_server import ApiServer
-
ServerClass = ApiServer
else:
- from .api_server import ApiServer
-
ServerClass = ApiServer
Verified locally: patched file, adk web . --reload_agents starts cleanly.
Workaround
Omit --reload_agents. (adk web has no --no-reload_agents flag.)
Env
google-adk==2.0.0, Python 3.12, macOS.
Bug
adk web . --reload_agentscrashes ongoogle-adk==2.0.0:Bare
adk web .is fine (--reload_agentsis opt-in).Cause
fast_api.pyimportsApiServerat the module top (line 42) and re-imports it insideget_fast_api_appat lines 529 and 533. The nested imports makeApiServerfunction-local. On theweb=Truehappy path,DevServerimports successfully so neither nested import runs, leaving the localApiServerunbound. Thesetup_observerannotation at line 582 then triggers the error (annotations are evaluated eagerly — nofrom __future__ import annotationsin this file).Fix
Delete the two redundant nested imports — the module-level import already provides
ApiServer:except ImportError: logger.warning(...) - from .api_server import ApiServer - ServerClass = ApiServer else: - from .api_server import ApiServer - ServerClass = ApiServerVerified locally: patched file,
adk web . --reload_agentsstarts cleanly.Workaround
Omit
--reload_agents. (adk webhas no--no-reload_agentsflag.)Env
google-adk==2.0.0, Python 3.12, macOS.