Skip to content

Commit 95b8e50

Browse files
committed
feat: AgentStaticLoader; like an đź§ť Elve, instead of the đź§™ mage (fixes #149)
1 parent 806e985 commit 95b8e50

File tree

3 files changed

+53
-1
lines changed

3 files changed

+53
-1
lines changed

‎dev/src/main/java/com/google/adk/web/AdkWebServer.java‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,8 @@
125125
@ComponentScan(basePackages = {"com.google.adk.web", "com.google.adk.web.config"})
126126
public class AdkWebServer implements WebMvcConfigurer {
127127

128+
public static AgentLoader AGENT_LOADER;
129+
128130
private static final Logger log = LoggerFactory.getLogger(AdkWebServer.class);
129131

130132
@Value("${adk.web.ui.dir:#{null}}")
@@ -175,6 +177,11 @@ public Map<String, BaseAgent> loadedAgentRegistry(
175177
}
176178

177179
try {
180+
// If AGENT_LOADER is set, us it
181+
if (AGENT_LOADER != null) {
182+
agents.putAll(AGENT_LOADER.loadAgents());
183+
}
184+
178185
// Create and use compiler loader
179186
AgentCompilerLoader compilerLoader = new AgentCompilerLoader(props);
180187
Map<String, BaseAgent> compiledAgents = compilerLoader.loadAgents();

‎dev/src/main/java/com/google/adk/web/AgentLoader.java‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@
2727
*/
2828
public interface AgentLoader {
2929

30+
static AgentLoader from(BaseAgent... agents) {
31+
return new AgentStaticLoader(agents);
32+
}
33+
3034
/**
3135
* Loads agents and returns them as a map. This method performs a one-time loading operation and
3236
* returns all discovered agents.
@@ -69,5 +73,7 @@ default boolean supportsHotReloading() {
6973
*
7074
* @return A string description of the loader type
7175
*/
72-
String getLoaderType();
76+
default String getLoaderType() {
77+
return getClass().getSimpleName();
78+
}
7379
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* Copyright 2025 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package com.google.adk.web;
17+
18+
import autovalue.shaded.com.google.common.collect.ImmutableMap;
19+
import com.google.adk.agents.BaseAgent;
20+
import java.io.IOException;
21+
import java.util.Map;
22+
23+
class AgentStaticLoader implements AgentLoader {
24+
25+
private final ImmutableMap<String, BaseAgent> agents;
26+
27+
AgentStaticLoader(BaseAgent... agents) {
28+
var builder = ImmutableMap.<String, BaseAgent>builder();
29+
for (BaseAgent agent : agents) {
30+
builder.put(agent.name(), agent);
31+
}
32+
this.agents = builder.build();
33+
}
34+
35+
@Override
36+
public Map<String, BaseAgent> loadAgents() throws IOException {
37+
return agents;
38+
}
39+
}

0 commit comments

Comments
 (0)