File tree Expand file tree Collapse file tree 1 file changed +10
-2
lines changed
ml-algorithms/src/main/java/org/opensearch/ml/engine/algorithms/agent Expand file tree Collapse file tree 1 file changed +10
-2
lines changed Original file line number Diff line number Diff line change @@ -320,7 +320,15 @@ public static Map<String, String> parseLLMOutput(
320
320
parseThoughtResponse (modelOutput , thoughtResponse );
321
321
} else if (parameters .containsKey (TOOL_CALLS_PATH )) {
322
322
modelOutput .put (THOUGHT_RESPONSE , StringUtils .toJson (dataAsMap ));
323
- Object response = JsonPath .read (dataAsMap , parameters .get (LLM_RESPONSE_FILTER ));
323
+ Object response ;
324
+ boolean isToolUseResponse = false ;
325
+ try {
326
+ response = JsonPath .read (dataAsMap , parameters .get (LLM_RESPONSE_FILTER ));
327
+ } catch (PathNotFoundException e ) {
328
+ // If the regular response path fails, try the tool calls path
329
+ response = JsonPath .read (dataAsMap , parameters .get (TOOL_CALLS_PATH ));
330
+ isToolUseResponse = true ;
331
+ }
324
332
325
333
String llmFinishReasonPath = parameters .get (LLM_FINISH_REASON_PATH );
326
334
String llmFinishReason = "" ;
@@ -330,7 +338,7 @@ public static Map<String, String> parseLLMOutput(
330
338
} else {
331
339
llmFinishReason = JsonPath .read (dataAsMap , llmFinishReasonPath );
332
340
}
333
- if (parameters .get (LLM_FINISH_REASON_TOOL_USE ).equalsIgnoreCase (llmFinishReason )) {
341
+ if (parameters .get (LLM_FINISH_REASON_TOOL_USE ).equalsIgnoreCase (llmFinishReason ) || isToolUseResponse ) {
334
342
List toolCalls = null ;
335
343
try {
336
344
String toolCallsPath = parameters .get (TOOL_CALLS_PATH );
You can’t perform that action at this time.
0 commit comments