feat: add AdkConfiguration abstraction layer for programmatic config injection#1193
Open
YuqiGuo105 wants to merge 1 commit into
Open
feat: add AdkConfiguration abstraction layer for programmatic config injection#1193YuqiGuo105 wants to merge 1 commit into
YuqiGuo105 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. |
…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
832a92e to
2a81339
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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