-
Notifications
You must be signed in to change notification settings - Fork 186
Fix tool used error message not proper escaped in MLChatAgentRunner #4410
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
base: main
Are you sure you want to change the base?
Fix tool used error message not proper escaped in MLChatAgentRunner #4410
Conversation
Signed-off-by: Mingshi Liu <[email protected]>
| Assert.assertTrue(result.containsKey(AgentUtils.TOOL_RESPONSE)); | ||
| } | ||
|
|
||
| @Test |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These tests well suit to the test class StringUtilsTest. Basically these are testing the API StringUtils.processTextDoc(p with different inputs. Nothing doing with APIs in MLChatAgentRunner.
| TOOL_CALL_ID, | ||
| toolCallId, | ||
| "tool_response", | ||
| "Tool " + action + " failed: " + StringUtils.processTextDoc(e.getMessage()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here StringUtils class name is not required. Static import of processTextDoc API is there . "import static org.opensearch.ml.common.utils.StringUtils.processTextDoc;"
| substitute( | ||
| tmpParameters.get(INTERACTION_TEMPLATE_TOOL_RESPONSE), | ||
| Map.of(TOOL_CALL_ID, toolCallId, "tool_response", "Tool " + action + " failed: " + e.getMessage()), | ||
| Map |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need to fix other agent runners?
|
Can you rebase with current main? |
Description
Fixes JSON parsing errors in ML agent error handling by properly escaping special characters in exception messages using
StringUtils.processTextDoc().What is the problem?
When ML agents encounter tool execution failures with complex error messages (containing newlines, quotes, etc.), the unescaped exception text breaks JSON structure in agent responses, causing parsing failures like:
Expected BEGIN_ARRAY but was STRING at line 1 column 1 path $
How does this PR solve it?
e.getMessage()withStringUtils.processTextDoc()inMLChatAgentRunner.javaline 628Testing
Added unit tests in
MLChatAgentRunnerTest.javato verify:Check List
--signoff.By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.