Skip to content

Conversation

@ylwu-amzn
Copy link
Collaborator

@ylwu-amzn ylwu-amzn commented Nov 18, 2025

Description

Current connector only support finding by action type. This PR add support to run connector by connector name. Connector can have multiple actions with same type, but different name. And we can run one of the actions by specifying action name.

Related Issues

Resolves #[Issue number to be closed when this PR is merged]

Test result

1. Unit test

./gradlew test

BUILD SUCCESSFUL in 8m 23s
49 actionable tasks: 47 executed, 2 up-to-date

2. Test on local 3.4 cluster

Create connector

POST /_plugins/_ml/connectors/_create
{
  "name": "Amazon Bedrock Converse",
  "description": "Test connector for Amazon Converse",
  "version": 1,
  "protocol": "aws_sigv4",
  "credential": {
    "access_key": "{{access_key}}",
    "secret_key": "{{secret_key}}",
    "session_token": "{{session_token}}"
  },
  "parameters": {
    "region": "{{region}}",
    "service_name": "bedrock",
    "model": "us.anthropic.claude-3-7-sonnet-20250219-v1:0"
  },
  "actions": [
    {
      "name": "test_execute1",
      "action_type": "execute",
      "method": "POST",
      "headers": {
        "content-type": "application/json"
      },
      "url": "https://bedrock-runtime.${parameters.region}.amazonaws.com/model/${parameters.model}/converse",
      "request_body": "${parameters.input}"
    },
    {
      "name": "test_execute2",
      "action_type": "execute",
      "method": "POST",
      "headers": {
        "content-type": "application/json"
      },
      "url": "https://bedrock-runtime.${parameters.region}.amazonaws.com/model/${parameters.model}/converse",
      "request_body": "{\"system\":[{\"text\": \"${parameters.system_prompt}\"}], \"messages\":[{\"role\":\"user\",\"content\":[{\"type\":\"text\",\"text\":\"${parameters.user_prompt}\"}]}]}"
    }
  ]
}

Run connector tool

POST _plugins/_ml/tools/_execute/ConnectorTool
{
  "parameters": {
    "connector_id": "D8V9mJoBCbNgW80ENod1",
    "connector_action": "test_execute1",
    "input": {
      "system": [
        {
          "text": "You are a helpful assistant."
        }
      ],
      "messages": [
        {
          "role": "user",
          "content": [
            {
              "type": "text",
              "text": "hello"
            }
          ]
        }
      ]
    }
  }
}
POST _plugins/_ml/tools/_execute/ConnectorTool
{
  "parameters": {
    "connector_id": "D8V9mJoBCbNgW80ENod1",
    "connector_action": "test_execute2",
    "system_prompt": "You are a helpful assistant.",
    "user_prompt": "hello"
  }
}

Response

{
  "inference_results": [
    {
      "output": [
        {
          "name": "response",
          "dataAsMap": {
            "metrics": {
              "latencyMs": 1264.0
            },
            "output": {
              "message": {
                "content": [
                  {
                    "text": "Hello! How can I help you today? Whether you have a question, need information, or just want to chat, I'm here to assist. What's on your mind?"
                  }
                ],
                "role": "assistant"
              }
            },
            "stopReason": "end_turn",
            "usage": {
              "cacheReadInputTokenCount": 0.0,
              "cacheReadInputTokens": 0.0,
              "cacheWriteInputTokenCount": 0.0,
              "cacheWriteInputTokens": 0.0,
              "inputTokens": 14.0,
              "outputTokens": 39.0,
              "serverToolUsage": {},
              "totalTokens": 53.0
            }
          }
        }
      ]
    }
  ]
}

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.

if (method == null) {
throw new IllegalArgumentException("method can't be null");
}
if (name != null && ActionType.isValidAction(name)) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we add a comment what is this name for and also why are we checking name not to be an action?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done

Signed-off-by: Yaliang Wu <[email protected]>
@ylwu-amzn ylwu-amzn merged commit 285b6e2 into opensearch-project:feature/3.4-release-prep Nov 18, 2025
5 of 9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants