Skip to content

Commit 008c196

Browse files
Doris26copybara-github
authored andcommitted
feat: update ConfigAgentLoader to load agents from the current directory
The ConfigAgentLoader is updated to support loading agent configurations directly from the specified directory, in addition to subdirectories. This allows for more flexible project structures where an agent configuration might reside alongside a pom.xml without needing its own subdirectory. PiperOrigin-RevId: 800650807
1 parent 87acdf8 commit 008c196

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

maven_plugin/examples/simple-agent/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,4 +62,4 @@
6262
</plugin>
6363
</plugins>
6464
</build>
65-
</project>
65+
</project>

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,25 @@ private void discoverAgents() throws IOException {
140140

141141
logger.info("Initial scan for YAML agents in: {}", sourcePath);
142142

143+
// First, check if the current directory itself contains a root_agent.yaml
144+
Path currentDirYamlPath = sourcePath.resolve(YAML_CONFIG_FILENAME);
145+
if (Files.exists(currentDirYamlPath) && Files.isRegularFile(currentDirYamlPath)) {
146+
String agentName = sourcePath.getFileName().toString();
147+
logger.debug("Discovering YAML agent config in current directory: {}", currentDirYamlPath);
148+
149+
// Create a memoized supplier that will load the agent only when requested
150+
agentSuppliers.put(agentName, Suppliers.memoize(() -> loadAgentFromPath(currentDirYamlPath)));
151+
152+
// Register with watcher if hot-reloading is enabled
153+
if (hotReloadingEnabled && watcher != null) {
154+
watcher.watch(sourcePath, agentDirPath -> updateAgentSupplier(agentDirPath));
155+
}
156+
157+
logger.info("Discovered YAML agent '{}' from: {}", agentName, currentDirYamlPath);
158+
return;
159+
}
160+
161+
// Otherwise, scan subdirectories for agents
143162
try (Stream<Path> entries = Files.list(sourcePath)) {
144163
for (Path agentDir : entries.collect(toList())) {
145164
if (Files.isDirectory(agentDir)) {

0 commit comments

Comments
 (0)