Skip to content

Commit 9e3723b

Browse files
Doris26copybara-github
authored andcommitted
fix: Refactor web server components and agent loaders from maven_plugin to dev module
This CL refactors the ADKWebServer logic in /dev and custom agent loading logic in /maven_plugin. PiperOrigin-RevId: 800192998
1 parent 0f7904b commit 9e3723b

File tree

8 files changed

+46
-2126
lines changed

8 files changed

+46
-2126
lines changed

maven_plugin/README.md

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# Google ADK Maven Plugin
22

3+
[![Maven Central](https://img.shields.io/maven-central/v/com.google.adk/google-adk-maven-plugin)](https://search.maven.org/artifact/com.google.adk/google-adk-maven-plugin)
4+
35
This Maven plugin provides a convenient way to start the ADK Web Server with your custom agents for development and testing.
46

57
## Usage
@@ -31,14 +33,14 @@ mvn google-adk:web \
3133

3234
### 1. Implement the AgentLoader Interface
3335

34-
Create a class that implements `com.google.adk.maven.AgentLoader`:
36+
Create a class that implements `com.google.adk.web.AgentLoader`:
3537

3638
```java
3739
package com.example;
3840

3941
import com.google.adk.agents.BaseAgent;
4042
import com.google.adk.agents.LlmAgent;
41-
import com.google.adk.maven.AgentLoader;
43+
import com.google.adk.web.AgentLoader;
4244
import com.google.common.collect.ImmutableList;
4345
import java.util.NoSuchElementException;
4446

@@ -84,17 +86,19 @@ public class MyAgentLoader implements AgentLoader {
8486

8587
Add the plugin to your `pom.xml`:
8688

89+
<!-- {x-version-start:google-adk:released} -->
8790
```xml
8891
<build>
8992
<plugins>
9093
<plugin>
9194
<groupId>com.google.adk</groupId>
9295
<artifactId>google-adk-maven-plugin</artifactId>
93-
<version>0.2.1-SNAPSHOT</version>
96+
<version>0.2.0</version>
9497
</plugin>
9598
</plugins>
9699
</build>
97100
```
101+
<!-- {x-version-end} -->
98102

99103
### 3. Run the Web Server
100104

@@ -266,41 +270,45 @@ The web UI provides:
266270
267271
Make sure your project has the necessary ADK dependencies:
268272
273+
<!-- {x-version-start:google-adk:released} -->
269274
```xml
270275
<dependencies>
271276
<dependency>
272277
<groupId>com.google.adk</groupId>
273278
<artifactId>google-adk</artifactId>
274-
<version>0.2.1-SNAPSHOT</version>
279+
<version>0.2.0</version>
275280
</dependency>
276281

277-
<!-- Maven plugin dependency for AgentLoader interface -->
282+
<!-- Dev module dependency for AgentLoader interface -->
278283
<dependency>
279284
<groupId>com.google.adk</groupId>
280-
<artifactId>google-adk-maven-plugin</artifactId>
281-
<version>0.2.1-SNAPSHOT</version>
285+
<artifactId>google-adk-dev</artifactId>
286+
<version>0.2.0</version>
282287
<scope>compile</scope>
283288
</dependency>
284289
</dependencies>
285290
```
291+
<!-- {x-version-end} -->
286292

287293
### Plugin Usage Options
288294

289295
**Option 1: With plugin declaration (shorter commands)**
290296

291297
Add the plugin to your `pom.xml` for convenience:
292298

299+
<!-- {x-version-start:google-adk:released} -->
293300
```xml
294301
<build>
295302
<plugins>
296303
<plugin>
297304
<groupId>com.google.adk</groupId>
298305
<artifactId>google-adk-maven-plugin</artifactId>
299-
<version>0.2.1-SNAPSHOT</version>
306+
<version>0.2.0</version>
300307
</plugin>
301308
</plugins>
302309
</build>
303310
```
311+
<!-- {x-version-end} -->
304312

305313
Then use the short command:
306314

@@ -318,4 +326,8 @@ mvn com.google.adk:google-adk-maven-plugin:web -Dagents=com.example.MyAgentLoade
318326

319327
## Stopping the Server
320328

321-
Press `Ctrl+C` in the terminal to stop the server.
329+
Press `Ctrl+C` in the terminal to stop the server.
330+
331+
## Version Notes
332+
333+
Replace version numbers with the latest version available on [Maven Central](https://search.maven.org/artifact/com.google.adk/google-adk-maven-plugin).

maven_plugin/examples/simple-agent/pom.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,13 @@
2626
<version>${google-adk.version}</version>
2727
</dependency>
2828

29+
<!-- Dev dependency for AgentLoader interface -->
30+
<dependency>
31+
<groupId>com.google.adk</groupId>
32+
<artifactId>google-adk-dev</artifactId>
33+
<version>${google-adk.version}</version>
34+
</dependency>
35+
2936
<!-- Maven plugin dependency for AgentProvider interface -->
3037
<dependency>
3138
<groupId>com.google.adk</groupId>

maven_plugin/examples/simple-agent/src/main/java/com/example/SimpleAgentLoader.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818

1919
import com.google.adk.agents.BaseAgent;
2020
import com.google.adk.agents.LlmAgent;
21-
import com.google.adk.maven.AgentLoader;
2221
import com.google.adk.tools.GoogleSearchTool;
22+
import com.google.adk.web.AgentLoader;
2323
import com.google.common.base.Suppliers;
2424
import com.google.common.collect.ImmutableList;
2525
import com.google.common.collect.ImmutableMap;

maven_plugin/pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,12 @@
5454
<version>${project.version}</version>
5555
</dependency>
5656

57+
<dependency>
58+
<groupId>com.google.adk</groupId>
59+
<artifactId>google-adk-dev</artifactId>
60+
<version>${project.version}</version>
61+
</dependency>
62+
5763
<!-- Spring Boot Dependencies -->
5864
<dependency>
5965
<groupId>org.springframework.boot</groupId>

maven_plugin/src/main/java/com/google/adk/maven/ConfigAgentLoader.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
import com.google.adk.agents.BaseAgent;
2222
import com.google.adk.agents.ConfigAgentUtils;
23+
import com.google.adk.web.AgentLoader;
2324
import com.google.common.base.Suppliers;
2425
import com.google.common.collect.ImmutableList;
2526
import java.io.IOException;

maven_plugin/src/main/java/com/google/adk/maven/WebMojo.java

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616

1717
package com.google.adk.maven;
1818

19-
import com.google.adk.maven.web.AdkWebServer;
2019
import com.google.adk.utils.ComponentRegistry;
20+
import com.google.adk.web.AdkWebServer;
2121
import java.io.IOException;
2222
import java.lang.reflect.Field;
2323
import java.net.MalformedURLException;
@@ -206,7 +206,7 @@ public void execute() throws MojoExecutionException, MojoFailureException {
206206

207207
// Load and instantiate the AgentLoader
208208
getLog().info("Loading agent loader: " + agents);
209-
AgentLoader provider = loadAgentProvider();
209+
com.google.adk.web.AgentLoader provider = loadAgentProvider();
210210

211211
// Set up system properties for Spring Boot
212212
setupSystemProperties();
@@ -268,14 +268,16 @@ private void logConfiguration() {
268268
getLog().info(" Agent Provider: " + agents);
269269
getLog().info(" Server Host: " + host);
270270
getLog().info(" Server Port: " + port);
271-
getLog().info(" Hot Reloading: " + hotReloading);
272271
getLog().info(" Registry: " + (registry != null ? registry : "default"));
273272
}
274273

275274
private void setupSystemProperties() {
276275
System.setProperty("server.address", host);
277276
System.setProperty("server.port", String.valueOf(port));
278-
System.setProperty("adk.agent.hotReloadingEnabled", String.valueOf(hotReloading));
277+
278+
// Use custom loader instead of compiled loader
279+
System.setProperty("adk.agents.loader", "custom");
280+
getLog().debug("Set adk.agents.loader=custom");
279281
}
280282

281283
/**
@@ -400,7 +402,7 @@ private <T> T tryLoadFromConstructor(String className, Class<T> expectedType)
400402
}
401403
}
402404

403-
private AgentLoader loadAgentProvider() throws MojoExecutionException {
405+
private com.google.adk.web.AgentLoader loadAgentProvider() throws MojoExecutionException {
404406
// First, check if agents parameter is a directory path
405407
Path agentsPath = Paths.get(agents);
406408
if (Files.isDirectory(agentsPath)) {
@@ -410,14 +412,15 @@ private AgentLoader loadAgentProvider() throws MojoExecutionException {
410412

411413
// Next, try to interpret as class.field syntax
412414
if (agents.contains(".")) {
413-
AgentLoader provider = tryLoadFromStaticField(agents, AgentLoader.class);
415+
com.google.adk.web.AgentLoader provider =
416+
tryLoadFromStaticField(agents, com.google.adk.web.AgentLoader.class);
414417
if (provider != null) {
415418
return provider;
416419
}
417420
}
418421

419422
// Fallback to trying the entire string as a class name
420-
return tryLoadFromConstructor(agents, AgentLoader.class);
423+
return tryLoadFromConstructor(agents, com.google.adk.web.AgentLoader.class);
421424
}
422425

423426
/** Cleans up all resources including application context, classloader. */
@@ -455,7 +458,6 @@ private void clearSystemProperties() {
455458
try {
456459
System.clearProperty("server.address");
457460
System.clearProperty("server.port");
458-
System.clearProperty("adk.agent.hotReloadingEnabled");
459461
System.clearProperty("adk.agents.source-dir");
460462
System.clearProperty("spring.autoconfigure.exclude");
461463
getLog().debug("System properties cleared");

0 commit comments

Comments
 (0)