-
Notifications
You must be signed in to change notification settings - Fork 30
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
[RFC] Add a new (PainlessScriptTool) as a generic tool #375
Comments
This is a valid problem but I have concern on using painless script. In ml-commons when remote inference initially supported, the process functions are in painless format, e.g. https://github.com/opensearch-project/ml-commons/blob/main/docs/remote_inference_blueprints/bedrock_connector_titan_multimodal_embedding_blueprint.md#2-create-connector-for-amazon-bedrock. Painless script has flexibility though it's difficult to read and maintain. So in later releases, more and more build-in process functions are added, e.g. |
Agree on this. As Painless script don't support json or xml/yml parsing, these parsing logic will in the tool itself and we can definitely have some built in parsers. This part will handled by // flatten parameters from previous tool
Map<String, Object> flattenedParameters = flattenMap(parameters); An example of json parse and flatten // ppl tool output
return '{\\"executionResult\\":\\"result\\",\\"ppl\\":\\"source=demo| head 1\\"}'
// after parse and flatten, flattenedParameters will have
// PPL.output.executionResult and PPL.output.ppl two entries. |
The tool's response will be parsed by build-in parsers first and then this painless script tool will be used as the final tool to build a final response to user? Do you have an example that painlessTool can be used as glue placed between two tools, the second tool consumes the results generated by the painlessTool? It seems the tool's response is included in the parameter map with key |
Here is one example for test purpose https://github.com/opensearch-project/skills/pull/380/files#diff-b36a3f988b4f9a022ca2be29cfa45a99ca309d0fc4cdf5a74245fef3968e6a7eR52-R79 |
the issue here is String key = getToolName(previousToolSpec);
String outputKey = key + ".output";
String outputResponse = parseResponse(output);
params.put(outputKey, escapeJson(outputResponse)); |
It seems the painlessTool is the |
I was thinking we can change the behavior in ml-commons, but it's fine if you think this is a different issue than current proposal to solve. But maybe we should consider where is a better place to put the parsers, skills or ml-commons. |
That could be options too, changes in ml-commons need to consider both flow/conversational agents |
Is your feature request related to a problem?
Nowadays, a single tool can typically produce only output of string type, which could be in various formats such as plain text, JSON, XML, and so on. With agent frameworks like Flow Agent, we can create pipelines that leverage the output of previous tools. However, this approach has some limitations.
For example, if tool A produces a JSON output like this:
{"key1":"value1","key2":"value2"}
and tool B wants to use only the key1 value, then tool B needs to have logic to parse the JSON object. This is not a generic solution, as each tool would need to have the necessary logic to adapt to the output format of the previous tool. Furthermore, the output format of the previous tool might change or be in a different format altogether, making it impractical to anticipate and handle all possible cases within the tools themselves.
To address these limitations, we need a generic tool that can handle string parsing and parameter processing, acting as a glue between the different tools in the pipeline. The PainlessScript tool, which leverages the built-in Painless scripting capabilities of OpenSearch, provides a solution. This tool allows you to pass scripts into it, making it a generic and adaptable component that can handle various input and output formats across the pipeline.
Here is the POC implementation
The text was updated successfully, but these errors were encountered: