feat: add AdkConfiguration abstraction layer for programmatic config injection#1193
feat: add AdkConfiguration abstraction layer for programmatic config injection#1193YuqiGuo105 wants to merge 1 commit into
Conversation
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
832a92e to
2a81339
Compare
|
Hi @YuqiGuo105, thank you for your contribution! We appreciate you taking the time to submit this pull request. I noticed that there are merge conflicts. Could you please take a look and address those conflicts? |
…injection Replace hardcoded System.getenv() calls with a three-tier fallback chain: 1. Programmatic overrides via AdkConfiguration.set() (highest priority) 2. JVM system properties via System.getProperty() 3. OS environment variables via System.getenv() (backward compatible) Files changed: - core/.../config/AdkConfiguration.java (new): central config provider with ConcurrentHashMap-backed programmatic overrides, set/get/clear/ clearAll API, and Optional-returning get() with full fallback chain. - core/.../sessions/ApiClient.java: replace 3x getenv with AdkConfiguration (GOOGLE_API_KEY, GOOGLE_CLOUD_PROJECT, GOOGLE_CLOUD_LOCATION) - core/.../tools/retrieval/VertexAiRagRetrieval.java: replace getenv with AdkConfiguration (GOOGLE_GENAI_USE_VERTEXAI) - core/.../models/ApigeeLlm.java: replace 2x getenv with AdkConfiguration (APIGEE_PROXY_URL, isEnvEnabled helper) - core/.../config/AdkConfigurationTest.java (new): 8 unit tests covering fallback priority, clear/clearAll, null safety, and defaults. Fixes google#1022
2a81339 to
9acd093
Compare
Hi @hemasekhar-p , rebased and resolved the conflicts :) |
Summary
Resolves #1022 — replaces all hardcoded
System.getenv()calls in the SDK's critical configuration paths with a newAdkConfigurationabstraction layer that supports a three-tier fallback chain.Problem
System.getenv()returns an immutable OS-level snapshot that cannot be modified at runtime. This blocks Spring Boot and other modern Java frameworks from injecting configuration values (fromapplication.yaml, Secret Manager, etc.) into the ADK SDK without resorting to unsafe JVM reflection hacks or external CI/CD wrappers.Solution
New file:
AdkConfiguration.javaA fully static, thread-safe configuration provider with the following fallback chain (highest priority first):
AdkConfiguration.set(key, value)at runtime-DGOOGLE_API_KEY=xxxor Spring'sapplication.propertiesbridgeSystem.getenv(), unchanged behavior for existing usersPublic API:
Modified files
sessions/ApiClient.javagetenv→AdkConfiguration.get()(GOOGLE_API_KEY,GOOGLE_CLOUD_PROJECT,GOOGLE_CLOUD_LOCATION)tools/retrieval/VertexAiRagRetrieval.javagetenv→AdkConfiguration.getOrDefault()(GOOGLE_GENAI_USE_VERTEXAI)models/ApigeeLlm.javagetenv→AdkConfiguration.get()(APIGEE_PROXY_URL,isEnvEnabledhelper — preserves"1"semantics)New test file:
AdkConfigurationTest.java8 unit tests covering: fallback priority ordering,
clear/clearAllbehaviour,nullkey/value safety, andgetOrDefaultwith and without resolved values.Backward Compatibility
Fully backward compatible. Users who rely on environment variables see no behaviour change —
System.getenv()remains the lowest-priority fallback.Spring Boot Integration Example
Test Results
AdkConfigurationTest: 8/8 passcoremodule: 1255 tests run, 0 failures attributable to this change (pre-existingLocalSkillSourceTestWindows path separator failure is unrelated)Fixes #1022