Skip to content

Commit 9e2c926

Browse files
google-genai-botcopybara-github
authored andcommitted
refactor: Runner and App now use ? extends Plugin
PiperOrigin-RevId: 862786641
1 parent e0fd53c commit 9e2c926

4 files changed

Lines changed: 19 additions & 25 deletions

File tree

core/src/main/java/com/google/adk/apps/App.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
package com.google.adk.apps;
1818

1919
import com.google.adk.agents.BaseAgent;
20-
import com.google.adk.plugins.BasePlugin;
20+
import com.google.adk.plugins.Plugin;
2121
import com.google.adk.summarizer.EventsCompactionConfig;
2222
import com.google.common.collect.ImmutableList;
2323
import com.google.errorprone.annotations.CanIgnoreReturnValue;
@@ -38,14 +38,14 @@ public class App {
3838

3939
private final String name;
4040
private final BaseAgent rootAgent;
41-
private final ImmutableList<BasePlugin> plugins;
41+
private final ImmutableList<? extends Plugin> plugins;
4242
@Nullable private final EventsCompactionConfig eventsCompactionConfig;
4343
@Nullable private final ResumabilityConfig resumabilityConfig;
4444

4545
private App(
4646
String name,
4747
BaseAgent rootAgent,
48-
List<BasePlugin> plugins,
48+
List<? extends Plugin> plugins,
4949
@Nullable EventsCompactionConfig eventsCompactionConfig,
5050
@Nullable ResumabilityConfig resumabilityConfig) {
5151
this.name = name;
@@ -63,7 +63,7 @@ public BaseAgent rootAgent() {
6363
return rootAgent;
6464
}
6565

66-
public ImmutableList<BasePlugin> plugins() {
66+
public ImmutableList<? extends Plugin> plugins() {
6767
return plugins;
6868
}
6969

@@ -81,7 +81,7 @@ public ResumabilityConfig resumabilityConfig() {
8181
public static class Builder {
8282
private String name;
8383
private BaseAgent rootAgent;
84-
private List<BasePlugin> plugins = ImmutableList.of();
84+
private List<? extends Plugin> plugins = ImmutableList.of();
8585
@Nullable private EventsCompactionConfig eventsCompactionConfig;
8686
@Nullable private ResumabilityConfig resumabilityConfig;
8787

@@ -98,7 +98,7 @@ public Builder rootAgent(BaseAgent rootAgent) {
9898
}
9999

100100
@CanIgnoreReturnValue
101-
public Builder plugins(List<BasePlugin> plugins) {
101+
public Builder plugins(List<? extends Plugin> plugins) {
102102
this.plugins = plugins;
103103
return this;
104104
}

core/src/main/java/com/google/adk/plugins/PluginManager.java

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -41,28 +41,22 @@
4141
* <p>The PluginManager is an internal class that orchestrates the invocation of plugin callbacks at
4242
* key points in the SDK's execution lifecycle.
4343
*/
44-
public class PluginManager implements Plugin {
44+
public class PluginManager extends BasePlugin {
4545
private static final Logger logger = LoggerFactory.getLogger(PluginManager.class);
46-
private final List<Plugin> plugins;
46+
private final List<Plugin> plugins = new ArrayList<>();
4747

4848
public PluginManager(List<? extends Plugin> plugins) {
49+
super("PluginManager");
4950
this.plugins = new ArrayList<>();
5051
if (plugins != null) {
51-
for (var plugin : plugins) {
52-
this.registerPlugin(plugin);
53-
}
52+
plugins.forEach(this::registerPlugin);
5453
}
5554
}
5655

5756
public PluginManager() {
5857
this(null);
5958
}
6059

61-
@Override
62-
public String getName() {
63-
return "PluginManager";
64-
}
65-
6660
/**
6761
* Registers a new plugin.
6862
*

core/src/main/java/com/google/adk/runner/InMemoryRunner.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
import com.google.adk.agents.BaseAgent;
2020
import com.google.adk.artifacts.InMemoryArtifactService;
2121
import com.google.adk.memory.InMemoryMemoryService;
22-
import com.google.adk.plugins.BasePlugin;
22+
import com.google.adk.plugins.Plugin;
2323
import com.google.adk.sessions.InMemorySessionService;
2424
import com.google.common.collect.ImmutableList;
2525
import java.util.List;
@@ -37,7 +37,7 @@ public InMemoryRunner(BaseAgent agent, String appName) {
3737
this(agent, appName, ImmutableList.of());
3838
}
3939

40-
public InMemoryRunner(BaseAgent agent, String appName, List<BasePlugin> plugins) {
40+
public InMemoryRunner(BaseAgent agent, String appName, List<? extends Plugin> plugins) {
4141
super(
4242
agent,
4343
appName,

core/src/main/java/com/google/adk/runner/Runner.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
import com.google.adk.events.EventActions;
3131
import com.google.adk.memory.BaseMemoryService;
3232
import com.google.adk.models.Model;
33-
import com.google.adk.plugins.BasePlugin;
33+
import com.google.adk.plugins.Plugin;
3434
import com.google.adk.plugins.PluginManager;
3535
import com.google.adk.sessions.BaseSessionService;
3636
import com.google.adk.sessions.InMemorySessionService;
@@ -84,7 +84,7 @@ public static class Builder {
8484
private BaseArtifactService artifactService = new InMemoryArtifactService();
8585
private BaseSessionService sessionService = new InMemorySessionService();
8686
@Nullable private BaseMemoryService memoryService = null;
87-
private List<BasePlugin> plugins = ImmutableList.of();
87+
private List<? extends Plugin> plugins = ImmutableList.of();
8888

8989
@CanIgnoreReturnValue
9090
public Builder app(App app) {
@@ -126,7 +126,7 @@ public Builder memoryService(BaseMemoryService memoryService) {
126126
}
127127

128128
@CanIgnoreReturnValue
129-
public Builder plugins(List<BasePlugin> plugins) {
129+
public Builder plugins(List<? extends Plugin> plugins) {
130130
Preconditions.checkState(this.app == null, "plugins() cannot be called when app is set.");
131131
this.plugins = plugins;
132132
return this;
@@ -135,7 +135,7 @@ public Builder plugins(List<BasePlugin> plugins) {
135135
public Runner build() {
136136
BaseAgent buildAgent;
137137
String buildAppName;
138-
List<BasePlugin> buildPlugins;
138+
List<? extends Plugin> buildPlugins;
139139
ResumabilityConfig buildResumabilityConfig;
140140
EventsCompactionConfig buildEventsCompactionConfig;
141141

@@ -224,7 +224,7 @@ public Runner(
224224
BaseArtifactService artifactService,
225225
BaseSessionService sessionService,
226226
@Nullable BaseMemoryService memoryService,
227-
List<BasePlugin> plugins) {
227+
List<? extends Plugin> plugins) {
228228
this(
229229
agent,
230230
appName,
@@ -247,7 +247,7 @@ public Runner(
247247
BaseArtifactService artifactService,
248248
BaseSessionService sessionService,
249249
@Nullable BaseMemoryService memoryService,
250-
List<BasePlugin> plugins,
250+
List<? extends Plugin> plugins,
251251
ResumabilityConfig resumabilityConfig) {
252252
this(
253253
agent,
@@ -272,7 +272,7 @@ protected Runner(
272272
BaseArtifactService artifactService,
273273
BaseSessionService sessionService,
274274
@Nullable BaseMemoryService memoryService,
275-
List<BasePlugin> plugins,
275+
List<? extends Plugin> plugins,
276276
ResumabilityConfig resumabilityConfig,
277277
@Nullable EventsCompactionConfig eventsCompactionConfig) {
278278
this.agent = agent;

0 commit comments

Comments
 (0)