From 9d4f9b66d26eea9a23a9be61aa6e8ff72053fbaa Mon Sep 17 00:00:00 2001 From: RUI-LONG Date: Fri, 3 Jul 2026 17:30:43 +0800 Subject: [PATCH] fix(cli): resolve UnboundLocalError for `json` when serving A2A agents `get_fast_api_app` imports `json` at module level, but also re-imports it locally inside the `gemini_enterprise_app_name` branch. Because Python treats any name assigned (including via `import`) anywhere in a function as local to the entire function, the module-level `json` is shadowed throughout `get_fast_api_app`. When A2A is enabled (`adk api_server --a2a`), the A2A setup block runs `json.load(f)` to read each agent's `agent.json` *before* the local `import json` executes, raising: cannot access local variable 'json' where it is not associated with a value so every A2A agent fails to register (logged as "Failed to setup A2A agent ..."). The local `import json` is redundant with the module-level import, so this removes it. `json.load`/`json.dumps` now resolve to the module-level `json` as intended. Co-Authored-By: Claude Opus 4.8 --- src/google/adk/cli/fast_api.py | 1 - 1 file changed, 1 deletion(-) diff --git a/src/google/adk/cli/fast_api.py b/src/google/adk/cli/fast_api.py index a6e7d9f62c..2bab01a202 100644 --- a/src/google/adk/cli/fast_api.py +++ b/src/google/adk/cli/fast_api.py @@ -756,7 +756,6 @@ async def _get_a2a_runner_async() -> Runner: ) import inspect - import json from google.adk.agents import Agent import google.auth