Skip to content

feat: add AdkConfiguration abstraction layer for programmatic config injection#1193

Open
YuqiGuo105 wants to merge 1 commit into
google:mainfrom
YuqiGuo105:feature/adk-configuration-abstraction-layer
Open

feat: add AdkConfiguration abstraction layer for programmatic config injection#1193
YuqiGuo105 wants to merge 1 commit into
google:mainfrom
YuqiGuo105:feature/adk-configuration-abstraction-layer

Conversation

@YuqiGuo105
Copy link
Copy Markdown
Contributor

Summary

Resolves #1022 — replaces all hardcoded System.getenv() calls in the SDK's critical configuration paths with a new AdkConfiguration abstraction 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 (from application.yaml, Secret Manager, etc.) into the ADK SDK without resorting to unsafe JVM reflection hacks or external CI/CD wrappers.

Solution

New file: AdkConfiguration.java

A fully static, thread-safe configuration provider with the following fallback chain (highest priority first):

  1. Programmatic overrides — set via AdkConfiguration.set(key, value) at runtime
  2. JVM system properties-DGOOGLE_API_KEY=xxx or Spring's application.properties bridge
  3. OS environment variablesSystem.getenv(), unchanged behavior for existing users

Public API:

AdkConfiguration.set("GOOGLE_API_KEY", value);       // inject programmatically
AdkConfiguration.get("GOOGLE_API_KEY");               // Optional<String>
AdkConfiguration.getOrDefault("GOOGLE_GENAI_USE_VERTEXAI", "false");
AdkConfiguration.clear("GOOGLE_API_KEY");             // remove single override
AdkConfiguration.clearAll();                          // reset (for tests)

Modified files

File Change
sessions/ApiClient.java 3 × getenvAdkConfiguration.get() (GOOGLE_API_KEY, GOOGLE_CLOUD_PROJECT, GOOGLE_CLOUD_LOCATION)
tools/retrieval/VertexAiRagRetrieval.java 1 × getenvAdkConfiguration.getOrDefault() (GOOGLE_GENAI_USE_VERTEXAI)
models/ApigeeLlm.java 2 × getenvAdkConfiguration.get() (APIGEE_PROXY_URL, isEnvEnabled helper — preserves "1" semantics)

New test file: AdkConfigurationTest.java

8 unit tests covering: fallback priority ordering, clear/clearAll behaviour, null key/value safety, and getOrDefault with 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

@Component
public class AdkInitializer {
    @Value("${google.api-key}") private String apiKey;
    @Value("${google.cloud.project}") private String project;

    @PostConstruct
    void init() {
        AdkConfiguration.set("GOOGLE_API_KEY", apiKey);
        AdkConfiguration.set("GOOGLE_CLOUD_PROJECT", project);
    }
}

Test Results

  • AdkConfigurationTest: 8/8 pass
  • Full core module: 1255 tests run, 0 failures attributable to this change (pre-existing LocalSkillSourceTest Windows path separator failure is unrelated)

Fixes #1022

@google-cla
Copy link
Copy Markdown

google-cla Bot commented May 12, 2026

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
@YuqiGuo105 YuqiGuo105 force-pushed the feature/adk-configuration-abstraction-layer branch from 832a92e to 2a81339 Compare May 12, 2026 04:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Hardcoded System.getenv() calls prevent programmatic configuration of parameters

1 participant