|
| 1 | +# Google ADK Maven Plugin |
| 2 | + |
| 3 | +This Maven plugin provides a convenient way to start the ADK Web Server with your custom agents for development and testing. |
| 4 | + |
| 5 | +## Usage |
| 6 | + |
| 7 | +### Basic Usage |
| 8 | + |
| 9 | +```bash |
| 10 | +mvn google-adk:web -Dagents=com.example.MyAgentProvider.INSTANCE |
| 11 | +``` |
| 12 | + |
| 13 | +### Parameters |
| 14 | + |
| 15 | +- **`agents`** (required): Full class path to your AgentProvider implementation |
| 16 | +- **`port`** (optional, default: 8000): Port for the web server |
| 17 | +- **`host`** (optional, default: localhost): Host address to bind to |
| 18 | +- **`hotReloading`** (optional, default: true): Whether to enable hot reloading |
| 19 | + |
| 20 | +### Example with Custom Parameters |
| 21 | + |
| 22 | +```bash |
| 23 | +mvn google-adk:web \ |
| 24 | + -Dagents=com.example.MyAgentProvider.INSTANCE \ |
| 25 | + -Dhost=0.0.0.0 \ |
| 26 | + -Dport=9090 \ |
| 27 | + -DhotReloading=false |
| 28 | +``` |
| 29 | + |
| 30 | +## Creating an AgentProvider |
| 31 | + |
| 32 | +### 1. Implement the AgentProvider Interface |
| 33 | + |
| 34 | +Create a class that implements `com.google.adk.maven.AgentProvider`: |
| 35 | + |
| 36 | +```java |
| 37 | +package com.example; |
| 38 | + |
| 39 | +import com.google.adk.agents.BaseAgent; |
| 40 | +import com.google.adk.agents.LlmAgent; |
| 41 | +import com.google.adk.maven.AgentProvider; |
| 42 | +import java.util.Map; |
| 43 | + |
| 44 | +public class MyAgentProvider implements AgentProvider { |
| 45 | + |
| 46 | + public static final MyAgentProvider INSTANCE = new MyAgentProvider(); |
| 47 | + |
| 48 | + @Override |
| 49 | + public Map<String, BaseAgent> getAgents() { |
| 50 | + return Map.of( |
| 51 | + "chat_bot", createChatBot(), |
| 52 | + "code_assistant", createCodeAssistant() |
| 53 | + ); |
| 54 | + } |
| 55 | + |
| 56 | + private BaseAgent createChatBot() { |
| 57 | + return LlmAgent.builder() |
| 58 | + .name("chat_bot") |
| 59 | + .description("A helpful chat bot") |
| 60 | + .model("gemini-2.0-flash") |
| 61 | + .instruction("You are a helpful assistant.") |
| 62 | + .build(); |
| 63 | + } |
| 64 | + |
| 65 | + private BaseAgent createCodeAssistant() { |
| 66 | + return LlmAgent.builder() |
| 67 | + .name("code_assistant") |
| 68 | + .description("A code assistance agent") |
| 69 | + .model("gemini-2.0-flash") |
| 70 | + .instruction("You are a coding assistant. Help users with programming questions.") |
| 71 | + .build(); |
| 72 | + } |
| 73 | +} |
| 74 | +``` |
| 75 | + |
| 76 | +### 2. Add the Plugin to Your Project |
| 77 | + |
| 78 | +Add the plugin to your `pom.xml`: |
| 79 | + |
| 80 | +```xml |
| 81 | +<build> |
| 82 | + <plugins> |
| 83 | + <plugin> |
| 84 | + <groupId>com.google.adk</groupId> |
| 85 | + <artifactId>google-adk-maven-plugin</artifactId> |
| 86 | + <version>0.2.1-SNAPSHOT</version> |
| 87 | + </plugin> |
| 88 | + </plugins> |
| 89 | +</build> |
| 90 | +``` |
| 91 | + |
| 92 | +### 3. Run the Web Server |
| 93 | + |
| 94 | +```bash |
| 95 | +mvn google-adk:web -Dagents=com.example.MyAgentProvider.INSTANCE |
| 96 | +``` |
| 97 | + |
| 98 | +## Alternative AgentProvider Patterns |
| 99 | + |
| 100 | +### Using Default Constructor |
| 101 | + |
| 102 | +```java |
| 103 | +public class SimpleAgentProvider implements AgentProvider { |
| 104 | + // No static field needed, uses default constructor |
| 105 | + @Override |
| 106 | + public Map<String, BaseAgent> getAgents() { |
| 107 | + return Map.of("simple_agent", createSimpleAgent()); |
| 108 | + } |
| 109 | + |
| 110 | + private BaseAgent createSimpleAgent() { |
| 111 | + return LlmAgent.builder() |
| 112 | + .name("simple_agent") |
| 113 | + .description("A simple agent") |
| 114 | + .model("gemini-2.0-flash") |
| 115 | + .instruction("You are a helpful assistant.") |
| 116 | + .build(); |
| 117 | + } |
| 118 | +} |
| 119 | +``` |
| 120 | + |
| 121 | +Usage: |
| 122 | +```bash |
| 123 | +mvn google-adk:web -Dagents=com.example.SimpleAgentProvider |
| 124 | +``` |
| 125 | + |
| 126 | +### Using Other Static Fields |
| 127 | + |
| 128 | +```java |
| 129 | +public class MultipleProviders implements AgentProvider { |
| 130 | + public static final MultipleProviders DEFAULT = new MultipleProviders(); |
| 131 | + public static final MultipleProviders ADVANCED = new MultipleProviders(true); |
| 132 | + |
| 133 | + private final boolean advanced; |
| 134 | + |
| 135 | + public MultipleProviders() { this(false); } |
| 136 | + public MultipleProviders(boolean advanced) { this.advanced = advanced; } |
| 137 | + |
| 138 | + @Override |
| 139 | + public Map<String, BaseAgent> getAgents() { |
| 140 | + if (advanced) { |
| 141 | + return Map.of("advanced_agent", createAdvancedAgent()); |
| 142 | + } |
| 143 | + return Map.of("basic_agent", createBasicAgent()); |
| 144 | + } |
| 145 | + |
| 146 | + private BaseAgent createBasicAgent() { |
| 147 | + return LlmAgent.builder() |
| 148 | + .name("basic_agent") |
| 149 | + .description("A basic agent") |
| 150 | + .model("gemini-2.0-flash") |
| 151 | + .instruction("You are a basic helpful assistant.") |
| 152 | + .build(); |
| 153 | + } |
| 154 | + |
| 155 | + private BaseAgent createAdvancedAgent() { |
| 156 | + return LlmAgent.builder() |
| 157 | + .name("advanced_agent") |
| 158 | + .description("An advanced agent with more capabilities") |
| 159 | + .model("gemini-2.0-flash") |
| 160 | + .instruction("You are an advanced assistant with enhanced capabilities.") |
| 161 | + .build(); |
| 162 | + } |
| 163 | +} |
| 164 | +``` |
| 165 | + |
| 166 | +Usage: |
| 167 | +```bash |
| 168 | +mvn google-adk:web -Dagents=com.example.MultipleProviders.ADVANCED |
| 169 | +``` |
| 170 | + |
| 171 | +## Web UI |
| 172 | + |
| 173 | +Once the server starts, open your browser to: |
| 174 | +- Default: http://localhost:8000 |
| 175 | +- Custom port: http://localhost:{port} |
| 176 | +- External access: http://0.0.0.0:{port} (if using -Dhost=0.0.0.0) |
| 177 | + |
| 178 | +The web UI provides: |
| 179 | +- Interactive chat interface with your agents |
| 180 | +- Agent selection dropdown |
| 181 | +- Real-time streaming responses |
| 182 | +- Session management |
| 183 | +- Debug information |
| 184 | + |
| 185 | +## Dependencies |
| 186 | + |
| 187 | +Make sure your project has the necessary ADK dependencies: |
| 188 | + |
| 189 | +```xml |
| 190 | +<dependencies> |
| 191 | + <dependency> |
| 192 | + <groupId>com.google.adk</groupId> |
| 193 | + <artifactId>google-adk</artifactId> |
| 194 | + <version>0.2.1-SNAPSHOT</version> |
| 195 | + </dependency> |
| 196 | + |
| 197 | + <!-- Maven plugin dependency for AgentProvider interface --> |
| 198 | + <dependency> |
| 199 | + <groupId>com.google.adk</groupId> |
| 200 | + <artifactId>google-adk-maven-plugin</artifactId> |
| 201 | + <version>0.2.1-SNAPSHOT</version> |
| 202 | + <scope>compile</scope> |
| 203 | + </dependency> |
| 204 | +</dependencies> |
| 205 | +``` |
| 206 | + |
| 207 | +### Plugin Usage Options |
| 208 | + |
| 209 | +**Option 1: With plugin declaration (shorter commands)** |
| 210 | + |
| 211 | +Add the plugin to your `pom.xml` for convenience: |
| 212 | + |
| 213 | +```xml |
| 214 | +<build> |
| 215 | + <plugins> |
| 216 | + <plugin> |
| 217 | + <groupId>com.google.adk</groupId> |
| 218 | + <artifactId>google-adk-maven-plugin</artifactId> |
| 219 | + <version>0.2.1-SNAPSHOT</version> |
| 220 | + </plugin> |
| 221 | + </plugins> |
| 222 | +</build> |
| 223 | +``` |
| 224 | + |
| 225 | +Then use the short command: |
| 226 | +```bash |
| 227 | +mvn google-adk:web -Dagents=com.example.MyAgentProvider.INSTANCE |
| 228 | +``` |
| 229 | + |
| 230 | +**Option 2: Without plugin declaration (no pom.xml changes)** |
| 231 | + |
| 232 | +Use the full coordinates directly: |
| 233 | +```bash |
| 234 | +mvn com.google.adk:google-adk-maven-plugin:web -Dagents=com.example.MyAgentProvider.INSTANCE |
| 235 | +``` |
| 236 | + |
| 237 | +## Stopping the Server |
| 238 | + |
| 239 | +Press `Ctrl+C` in the terminal to stop the server. |
0 commit comments