Skip to content

Commit 322378e

Browse files
authored
Merge branch 'main' into feat/planner-support
2 parents 9e85079 + 62ed9d8 commit 322378e

31 files changed

+3800
-674
lines changed

CHANGELOG.md

Whitespace-only changes.

core/pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,11 @@
8181
<artifactId>auto-value-annotations</artifactId>
8282
<scope>provided</scope>
8383
</dependency>
84+
<dependency>
85+
<groupId>com.google.guava</groupId>
86+
<artifactId>guava</artifactId>
87+
<version>33.0.0-jre</version>
88+
</dependency>
8489
<dependency>
8590
<groupId>com.google.errorprone</groupId>
8691
<artifactId>error_prone_annotations</artifactId>

core/src/main/java/com/google/adk/agents/BaseAgentConfig.java

Lines changed: 7 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
package com.google.adk.agents;
1818

19-
import com.fasterxml.jackson.annotation.JsonProperty;
2019
import java.util.List;
2120

2221
/**
@@ -32,50 +31,23 @@ public class BaseAgentConfig {
3231

3332
/**
3433
* Configuration for referencing other agents (subagents). Supports both config-based references
35-
* (YAML files) and programmatic references (Java classes).
34+
* (YAML files) and programmatic references (via code registry).
3635
*/
3736
public static class AgentRefConfig {
38-
private String name;
3937
private String configPath;
40-
private String className;
41-
private String staticField;
38+
private String code;
4239

4340
public AgentRefConfig() {}
4441

4542
/**
4643
* Constructor for config-based agent reference.
4744
*
48-
* @param name The name of the subagent
4945
* @param configPath The path to the subagent's config file
5046
*/
51-
public AgentRefConfig(String name, String configPath) {
52-
this.name = name;
47+
public AgentRefConfig(String configPath) {
5348
this.configPath = configPath;
5449
}
5550

56-
/**
57-
* Constructor for programmatic agent reference.
58-
*
59-
* @param name The name of the subagent
60-
* @param className The Java class name
61-
* @param staticField Optional static field name
62-
*/
63-
public AgentRefConfig(String name, String className, String staticField) {
64-
this.name = name;
65-
this.className = className;
66-
this.staticField = staticField;
67-
}
68-
69-
@JsonProperty("name")
70-
public String name() {
71-
return name;
72-
}
73-
74-
public void setName(String name) {
75-
this.name = name;
76-
}
77-
78-
@JsonProperty("config_path")
7951
public String configPath() {
8052
return configPath;
8153
}
@@ -84,37 +56,12 @@ public void setConfigPath(String configPath) {
8456
this.configPath = configPath;
8557
}
8658

87-
@JsonProperty("class_name")
88-
public String className() {
89-
return className;
90-
}
91-
92-
public void setClassName(String className) {
93-
this.className = className;
94-
}
95-
96-
@JsonProperty("static_field")
97-
public String staticField() {
98-
return staticField;
99-
}
100-
101-
public void setStaticField(String staticField) {
102-
this.staticField = staticField;
59+
public String code() {
60+
return code;
10361
}
10462

105-
@Override
106-
public String toString() {
107-
if (configPath != null) {
108-
return "AgentRefConfig{name='" + name + "', configPath='" + configPath + "'}";
109-
} else {
110-
return "AgentRefConfig{name='"
111-
+ name
112-
+ "', className='"
113-
+ className
114-
+ "', staticField='"
115-
+ staticField
116-
+ "'}";
117-
}
63+
public void setCode(String code) {
64+
this.code = code;
11865
}
11966
}
12067

@@ -133,7 +80,6 @@ public BaseAgentConfig(String name, String description, String agentClass) {
13380
this.agentClass = agentClass;
13481
}
13582

136-
@JsonProperty(value = "name", required = true)
13783
public String name() {
13884
return name;
13985
}
@@ -142,7 +88,6 @@ public void setName(String name) {
14288
this.name = name;
14389
}
14490

145-
@JsonProperty("description")
14691
public String description() {
14792
return description;
14893
}
@@ -151,7 +96,6 @@ public void setDescription(String description) {
15196
this.description = description;
15297
}
15398

154-
@JsonProperty("agent_class")
15599
public String agentClass() {
156100
return agentClass;
157101
}
@@ -160,7 +104,6 @@ public void setAgentClass(String agentClass) {
160104
this.agentClass = agentClass;
161105
}
162106

163-
@JsonProperty("sub_agents")
164107
public List<AgentRefConfig> subAgents() {
165108
return subAgents;
166109
}

core/src/main/java/com/google/adk/agents/Callbacks.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,10 @@ public interface BeforeModelCallback extends BeforeModelCallbackBase {
3636
* Async callback before LLM invocation.
3737
*
3838
* @param callbackContext Callback context.
39-
* @param llmRequest LLM request.
39+
* @param llmRequestBuilder LLM request builder.
4040
* @return response override, or empty to continue.
4141
*/
42-
Maybe<LlmResponse> call(CallbackContext callbackContext, LlmRequest llmRequest);
42+
Maybe<LlmResponse> call(CallbackContext callbackContext, LlmRequest.Builder llmRequestBuilder);
4343
}
4444

4545
/**
@@ -48,7 +48,8 @@ public interface BeforeModelCallback extends BeforeModelCallbackBase {
4848
*/
4949
@FunctionalInterface
5050
public interface BeforeModelCallbackSync extends BeforeModelCallbackBase {
51-
Optional<LlmResponse> call(CallbackContext callbackContext, LlmRequest llmRequest);
51+
Optional<LlmResponse> call(
52+
CallbackContext callbackContext, LlmRequest.Builder llmRequestBuilder);
5253
}
5354

5455
interface AfterModelCallbackBase {}

core/src/main/java/com/google/adk/agents/ConfigAgentUtils.java

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,15 @@
1717
package com.google.adk.agents;
1818

1919
import com.fasterxml.jackson.databind.DeserializationFeature;
20+
import com.fasterxml.jackson.databind.MapperFeature;
2021
import com.fasterxml.jackson.databind.ObjectMapper;
22+
import com.fasterxml.jackson.databind.json.JsonMapper;
2123
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
2224
import com.google.adk.utils.ComponentRegistry;
2325
import com.google.common.collect.ImmutableList;
2426
import java.io.File;
25-
import java.io.FileInputStream;
2627
import java.io.IOException;
27-
import java.io.InputStream;
28+
import java.nio.charset.StandardCharsets;
2829
import java.nio.file.Files;
2930
import java.nio.file.Path;
3031
import java.nio.file.Paths;
@@ -110,9 +111,7 @@ public static ImmutableList<BaseAgent> resolveSubAgents(
110111
resolvedSubAgents.add(subAgent);
111112
logger.debug("Successfully resolved subagent: {}", subAgent.name());
112113
} catch (Exception e) {
113-
String errorMsg =
114-
"Failed to resolve subagent: "
115-
+ (subAgentConfig.name() != null ? subAgentConfig.name() : "unnamed");
114+
String errorMsg = "Failed to resolve subagent";
116115
logger.error(errorMsg, e);
117116
throw new ConfigurationException(errorMsg, e);
118117
}
@@ -136,19 +135,18 @@ private static BaseAgent resolveSubAgent(
136135
return resolveSubAgentFromConfigPath(subAgentConfig, configDir);
137136
}
138137

139-
// TODO: Add support for programmatic subagent resolution (className/staticField).
140-
if (subAgentConfig.className() != null || subAgentConfig.staticField() != null) {
141-
throw new ConfigurationException(
142-
"Programmatic subagent resolution (className/staticField) is not yet supported for"
143-
+ " subagent: "
144-
+ subAgentConfig.name());
138+
// Check for programmatic references (only 'code' is supported)
139+
if (subAgentConfig.code() != null && !subAgentConfig.code().trim().isEmpty()) {
140+
String registryKey = subAgentConfig.code().trim();
141+
return ComponentRegistry.resolveAgentInstance(registryKey)
142+
.orElseThrow(
143+
() ->
144+
new ConfigurationException(
145+
"Failed to resolve subagent from registry with code key: " + registryKey));
145146
}
146147

147148
throw new ConfigurationException(
148-
"Subagent configuration for '"
149-
+ subAgentConfig.name()
150-
+ "' must specify 'configPath'."
151-
+ " Programmatic references (className/staticField) are not yet supported.");
149+
"Subagent configuration must specify either 'configPath' or 'code'.");
152150
}
153151

154152
/** Resolves a subagent from a configuration file path. */
@@ -187,11 +185,18 @@ private static BaseAgent resolveSubAgentFromConfigPath(
187185
*/
188186
private static <T extends BaseAgentConfig> T loadConfigAsType(
189187
String configPath, Class<T> configClass) throws ConfigurationException {
190-
try (InputStream inputStream = new FileInputStream(configPath)) {
191-
ObjectMapper mapper = new ObjectMapper(new YAMLFactory());
192-
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
193-
mapper.enable(com.fasterxml.jackson.databind.MapperFeature.ACCEPT_CASE_INSENSITIVE_ENUMS);
194-
return mapper.readValue(inputStream, configClass);
188+
try {
189+
String yamlContent = Files.readString(Paths.get(configPath), StandardCharsets.UTF_8);
190+
191+
// Preprocess YAML to convert snake_case to camelCase
192+
String processedYaml = YamlPreprocessor.preprocessYaml(yamlContent);
193+
194+
ObjectMapper mapper =
195+
JsonMapper.builder(new YAMLFactory())
196+
.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES)
197+
.enable(MapperFeature.ACCEPT_CASE_INSENSITIVE_ENUMS)
198+
.build();
199+
return mapper.readValue(processedYaml, configClass);
195200
} catch (IOException e) {
196201
throw new ConfigurationException("Failed to load or parse config file: " + configPath, e);
197202
}

0 commit comments

Comments
 (0)