From 203513da039a0d9c6c4037aee17260aa85e45466 Mon Sep 17 00:00:00 2001 From: yuye-aws Date: Sat, 14 Sep 2024 17:55:43 +0800 Subject: [PATCH 1/4] add sample template for create alert agent Signed-off-by: yuye-aws --- .../create-knowledge-base-alert-agent.json | 0 .../create-knowledge-base-alert-agent.yml | 110 ++++++++++++++++++ 2 files changed, 110 insertions(+) create mode 100644 sample-templates/create-knowledge-base-alert-agent.json create mode 100644 sample-templates/create-knowledge-base-alert-agent.yml diff --git a/sample-templates/create-knowledge-base-alert-agent.json b/sample-templates/create-knowledge-base-alert-agent.json new file mode 100644 index 000000000..e69de29bb diff --git a/sample-templates/create-knowledge-base-alert-agent.yml b/sample-templates/create-knowledge-base-alert-agent.yml new file mode 100644 index 000000000..e91e17a7a --- /dev/null +++ b/sample-templates/create-knowledge-base-alert-agent.yml @@ -0,0 +1,110 @@ +--- +name: Olly II Agents +description: 'This template is to create all Agents required for olly II features ' +use_case: REGISTER_AGENTS +version: + template: 1.0.0 + compatibility: + - 2.15.0 + - 3.0.0 +workflows: + provision: + user_params: {} + nodes: + - id: create_claude_connector + type: create_connector + previous_node_inputs: {} + user_inputs: + credential: + access_key: PUT_YOUR_ACCESS_KEY_HERE + secret_key: PUT_YOUR_SECRET_KEY_HERE + parameters: + endpoint: bedrock-runtime.us-west-2.amazonaws.com + content_type: application/json + auth: Sig_V4 + max_tokens_to_sample: '8000' + service_name: bedrock + temperature: '0.0001' + response_filter: "$.content[0].text" + region: us-west-2 + anthropic_version: bedrock-2023-05-31 + version: '1' + name: Claude haiku runtime Connector + protocol: aws_sigv4 + description: The connector to BedRock service for claude model + actions: + - action_type: predict + method: POST + url: https://bedrock-runtime.us-west-2.amazonaws.com/model/anthropic.claude-3-haiku-20240307-v1:0/invoke + headers: + content-type: application/json + x-amz-content-sha256: required + request_body: '{"messages":[{"role":"user","content":[{"type":"text","text":"${parameters.prompt}"}]}],"anthropic_version":"${parameters.anthropic_version}","max_tokens":${parameters.max_tokens_to_sample}}' + - id: register_claude_model + type: register_remote_model + previous_node_inputs: + create_claude_connector: connector_id + user_inputs: + name: claude-haiku + function_name: remote + description: Claude model + deploy: 'true' + - id: create_knowledge_base_connector + type: create_connector + previous_node_inputs: {} + user_inputs: + name: 'Amazon Bedrock Connector: knowledge base' + description: The connector to the Bedrock knowledge base + version: '1' + protocol: aws_sigv4 + parameters: + region: us-west-2 + service_name: bedrock + knowledgeBaseId: PUT_YOUR_KNOWLEDGE_BASE_I_HERE + model_arn: arn:aws:bedrock:us-west-2::foundation-model/anthropic.claude-3-sonnet-20240229-v1:0 + credential: + access_key: PUT_YOUR_ACCESS_KEY_HERE + secret_key: PUT_YOUR_SECRET_KEY_HERE + actions: + - action_type: predict + method: POST + url: https://bedrock-agent-runtime.us-west-2.amazonaws.com/retrieveAndGenerate + headers: + content-type: application/json + request_body: '{"input": {"text": "${parameters.text}"}, "retrieveAndGenerateConfiguration": + {"type": "KNOWLEDGE_BASE", "knowledgeBaseConfiguration": {"knowledgeBaseId": + "${parameters.knowledgeBaseId}", "modelArn": "${parameters.model_arn}"}}}' + post_process_function: return params.output.text; + - id: register_knowledge_base_model + type: register_remote_model + previous_node_inputs: + create_knowledge_base_connector: connector_id + user_inputs: + name: Claude model on bedrock + function_name: remote + version: 1.0.0 + description: Claude model on bedrock + deploy: 'true' + - id: create_kb_ml_model_tool + type: create_tool + previous_node_inputs: + register_knowledge_base_model: model_id + user_inputs: + parameters: + text: |- + You are an OpenSearch Alert Assistant to provide your insight on this alert to help users understand the alert, find potential causes and give feasible solutions to address it. + Here is the detail of alert: ${parameters.context}; + The alert summary is: ${parameters.summary}; + The question is: ${parameters.question}. + name: MLModelTool + type: MLModelTool + - id: create_knowledge_base_agent + type: register_agent + previous_node_inputs: + create_kb_ml_model_tool: tools + user_inputs: + parameters: {} + type: flow + name: Bedrock knowledge base agent + description: this is an agent to call retrieveAndGenerate API in bedrock knowledge + base suggestion agent From 40f63b94af90ebdfbfd938d30f2057fb2ec7a043 Mon Sep 17 00:00:00 2001 From: yuye-aws Date: Sat, 14 Sep 2024 18:07:30 +0800 Subject: [PATCH 2/4] add description Signed-off-by: yuye-aws --- .../create-knowledge-base-alert-agent.json | 93 +++++++++++++++++++ .../create-knowledge-base-alert-agent.yml | 52 +++-------- 2 files changed, 106 insertions(+), 39 deletions(-) diff --git a/sample-templates/create-knowledge-base-alert-agent.json b/sample-templates/create-knowledge-base-alert-agent.json index e69de29bb..da0f60c40 100644 --- a/sample-templates/create-knowledge-base-alert-agent.json +++ b/sample-templates/create-knowledge-base-alert-agent.json @@ -0,0 +1,93 @@ +{ + "name": "Olly II Agents", + "description": "This template is to create all Agents required for olly II features ", + "use_case": "REGISTER_AGENTS", + "version": { + "template": "1.0.0", + "compatibility": [ + "2.15.0", + "3.0.0" + ] + }, + "workflows": { + "provision": { + "user_params": {}, + "nodes": [ + { + "id": "create_knowledge_base_connector", + "type": "create_connector", + "previous_node_inputs": {}, + "user_inputs": { + "name": "Amazon Bedrock Connector: knowledge base", + "description": "The connector to the Bedrock knowledge base", + "version": "1", + "protocol": "aws_sigv4", + "parameters": { + "region": "us-west-2", + "service_name": "bedrock", + "knowledgeBaseId": "PUT_YOUR_KNOWLEDGE_BASE_ID_HERE", + "model_arn": "arn:aws:bedrock:us-west-2::foundation-model/anthropic.claude-3-sonnet-20240229-v1:0" + }, + "credential": { + "access_key": "PUT_YOUR_ACCESS_KEY_HERE", + "secret_key": "PUT_YOUR_SECRET_KEY_HERE" + }, + "actions": [ + { + "action_type": "predict", + "method": "POST", + "url": "https://bedrock-agent-runtime.us-west-2.amazonaws.com/retrieveAndGenerate", + "headers": { + "content-type": "application/json" + }, + "request_body": "{\"input\": {\"text\": \"${parameters.text}\"}, \"retrieveAndGenerateConfiguration\": {\"type\": \"KNOWLEDGE_BASE\", \"knowledgeBaseConfiguration\": {\"knowledgeBaseId\": \"${parameters.knowledgeBaseId}\", \"modelArn\": \"${parameters.model_arn}\"}}}", + "post_process_function": "return params.output.text;" + } + ] + } + }, + { + "id": "register_knowledge_base_model", + "type": "register_remote_model", + "previous_node_inputs": { + "create_knowledge_base_connector": "connector_id" + }, + "user_inputs": { + "name": "Claude model on bedrock", + "function_name": "remote", + "version": "1.0.0", + "description": "Claude model on bedrock", + "deploy": "true" + } + }, + { + "id": "create_kb_ml_model_tool", + "type": "create_tool", + "previous_node_inputs": { + "register_knowledge_base_model": "model_id" + }, + "user_inputs": { + "parameters": { + "text": "You are an OpenSearch Alert Assistant to provide your insight on this alert to help users understand the alert, find potential causes and give feasible solutions to address it.\n Here is the detail of alert: ${parameters.context};\n The alert summary is: ${parameters.summary};\n The question is: ${parameters.question}." + }, + "name": "MLModelTool", + "type": "MLModelTool" + } + }, + { + "id": "create_knowledge_base_agent", + "type": "register_agent", + "previous_node_inputs": { + "create_kb_ml_model_tool": "tools" + }, + "user_inputs": { + "parameters": {}, + "type": "flow", + "name": "Bedrock knowledge base agent", + "description": "this is an agent to call retrieveAndGenerate API in bedrock knowledge base suggestion agent" + } + } + ] + } + } +} diff --git a/sample-templates/create-knowledge-base-alert-agent.yml b/sample-templates/create-knowledge-base-alert-agent.yml index e91e17a7a..d7dba5acf 100644 --- a/sample-templates/create-knowledge-base-alert-agent.yml +++ b/sample-templates/create-knowledge-base-alert-agent.yml @@ -1,3 +1,14 @@ +# This template creates a connector to the BedRock service for Knowledge base +# It then registers a model using the connector and deploys it. +# Finally, it creates a flow agent base agent with ML Model tool to access the knowledge base. +# +# To use: +# - update the "credential" and "knowledgeBaseId" fields under the create_knowledge_base_connector node. +# - if needed, update region +# +# After provisioning: +# - returns a workflow ID +# - use the status API to get the deployed agent ID --- name: Olly II Agents description: 'This template is to create all Agents required for olly II features ' @@ -11,44 +22,6 @@ workflows: provision: user_params: {} nodes: - - id: create_claude_connector - type: create_connector - previous_node_inputs: {} - user_inputs: - credential: - access_key: PUT_YOUR_ACCESS_KEY_HERE - secret_key: PUT_YOUR_SECRET_KEY_HERE - parameters: - endpoint: bedrock-runtime.us-west-2.amazonaws.com - content_type: application/json - auth: Sig_V4 - max_tokens_to_sample: '8000' - service_name: bedrock - temperature: '0.0001' - response_filter: "$.content[0].text" - region: us-west-2 - anthropic_version: bedrock-2023-05-31 - version: '1' - name: Claude haiku runtime Connector - protocol: aws_sigv4 - description: The connector to BedRock service for claude model - actions: - - action_type: predict - method: POST - url: https://bedrock-runtime.us-west-2.amazonaws.com/model/anthropic.claude-3-haiku-20240307-v1:0/invoke - headers: - content-type: application/json - x-amz-content-sha256: required - request_body: '{"messages":[{"role":"user","content":[{"type":"text","text":"${parameters.prompt}"}]}],"anthropic_version":"${parameters.anthropic_version}","max_tokens":${parameters.max_tokens_to_sample}}' - - id: register_claude_model - type: register_remote_model - previous_node_inputs: - create_claude_connector: connector_id - user_inputs: - name: claude-haiku - function_name: remote - description: Claude model - deploy: 'true' - id: create_knowledge_base_connector type: create_connector previous_node_inputs: {} @@ -60,7 +33,7 @@ workflows: parameters: region: us-west-2 service_name: bedrock - knowledgeBaseId: PUT_YOUR_KNOWLEDGE_BASE_I_HERE + knowledgeBaseId: PUT_YOUR_KNOWLEDGE_BASE_ID_HERE model_arn: arn:aws:bedrock:us-west-2::foundation-model/anthropic.claude-3-sonnet-20240229-v1:0 credential: access_key: PUT_YOUR_ACCESS_KEY_HERE @@ -108,3 +81,4 @@ workflows: name: Bedrock knowledge base agent description: this is an agent to call retrieveAndGenerate API in bedrock knowledge base suggestion agent + From 7db21cc4f2378d6dd80f5ecb6a29dba52399d3a3 Mon Sep 17 00:00:00 2001 From: yuye-aws Date: Sat, 14 Sep 2024 18:10:09 +0800 Subject: [PATCH 3/4] spotless apply Signed-off-by: yuye-aws --- sample-templates/create-knowledge-base-alert-agent.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/sample-templates/create-knowledge-base-alert-agent.yml b/sample-templates/create-knowledge-base-alert-agent.yml index d7dba5acf..e4126cd70 100644 --- a/sample-templates/create-knowledge-base-alert-agent.yml +++ b/sample-templates/create-knowledge-base-alert-agent.yml @@ -81,4 +81,3 @@ workflows: name: Bedrock knowledge base agent description: this is an agent to call retrieveAndGenerate API in bedrock knowledge base suggestion agent - From f1207bb96fc97771974d2f1aa0321ff4484b2283 Mon Sep 17 00:00:00 2001 From: yuye-aws Date: Sat, 14 Sep 2024 18:11:16 +0800 Subject: [PATCH 4/4] update changelog Signed-off-by: yuye-aws --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9e734dbf2..95d8edaaa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.1.0/) ### Bug Fixes ### Infrastructure - Set Java target compatibility to JDK 21 ([#730](https://github.com/opensearch-project/flow-framework/pull/730)) +- Add knowledge base alert agent into sample templates ([#874](https://github.com/opensearch-project/flow-framework/pull/874)) ### Documentation ### Maintenance