Skip to content

Add error handling for plan&execute agent #3845

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -701,7 +701,13 @@ private static void runTool(
);
nextStepListener
.onResponse(
String.format(Locale.ROOT, "Failed to run the tool %s with the error message %s.", finalAction, e.getMessage())
String
.format(
Locale.ROOT,
"Failed to run the tool %s with the error message %s.",
finalAction,
e.getMessage().replaceAll("\\n", "\n")
)
);
});
if (tools.get(action) instanceof MLModelTool) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,11 @@
if (response.contains("```")) {
response = response.substring(0, response.lastIndexOf("```"));
}
} else {
// extract content from {} block
if (response.contains("{") && response.contains("}")) {
response = response.substring(response.indexOf("{"), response.lastIndexOf("}") + 1);

Check warning on line 526 in ml-algorithms/src/main/java/org/opensearch/ml/engine/algorithms/agent/MLPlanExecuteAndReflectAgentRunner.java

View check run for this annotation

Codecov / codecov/patch

ml-algorithms/src/main/java/org/opensearch/ml/engine/algorithms/agent/MLPlanExecuteAndReflectAgentRunner.java#L526

Added line #L526 was not covered by tests
}
}

response = response.trim();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,11 @@
try {
List<String> indexList = new ArrayList<>();
if (StringUtils.isNotBlank(parameters.get("index"))) {
indexList = gson.fromJson(parameters.get("index"), List.class);
try {
indexList = gson.fromJson(parameters.get("index"), List.class);
} catch (Exception e) {
indexList.add(parameters.get("index"));

Check warning on line 101 in ml-algorithms/src/main/java/org/opensearch/ml/engine/tools/IndexMappingTool.java

View check run for this annotation

Codecov / codecov/patch

ml-algorithms/src/main/java/org/opensearch/ml/engine/tools/IndexMappingTool.java#L100-L101

Added lines #L100 - L101 were not covered by tests
}
}

if (indexList.isEmpty()) {
Expand Down
Loading