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 CreateAlertTool #349

Merged
merged 12 commits into from
Aug 1, 2024
Merged

Conversation

qianheng-aws
Copy link
Contributor

@qianheng-aws qianheng-aws commented Jul 12, 2024

Description

Implementing CreateAlertTool, which aims to help create alert with natural language. The tool has 3 input parameters:

  • question: user's question about creating a new alert
  • indices: The input indices of the monitor.
  • chat_history: optional, the chat history of chatbot. This is helpful when creating alert as a follow-up question in conversation.

This tool is able to request LLM by itself and has its own tool prompt, and it can also get some necessary information by calling OS API.

When this tool is selected by chat agent or invoked by flow agent, it will be executed as following steps:

  • get the mapping info of the input indices
  • construct its final tool prompt by substitute the placeholders(e.g. question, indices, chat_history, mapping_info) in its raw prompt
  • request LLM with the final prompt and got response
  • extract the alert configuration from the LLM response as its output.

The tool output format may be like:

Tool output:
{
    "name": "Error 500 Response Alert",
    "search": {
        "indices": ["opensearch_dashboards_sample_data_logs"],
        "timeField": "timestamp",
        "bucketValue": 60,
        "bucketUnitOfTime": "m",
        "filters": [
            {
                "fieldName": [
                    {
                        "label": "response",
                        "type": "text"
                    }
                ],
                "fieldValue": "500",
                "operator": "is"
            }
        ],
        "aggregations": [
            {
                "aggregationType": "count",
                "fieldName": "bytes"
            }
        ]
    },
    "triggers": [
        {
            "name": "Error 500 Response Count Above 1",
            "severity": 1,
            "thresholdValue": 1,
            "thresholdEnum": "ABOVE"
        }
    ]
}

Note: it relies on ChatAgentRunner to pass chat_history to this tool, so it needs to add a new method in Tool interface and override it, as explained in this issue #2645

There is a demo video about creating an alert by LLM: https://broadcast.amazon.com/videos/1159580

Related Issues

Resolves #[338]

Has dependency on this issue in ml-commons repo: #2645

Check List

  • New functionality includes testing.
  • New functionality has been documented.
  • API changes companion pull request created.
  • Commits are signed per the DCO using --signoff.
  • Public documentation issue/PR created.

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.

@zane-neo
Copy link
Collaborator

@qianheng-aws please run ./gradlew spotlessApply to format code

Signed-off-by: Heng Qian <[email protected]>
Signed-off-by: Heng Qian <[email protected]>
Signed-off-by: Heng Qian <[email protected]>
Signed-off-by: Heng Qian <[email protected]>
@xinyual xinyual merged commit 798065f into opensearch-project:main Aug 1, 2024
8 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-349-to-2.x
# Cherry-pick the merged commit of this pull request and resolve the conflicts
git cherry-pick -x --mainline 1 798065f7e945b0569c89d003776c147dc6722723
# Push it to GitHub
git push --set-upstream origin backport/backport-349-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-349-to-2.x.

qianheng-aws added a commit to qianheng-aws/skills that referenced this pull request Oct 31, 2024
* add CreateAlertTool

Signed-off-by: Heng Qian <[email protected]>

* spotlessApply and address comments

Signed-off-by: Heng Qian <[email protected]>

* add IT for CreateAlertTool

Signed-off-by: Heng Qian <[email protected]>

* address comments

Signed-off-by: Heng Qian <[email protected]>

* fix after merging main

Signed-off-by: Heng Qian <[email protected]>

* fix forbidden API

Signed-off-by: Heng Qian <[email protected]>

* fix IT failure

Signed-off-by: Heng Qian <[email protected]>

* run spotlessCheck

Signed-off-by: Heng Qian <[email protected]>

* Address comments

Signed-off-by: Heng Qian <[email protected]>

* Address comments of changing getIndex to use ActionListener

Signed-off-by: Heng Qian <[email protected]>

* fix IT

Signed-off-by: Heng Qian <[email protected]>

* make prompt dict static

Signed-off-by: Heng Qian <[email protected]>

---------

Signed-off-by: Heng Qian <[email protected]>
qianheng-aws added a commit to qianheng-aws/skills that referenced this pull request Oct 31, 2024
* add CreateAlertTool

Signed-off-by: Heng Qian <[email protected]>

* spotlessApply and address comments

Signed-off-by: Heng Qian <[email protected]>

* add IT for CreateAlertTool

Signed-off-by: Heng Qian <[email protected]>

* address comments

Signed-off-by: Heng Qian <[email protected]>

* fix after merging main

Signed-off-by: Heng Qian <[email protected]>

* fix forbidden API

Signed-off-by: Heng Qian <[email protected]>

* fix IT failure

Signed-off-by: Heng Qian <[email protected]>

* run spotlessCheck

Signed-off-by: Heng Qian <[email protected]>

* Address comments

Signed-off-by: Heng Qian <[email protected]>

* Address comments of changing getIndex to use ActionListener

Signed-off-by: Heng Qian <[email protected]>

* fix IT

Signed-off-by: Heng Qian <[email protected]>

* make prompt dict static

Signed-off-by: Heng Qian <[email protected]>

---------

Signed-off-by: Heng Qian <[email protected]>
zane-neo added a commit that referenced this pull request Nov 14, 2024
* add CreateAlertTool (#349)

* add CreateAlertTool

Signed-off-by: Heng Qian <[email protected]>

* spotlessApply and address comments

Signed-off-by: Heng Qian <[email protected]>

* add IT for CreateAlertTool

Signed-off-by: Heng Qian <[email protected]>

* address comments

Signed-off-by: Heng Qian <[email protected]>

* fix after merging main

Signed-off-by: Heng Qian <[email protected]>

* fix forbidden API

Signed-off-by: Heng Qian <[email protected]>

* fix IT failure

Signed-off-by: Heng Qian <[email protected]>

* run spotlessCheck

Signed-off-by: Heng Qian <[email protected]>

* Address comments

Signed-off-by: Heng Qian <[email protected]>

* Address comments of changing getIndex to use ActionListener

Signed-off-by: Heng Qian <[email protected]>

* fix IT

Signed-off-by: Heng Qian <[email protected]>

* make prompt dict static

Signed-off-by: Heng Qian <[email protected]>

---------

Signed-off-by: Heng Qian <[email protected]>

* Fix gradle task forbiddenApisMain failure (#391)

* Fix gradle task forbiddenApisMain failure

Signed-off-by: zane-neo <[email protected]>

* fix compilation error since AD change

Signed-off-by: zane-neo <[email protected]>

---------

Signed-off-by: zane-neo <[email protected]>

(cherry picked from commit 3e63a62)
Signed-off-by: Heng Qian <[email protected]>

---------

Signed-off-by: Heng Qian <[email protected]>
Signed-off-by: zane-neo <[email protected]>
Co-authored-by: zane-neo <[email protected]>
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