Skip to content
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

add previous key for PPL tool #131

Merged
merged 13 commits into from
Feb 5, 2024

Conversation

xinyual
Copy link
Collaborator

@xinyual xinyual commented Jan 16, 2024

Description

add previous key for PPL tool, so we can extract content from previous tool output.
request body would be like:

{
      "type": "CatIndexTool",
      "name": "CatIndexTool2",
      "description": "Use this tool to get OpenSearch index information: (health, status, index, uuid, primary count, replica count, docs.count, docs.deleted, store.size, primary.store.size). Also, use this to get all index name. You should always use this tool when you are asked questions about indices number."
    },
      {
      "type": "PPLTool",
      "name": "TransferQuestionToPPLAndExecuteTool",
      "description": "Use this tool to transfer natural language to generate PPL and execute PPL to query inside. Use this tool after you know the index name, otherwise, call IndexRoutingTool first. The input parameters are: {index:IndexName, question:UserQuestion}",
      "parameters": {
        "model_id": "PrlMEI0BavJyXuD79Loi",
        "model_type": "CLAUDE",
        "previous_tool_name": "CatIndexTool3",
        "response_filter": "$.completion"
      }
    }
 

The previous_tool_name should be name of previous tool

Issues Resolved

add previous key for PPL tool, so we can extract content from previous tool output.

Check List

  • New functionality includes testing.
    • All tests pass
  • New functionality has been documented.
    • New functionality has javadoc added
  • Commits are signed per the DCO using --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.

Signed-off-by: xinyual <xinyual@amazon.com>
Signed-off-by: xinyual <xinyual@amazon.com>
Copy link

codecov bot commented Jan 16, 2024

Codecov Report

Attention: 3 lines in your changes are missing coverage. Please review.

Comparison is base (940ac32) 81.75% compared to head (91fd51f) 81.76%.
Report is 1 commits behind head on main.

Files Patch % Lines
.../main/java/org/opensearch/agent/tools/PPLTool.java 85.71% 1 Missing and 2 partials ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##               main     #131      +/-   ##
============================================
+ Coverage     81.75%   81.76%   +0.01%     
- Complexity      197      201       +4     
============================================
  Files            13       13              
  Lines          1003     1042      +39     
  Branches        132      139       +7     
============================================
+ Hits            820      852      +32     
- Misses          133      136       +3     
- Partials         50       54       +4     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Signed-off-by: xinyual <xinyual@amazon.com>
if (parameters.containsKey("index")) {
indexName = parameters.get("index");
} else if (!StringUtils.isBlank(this.previousToolKey) && parameters.containsKey(this.previousToolKey + ".output")) {
indexName = parameters.get(this.previousToolKey + ".output"); // read index name from previous key
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we handle 'Not sure' here ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok. Once the index routing pr is merged I will check whether the index is equal to NOT_SURE and then throw an exception if it is.

@zane-neo
Copy link
Collaborator

This should work for PPLTool case, but I'm thinking of creating a systematically approach to deal with the tool results passing through the agent execute flow, e.g. a map contains all tool's result with iteration number. That would need bigger effort but that should be the correct direction. Please evaluate the effort and better creating a design doc to involve broader audience.

Signed-off-by: xinyual <xinyual@amazon.com>
Signed-off-by: xinyual <xinyual@amazon.com>
Signed-off-by: xinyual <xinyual@amazon.com>
Signed-off-by: xinyual <xinyual@amazon.com>
Signed-off-by: xinyual <xinyual@amazon.com>
Signed-off-by: xinyual <xinyual@amazon.com>
Signed-off-by: xinyual <xinyual@amazon.com>
@@ -213,7 +222,17 @@ public <T> void run(Map<String, String> parameters, ActionListener<T> listener)
));
}, e -> {
log.info("fail to get mapping: " + e);
listener.onFailure(e);
String error_message = e.getMessage();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please use camel naming convention for variables

Signed-off-by: xinyual <xinyual@amazon.com>
Signed-off-by: xinyual <xinyual@amazon.com>
Comment on lines 455 to 456
String indexName = "";
indexName = parameters.getOrDefault("index", "");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This two line can be merged together

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Already changed

Signed-off-by: xinyual <xinyual@amazon.com>
@zane-neo zane-neo merged commit c2a1fed into opensearch-project:main Feb 5, 2024
14 checks passed
@opensearch-trigger-bot
Copy link
Contributor

The backport to 2.x failed:

The process '/usr/bin/git' failed with exit code 128

To backport manually, run these commands in your terminal:

# Navigate to the root of your repository
cd $(git rev-parse --show-toplevel)
# Fetch latest updates from GitHub
git fetch
# Create a new working tree
git worktree add ../.worktrees/skills/backport-2.x 2.x
# Navigate to the new working tree
pushd ../.worktrees/skills/backport-2.x
# Create a new branch
git switch --create backport/backport-131-to-2.x
# Cherry-pick the merged commit of this pull request and resolve the conflicts
git cherry-pick -x --mainline 1 c2a1fedd0a70959c6375a30df6e823989d74c295
# Push it to GitHub
git push --set-upstream origin backport/backport-131-to-2.x
# Go back to the original working tree
popd
# Delete the working tree
git worktree remove ../.worktrees/skills/backport-2.x

Then, create a pull request where the base branch is 2.x and the compare/head branch is backport/backport-131-to-2.x.

xinyual added a commit to xinyual/skills that referenced this pull request Feb 5, 2024
Signed-off-by: xinyual <xinyual@amazon.com>
@xinyual xinyual mentioned this pull request Feb 5, 2024
5 tasks
xinyual added a commit to xinyual/skills that referenced this pull request Feb 5, 2024
Signed-off-by: xinyual <xinyual@amazon.com>
xinyual added a commit to xinyual/skills that referenced this pull request Feb 5, 2024
Signed-off-by: xinyual <xinyual@amazon.com>
zhichao-aws pushed a commit that referenced this pull request Feb 5, 2024
* backport from #131

Signed-off-by: xinyual <xinyual@amazon.com>

* backport from #131

Signed-off-by: xinyual <xinyual@amazon.com>

* backport from #131

Signed-off-by: xinyual <xinyual@amazon.com>

---------

Signed-off-by: xinyual <xinyual@amazon.com>
yuye-aws pushed a commit to yuye-aws/skills that referenced this pull request Apr 26, 2024
* backport from opensearch-project#131

Signed-off-by: xinyual <xinyual@amazon.com>

* backport from opensearch-project#131

Signed-off-by: xinyual <xinyual@amazon.com>

* backport from opensearch-project#131

Signed-off-by: xinyual <xinyual@amazon.com>

---------

Signed-off-by: xinyual <xinyual@amazon.com>
Signed-off-by: yuye-aws <yuyezhu@amazon.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants