From 8ea9749dfa8864ee75cc9ac950d082d197584543 Mon Sep 17 00:00:00 2001 From: Jiaping Zeng Date: Sun, 21 Sep 2025 22:57:21 -0700 Subject: [PATCH] add default bedrock converse interface Signed-off-by: Jiaping Zeng --- .../ml/engine/algorithms/agent/AgentUtils.java | 1 + .../function_calling/FunctionCallingFactory.java | 3 +++ .../ml/engine/algorithms/agent/AgentUtilsTest.java | 12 ++++++++++++ 3 files changed, 16 insertions(+) diff --git a/ml-algorithms/src/main/java/org/opensearch/ml/engine/algorithms/agent/AgentUtils.java b/ml-algorithms/src/main/java/org/opensearch/ml/engine/algorithms/agent/AgentUtils.java index 8f14f54478..2a1a8d7cd8 100644 --- a/ml-algorithms/src/main/java/org/opensearch/ml/engine/algorithms/agent/AgentUtils.java +++ b/ml-algorithms/src/main/java/org/opensearch/ml/engine/algorithms/agent/AgentUtils.java @@ -111,6 +111,7 @@ public class AgentUtils { public static final String LLM_RESPONSE_FILTER = "llm_response_filter"; public static final String TOOL_RESULT = "tool_result"; public static final String TOOL_CALL_ID = "tool_call_id"; + public static final String LLM_INTERFACE_BEDROCK_CONVERSE = "bedrock/converse"; public static final String LLM_INTERFACE_BEDROCK_CONVERSE_CLAUDE = "bedrock/converse/claude"; public static final String LLM_INTERFACE_OPENAI_V1_CHAT_COMPLETIONS = "openai/v1/chat/completions"; public static final String LLM_INTERFACE_BEDROCK_CONVERSE_DEEPSEEK_R1 = "bedrock/converse/deepseek_r1"; diff --git a/ml-algorithms/src/main/java/org/opensearch/ml/engine/function_calling/FunctionCallingFactory.java b/ml-algorithms/src/main/java/org/opensearch/ml/engine/function_calling/FunctionCallingFactory.java index 49a2a45262..0385fcba4b 100644 --- a/ml-algorithms/src/main/java/org/opensearch/ml/engine/function_calling/FunctionCallingFactory.java +++ b/ml-algorithms/src/main/java/org/opensearch/ml/engine/function_calling/FunctionCallingFactory.java @@ -5,6 +5,7 @@ package org.opensearch.ml.engine.function_calling; +import static org.opensearch.ml.engine.algorithms.agent.AgentUtils.LLM_INTERFACE_BEDROCK_CONVERSE; import static org.opensearch.ml.engine.algorithms.agent.AgentUtils.LLM_INTERFACE_BEDROCK_CONVERSE_CLAUDE; import static org.opensearch.ml.engine.algorithms.agent.AgentUtils.LLM_INTERFACE_BEDROCK_CONVERSE_DEEPSEEK_R1; import static org.opensearch.ml.engine.algorithms.agent.AgentUtils.LLM_INTERFACE_OPENAI_V1_CHAT_COMPLETIONS; @@ -21,6 +22,8 @@ public static FunctionCalling create(String llmInterface) { } switch (llmInterface.trim().toLowerCase(Locale.ROOT)) { + case LLM_INTERFACE_BEDROCK_CONVERSE: + return new BedrockConverseFunctionCalling(); case LLM_INTERFACE_BEDROCK_CONVERSE_CLAUDE: return new BedrockConverseFunctionCalling(); case LLM_INTERFACE_OPENAI_V1_CHAT_COMPLETIONS: diff --git a/ml-algorithms/src/test/java/org/opensearch/ml/engine/algorithms/agent/AgentUtilsTest.java b/ml-algorithms/src/test/java/org/opensearch/ml/engine/algorithms/agent/AgentUtilsTest.java index d0f66e2df6..4374d6f4b9 100644 --- a/ml-algorithms/src/test/java/org/opensearch/ml/engine/algorithms/agent/AgentUtilsTest.java +++ b/ml-algorithms/src/test/java/org/opensearch/ml/engine/algorithms/agent/AgentUtilsTest.java @@ -21,6 +21,7 @@ import static org.opensearch.ml.engine.algorithms.agent.AgentUtils.LLM_FINISH_REASON_PATH; import static org.opensearch.ml.engine.algorithms.agent.AgentUtils.LLM_FINISH_REASON_TOOL_USE; import static org.opensearch.ml.engine.algorithms.agent.AgentUtils.LLM_GEN_INPUT; +import static org.opensearch.ml.engine.algorithms.agent.AgentUtils.LLM_INTERFACE_BEDROCK_CONVERSE; import static org.opensearch.ml.engine.algorithms.agent.AgentUtils.LLM_INTERFACE_BEDROCK_CONVERSE_CLAUDE; import static org.opensearch.ml.engine.algorithms.agent.AgentUtils.LLM_RESPONSE_EXCLUDE_PATH; import static org.opensearch.ml.engine.algorithms.agent.AgentUtils.LLM_RESPONSE_FILTER; @@ -1898,4 +1899,15 @@ public void testParseLLMOutput_PathNotFoundExceptionWithEmptyToolCalls() { Assert.assertTrue(output.containsKey(FINAL_ANSWER)); Assert.assertTrue(output.get(FINAL_ANSWER).contains("[]")); } + + @Test + public void testFunctionCallingFactory_BedrockConverseInterface() { + FunctionCalling genericFunctionCalling = FunctionCallingFactory.create(LLM_INTERFACE_BEDROCK_CONVERSE); + FunctionCalling specificFunctionCalling = FunctionCallingFactory.create(LLM_INTERFACE_BEDROCK_CONVERSE_CLAUDE); + + Assert.assertNotNull("Generic bedrock/converse interface should create function calling instance", genericFunctionCalling); + Assert.assertNotNull("Specific bedrock/converse/claude interface should create function calling instance", specificFunctionCalling); + Assert.assertEquals("Both interfaces should return the same type", + genericFunctionCalling.getClass(), specificFunctionCalling.getClass()); + } }