Skip to content

Commit 8bd5e51

Browse files
committed
spotless apply and change log levels
Signed-off-by: Jiaping Zeng <[email protected]>
1 parent b6685c6 commit 8bd5e51

File tree

8 files changed

+48
-53
lines changed

8 files changed

+48
-53
lines changed

common/src/main/java/org/opensearch/ml/common/agui/AGUIInputConverter.java

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import java.util.List;
3030
import java.util.Map;
3131

32+
import org.opensearch.ml.common.FunctionName;
3233
import org.opensearch.ml.common.dataset.remote.RemoteInferenceInputDataSet;
3334
import org.opensearch.ml.common.input.execute.agent.AgentMLInput;
3435

@@ -47,27 +48,27 @@ public class AGUIInputConverter {
4748
public static boolean isAGUIInput(String inputJson) {
4849
try {
4950
JsonObject jsonObj = JsonParser.parseString(inputJson).getAsJsonObject();
50-
51+
5152
// Check required fields exist
52-
if (!jsonObj.has(AGUI_FIELD_THREAD_ID)
53-
|| !jsonObj.has(AGUI_FIELD_RUN_ID)
54-
|| !jsonObj.has(AGUI_FIELD_MESSAGES)
53+
if (!jsonObj.has(AGUI_FIELD_THREAD_ID)
54+
|| !jsonObj.has(AGUI_FIELD_RUN_ID)
55+
|| !jsonObj.has(AGUI_FIELD_MESSAGES)
5556
|| !jsonObj.has(AGUI_FIELD_TOOLS)) {
5657
return false;
5758
}
58-
59+
5960
// Validate messages is an array
6061
JsonElement messages = jsonObj.get(AGUI_FIELD_MESSAGES);
6162
if (!messages.isJsonArray()) {
6263
return false;
6364
}
64-
65+
6566
// Validate tools is an array
6667
JsonElement tools = jsonObj.get(AGUI_FIELD_TOOLS);
6768
if (!tools.isJsonArray()) {
6869
return false;
6970
}
70-
71+
7172
return true;
7273
} catch (Exception e) {
7374
log.debug("Failed to parse input as JSON for AG-UI detection", e);
@@ -112,13 +113,7 @@ public static AgentMLInput convertFromAGUIInput(String aguiInputJson, String age
112113
parameters.put(AGUI_PARAM_FORWARDED_PROPS, gson.toJson(forwardedProps));
113114
}
114115
RemoteInferenceInputDataSet inputDataSet = RemoteInferenceInputDataSet.builder().parameters(parameters).build();
115-
AgentMLInput agentMLInput = new AgentMLInput(
116-
agentId,
117-
tenantId,
118-
org.opensearch.ml.common.FunctionName.AGENT,
119-
inputDataSet,
120-
isAsync
121-
);
116+
AgentMLInput agentMLInput = new AgentMLInput(agentId, tenantId, FunctionName.AGENT, inputDataSet, isAsync);
122117

123118
log.debug("Converted AG-UI input to ML-Commons format for agent: {}", agentId);
124119
return agentMLInput;

ml-algorithms/src/main/java/org/opensearch/ml/engine/algorithms/agent/MLAGUIAgentRunner.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
import static org.opensearch.ml.common.agui.AGUIConstants.AGUI_FIELD_ID;
1212
import static org.opensearch.ml.common.agui.AGUIConstants.AGUI_FIELD_NAME;
1313
import static org.opensearch.ml.common.agui.AGUIConstants.AGUI_FIELD_ROLE;
14-
import static org.opensearch.ml.common.agui.AGUIConstants.AGUI_FIELD_TOOL_CALL_ID;
1514
import static org.opensearch.ml.common.agui.AGUIConstants.AGUI_FIELD_TOOL_CALLS;
15+
import static org.opensearch.ml.common.agui.AGUIConstants.AGUI_FIELD_TOOL_CALL_ID;
1616
import static org.opensearch.ml.common.agui.AGUIConstants.AGUI_FIELD_TYPE;
1717
import static org.opensearch.ml.common.agui.AGUIConstants.AGUI_PARAM_ASSISTANT_TOOL_CALL_MESSAGES;
1818
import static org.opensearch.ml.common.agui.AGUIConstants.AGUI_PARAM_CONTEXT;
@@ -164,10 +164,10 @@ private void processAgentResult(Object result, AGUIEventCollector eventCollector
164164
String resultString = (String) result;
165165
// Check if this is a frontend tool call response
166166
if (resultString.startsWith("FRONTEND_TOOL_CALL: ")) {
167-
log.info("AG-UI: Detected frontend tool call response, processing...");
167+
log.debug("AG-UI: Detected frontend tool call response, processing...");
168168
processFrontendToolCall(resultString, eventCollector);
169169
} else {
170-
log.info("AG-UI: String result is not a frontend tool call");
170+
log.debug("AG-UI: String result is not a frontend tool call");
171171
}
172172
}
173173
List<Object> messages = new ArrayList<>();
@@ -284,11 +284,11 @@ private void processToolCallsFromDataMap(Map<String, ?> dataMap, AGUIEventCollec
284284
}
285285

286286
private void processFrontendToolCall(String frontendToolCallResponse, AGUIEventCollector eventCollector) {
287-
log.info("AG-UI: Processing frontend tool call response: {}", frontendToolCallResponse);
287+
log.debug("AG-UI: Processing frontend tool call response: {}", frontendToolCallResponse);
288288
try {
289289
// Extract the JSON part after "FRONTEND_TOOL_CALL: "
290290
String jsonPart = frontendToolCallResponse.substring("FRONTEND_TOOL_CALL: ".length());
291-
log.info("AG-UI: Extracted JSON part: {}", jsonPart);
291+
log.debug("AG-UI: Extracted JSON part: {}", jsonPart);
292292

293293
JsonElement element = gson.fromJson(jsonPart, JsonElement.class);
294294

@@ -297,7 +297,7 @@ private void processFrontendToolCall(String frontendToolCallResponse, AGUIEventC
297297
String toolName = toolCallObj.get("tool").getAsString();
298298
String toolInput = toolCallObj.get("input").getAsString();
299299

300-
log.info("AG-UI: Processing frontend tool call - tool: {}, input: {}", toolName, toolInput);
300+
log.debug("AG-UI: Processing frontend tool call - tool: {}, input: {}", toolName, toolInput);
301301

302302
// Generate AG-UI events for the frontend tool call
303303
String toolCallId = eventCollector.startToolCall(toolName, null);

ml-algorithms/src/main/java/org/opensearch/ml/engine/algorithms/agent/MLChatAgentRunner.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -492,8 +492,8 @@ private void runReAct(
492492
.mlModelOutputs(List.of(modelTensors))
493493
.build();
494494

495-
log.info("AG-UI: Generated ModelTensorOutput with frontend tool call events for tool: {}", action);
496-
log.info("AG-UI: Bypassing ReAct loop and returning frontend tool calls directly to MLAGUIAgentRunner");
495+
log.debug("AG-UI: Generated ModelTensorOutput with frontend tool call events for tool: {}", action);
496+
log.debug("AG-UI: Bypassing ReAct loop and returning frontend tool calls directly to MLAGUIAgentRunner");
497497

498498
// Exit ReAct loop early and return frontend tool calls directly to main listener (MLAGUIAgentRunner)
499499
listener.onResponse(frontendToolResponse);
@@ -1186,7 +1186,7 @@ public void setAttributes(Map<String, Object> attributes) { /* Not needed for fr
11861186
public <T> void run(Map<String, String> parameters, ActionListener<T> listener) {
11871187
// Frontend tools return a placeholder result that allows ReAct to continue
11881188
// The actual AG-UI events will be generated when MLAGUIAgentRunner processes the LLM response
1189-
log.info("AG-UI: Frontend tool {} executed with parameters: {}", toolName, parameters);
1189+
log.debug("AG-UI: Frontend tool {} executed with parameters: {}", toolName, parameters);
11901190
// Frontend tools should not be executed during ReAct - they should be called by the LLM in its final response
11911191
// Return an error to indicate this tool should be called differently
11921192
String errorResult = String
@@ -1257,7 +1257,7 @@ private void processAGUIToolResults(
12571257
String aguiToolCallResults
12581258
) {
12591259
try {
1260-
log.info("AG-UI: Processing tool call results for agent: {}", mlAgent.getName());
1260+
log.debug("AG-UI: Processing tool call results for agent: {}", mlAgent.getName());
12611261

12621262
// Parse tool call results from frontend
12631263
Type listType = new TypeToken<List<Map<String, String>>>() {

ml-algorithms/src/main/java/org/opensearch/ml/engine/algorithms/remote/streaming/BedrockStreamingHandler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ public BedrockStreamingHandler(SdkAsyncHttpClient httpClient, AwsConnector conne
9898
&& (parameters.containsKey(AGUI_PARAM_THREAD_ID) || parameters.containsKey(AGUI_PARAM_RUN_ID));
9999

100100
if (isAGUIAgent) {
101-
log.info("BedrockStreamingHandler: Detected AG-UI agent - raw tool use events will be filtered");
101+
log.debug("BedrockStreamingHandler: Detected AG-UI agent - raw tool use events will be filtered");
102102
}
103103
}
104104

ml-algorithms/src/main/java/org/opensearch/ml/engine/algorithms/remote/streaming/HttpStreamingHandler.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55

66
package org.opensearch.ml.engine.algorithms.remote.streaming;
77

8+
import static org.opensearch.ml.common.agui.AGUIConstants.AGUI_PARAM_RUN_ID;
9+
import static org.opensearch.ml.common.agui.AGUIConstants.AGUI_PARAM_THREAD_ID;
810
import static org.opensearch.ml.common.utils.StringUtils.gson;
911
import static org.opensearch.ml.engine.algorithms.agent.AgentUtils.LLM_INTERFACE_OPENAI_V1_CHAT_COMPLETIONS;
1012

@@ -117,10 +119,11 @@ public HTTPEventSourceListener(
117119
this.isStreamClosed = new AtomicBoolean(false);
118120

119121
// Detect if this is an AG-UI agent by checking for AG-UI specific parameters
120-
this.isAGUIAgent = parameters != null && (parameters.containsKey("agui_thread_id") || parameters.containsKey("agui_run_id"));
122+
this.isAGUIAgent = parameters != null
123+
&& (parameters.containsKey(AGUI_PARAM_THREAD_ID) || parameters.containsKey(AGUI_PARAM_RUN_ID));
121124

122125
if (isAGUIAgent) {
123-
log.info("HttpStreamingHandler: Detected AG-UI agent - raw function call chunks will be filtered");
126+
log.debug("HttpStreamingHandler: Detected AG-UI agent - raw function call chunks will be filtered");
124127
}
125128
}
126129

ml-algorithms/src/test/java/org/opensearch/ml/engine/algorithms/agent/MLAGUIAgentRunnerTest.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import static org.junit.Assert.assertTrue;
1010
import static org.opensearch.ml.engine.algorithms.agent.MLChatAgentRunner.CONTEXT;
1111

12+
import java.lang.reflect.Method;
1213
import java.util.HashMap;
1314
import java.util.Map;
1415

@@ -58,7 +59,7 @@ public void testProcessAGUIContext_WithValidContext() {
5859

5960
// Use reflection to call the private method
6061
try {
61-
java.lang.reflect.Method method = MLAGUIAgentRunner.class.getDeclaredMethod("processAGUIContext", MLAgent.class, Map.class);
62+
Method method = MLAGUIAgentRunner.class.getDeclaredMethod("processAGUIContext", MLAgent.class, Map.class);
6263
method.setAccessible(true);
6364
method.invoke(agentRunner, mlAgent, params);
6465
} catch (Exception e) {
@@ -84,7 +85,7 @@ public void testProcessAGUIContext_WithEmptyContext() {
8485

8586
// Use reflection to call the private method
8687
try {
87-
java.lang.reflect.Method method = MLAGUIAgentRunner.class.getDeclaredMethod("processAGUIContext", MLAgent.class, Map.class);
88+
Method method = MLAGUIAgentRunner.class.getDeclaredMethod("processAGUIContext", MLAgent.class, Map.class);
8889
method.setAccessible(true);
8990
method.invoke(agentRunner, mlAgent, params);
9091
} catch (Exception e) {
@@ -102,7 +103,7 @@ public void testProcessAGUIContext_WithNoContext() {
102103

103104
// Use reflection to call the private method
104105
try {
105-
java.lang.reflect.Method method = MLAGUIAgentRunner.class.getDeclaredMethod("processAGUIContext", MLAgent.class, Map.class);
106+
Method method = MLAGUIAgentRunner.class.getDeclaredMethod("processAGUIContext", MLAgent.class, Map.class);
106107
method.setAccessible(true);
107108
method.invoke(agentRunner, mlAgent, params);
108109
} catch (Exception e) {
@@ -121,7 +122,7 @@ public void testProcessAGUIContext_WithInvalidJson() {
121122

122123
// Use reflection to call the private method
123124
try {
124-
java.lang.reflect.Method method = MLAGUIAgentRunner.class.getDeclaredMethod("processAGUIContext", MLAgent.class, Map.class);
125+
Method method = MLAGUIAgentRunner.class.getDeclaredMethod("processAGUIContext", MLAgent.class, Map.class);
125126
method.setAccessible(true);
126127
method.invoke(agentRunner, mlAgent, params);
127128
} catch (Exception e) {
@@ -148,7 +149,7 @@ public void testProcessAGUIContext_WithMissingFields() {
148149

149150
// Use reflection to call the private method
150151
try {
151-
java.lang.reflect.Method method = MLAGUIAgentRunner.class.getDeclaredMethod("processAGUIContext", MLAgent.class, Map.class);
152+
Method method = MLAGUIAgentRunner.class.getDeclaredMethod("processAGUIContext", MLAgent.class, Map.class);
152153
method.setAccessible(true);
153154
method.invoke(agentRunner, mlAgent, params);
154155
} catch (Exception e) {
@@ -183,7 +184,7 @@ public void testProcessAGUIContext_RealWorldSample() {
183184

184185
// Use reflection to call the private method
185186
try {
186-
java.lang.reflect.Method method = MLAGUIAgentRunner.class.getDeclaredMethod("processAGUIContext", MLAgent.class, Map.class);
187+
Method method = MLAGUIAgentRunner.class.getDeclaredMethod("processAGUIContext", MLAgent.class, Map.class);
187188
method.setAccessible(true);
188189
method.invoke(agentRunner, mlAgent, params);
189190
} catch (Exception e) {

plugin/src/main/java/org/opensearch/ml/rest/RestMLExecuteAction.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ MLExecuteTaskRequest getRequest(RestRequest request) throws IOException {
128128

129129
String requestBodyJson = request.contentOrSourceParam().v2().utf8ToString();
130130
if (AGUIInputConverter.isAGUIInput(requestBodyJson)) {
131-
log.info("Detected AG-UI input format for agent: {}", agentId);
131+
log.debug("AG-UI: Detected AG-UI input format for agent: {}", agentId);
132132
input = AGUIInputConverter.convertFromAGUIInput(requestBodyJson, agentId, tenantId, async);
133133
} else {
134134
input = MLInput.parse(parser, functionName.name());

0 commit comments

Comments
 (0)