This is an automated email from the ASF dual-hosted git repository. xtsong pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/flink-agents.git
commit c96338862537b879bfe89e4a24513144dc2b7ace Author: youjin <[email protected]> AuthorDate: Fri Jan 23 16:06:18 2026 +0800 [refactor] unify Python class path into single pythonClazz parameter --- .../resource/test/ChatModelCrossLanguageAgent.java | 12 ++++++------ .../resource/test/EmbeddingCrossLanguageAgent.java | 10 ++++------ .../resource/test/VectorStoreCrossLanguageAgent.java | 15 ++++++--------- .../resourceprovider/PythonResourceProvider.java | 20 ++++++++++++++------ .../org/apache/flink/agents/plan/AgentPlanTest.java | 3 +-- 5 files changed, 31 insertions(+), 29 deletions(-) diff --git a/e2e-test/flink-agents-end-to-end-tests-resource-cross-language/src/test/java/org/apache/flink/agents/resource/test/ChatModelCrossLanguageAgent.java b/e2e-test/flink-agents-end-to-end-tests-resource-cross-language/src/test/java/org/apache/flink/agents/resource/test/ChatModelCrossLanguageAgent.java index f3f8374e..c5cd05e3 100644 --- a/e2e-test/flink-agents-end-to-end-tests-resource-cross-language/src/test/java/org/apache/flink/agents/resource/test/ChatModelCrossLanguageAgent.java +++ b/e2e-test/flink-agents-end-to-end-tests-resource-cross-language/src/test/java/org/apache/flink/agents/resource/test/ChatModelCrossLanguageAgent.java @@ -79,8 +79,8 @@ public class ChatModelCrossLanguageAgent extends Agent { public static ResourceDescriptor pythonChatModelConnection() { return ResourceDescriptor.Builder.newBuilder(PYTHON_CHAT_MODEL_CONNECTION) .addInitialArgument( - "module", "flink_agents.integrations.chat_models.ollama_chat_model") - .addInitialArgument("clazz", "OllamaChatModelConnection") + "pythonClazz", + "flink_agents.integrations.chat_models.ollama_chat_model.OllamaChatModelConnection") .build(); } @@ -88,8 +88,8 @@ public class ChatModelCrossLanguageAgent extends Agent { public static ResourceDescriptor temperatureChatModel() { return ResourceDescriptor.Builder.newBuilder(PYTHON_CHAT_MODEL_SETUP) .addInitialArgument( - "module", "flink_agents.integrations.chat_models.ollama_chat_model") - .addInitialArgument("clazz", "OllamaChatModelSetup") + "pythonClazz", + "flink_agents.integrations.chat_models.ollama_chat_model.OllamaChatModelSetup") .addInitialArgument("connection", "javaChatModelConnection") .addInitialArgument("model", OLLAMA_MODEL) .addInitialArgument("tools", List.of("convertTemperature")) @@ -101,8 +101,8 @@ public class ChatModelCrossLanguageAgent extends Agent { public static ResourceDescriptor chatModel() { return ResourceDescriptor.Builder.newBuilder(PYTHON_CHAT_MODEL_SETUP) .addInitialArgument( - "module", "flink_agents.integrations.chat_models.ollama_chat_model") - .addInitialArgument("clazz", "OllamaChatModelSetup") + "pythonClazz", + "flink_agents.integrations.chat_models.ollama_chat_model.OllamaChatModelSetup") .addInitialArgument("connection", "pythonChatModelConnection") .addInitialArgument("model", OLLAMA_MODEL) .addInitialArgument("tools", List.of("calculateBMI", "createRandomNumber")) diff --git a/e2e-test/flink-agents-end-to-end-tests-resource-cross-language/src/test/java/org/apache/flink/agents/resource/test/EmbeddingCrossLanguageAgent.java b/e2e-test/flink-agents-end-to-end-tests-resource-cross-language/src/test/java/org/apache/flink/agents/resource/test/EmbeddingCrossLanguageAgent.java index 98f53e39..cc533ff1 100644 --- a/e2e-test/flink-agents-end-to-end-tests-resource-cross-language/src/test/java/org/apache/flink/agents/resource/test/EmbeddingCrossLanguageAgent.java +++ b/e2e-test/flink-agents-end-to-end-tests-resource-cross-language/src/test/java/org/apache/flink/agents/resource/test/EmbeddingCrossLanguageAgent.java @@ -53,9 +53,8 @@ public class EmbeddingCrossLanguageAgent extends Agent { public static ResourceDescriptor embeddingConnection() { return ResourceDescriptor.Builder.newBuilder(PYTHON_EMBEDDING_MODEL_CONNECTION) .addInitialArgument( - "module", - "flink_agents.integrations.embedding_models.local.ollama_embedding_model") - .addInitialArgument("clazz", "OllamaEmbeddingModelConnection") + "pythonClazz", + "flink_agents.integrations.embedding_models.local.ollama_embedding_model.OllamaEmbeddingModelConnection") .build(); } @@ -63,9 +62,8 @@ public class EmbeddingCrossLanguageAgent extends Agent { public static ResourceDescriptor embeddingModel() { return ResourceDescriptor.Builder.newBuilder(PYTHON_EMBEDDING_MODEL_SETUP) .addInitialArgument( - "module", - "flink_agents.integrations.embedding_models.local.ollama_embedding_model") - .addInitialArgument("clazz", "OllamaEmbeddingModelSetup") + "pythonClazz", + "flink_agents.integrations.embedding_models.local.ollama_embedding_model.OllamaEmbeddingModelSetup") .addInitialArgument("connection", "embeddingConnection") .addInitialArgument("model", OLLAMA_MODEL) .build(); diff --git a/e2e-test/flink-agents-end-to-end-tests-resource-cross-language/src/test/java/org/apache/flink/agents/resource/test/VectorStoreCrossLanguageAgent.java b/e2e-test/flink-agents-end-to-end-tests-resource-cross-language/src/test/java/org/apache/flink/agents/resource/test/VectorStoreCrossLanguageAgent.java index 62410527..bdcca06e 100644 --- a/e2e-test/flink-agents-end-to-end-tests-resource-cross-language/src/test/java/org/apache/flink/agents/resource/test/VectorStoreCrossLanguageAgent.java +++ b/e2e-test/flink-agents-end-to-end-tests-resource-cross-language/src/test/java/org/apache/flink/agents/resource/test/VectorStoreCrossLanguageAgent.java @@ -67,9 +67,8 @@ public class VectorStoreCrossLanguageAgent extends Agent { if (System.getProperty("EMBEDDING_TYPE", "PYTHON").equals("PYTHON")) { return ResourceDescriptor.Builder.newBuilder(PYTHON_EMBEDDING_MODEL_CONNECTION) .addInitialArgument( - "module", - "flink_agents.integrations.embedding_models.local.ollama_embedding_model") - .addInitialArgument("clazz", "OllamaEmbeddingModelConnection") + "pythonClazz", + "flink_agents.integrations.embedding_models.local.ollama_embedding_model.OllamaEmbeddingModelConnection") .build(); } else { return ResourceDescriptor.Builder.newBuilder(OLLAMA_EMBEDDING_MODEL_CONNECTION) @@ -84,9 +83,8 @@ public class VectorStoreCrossLanguageAgent extends Agent { if (System.getProperty("EMBEDDING_TYPE", "PYTHON").equals("PYTHON")) { return ResourceDescriptor.Builder.newBuilder(PYTHON_EMBEDDING_MODEL_SETUP) .addInitialArgument( - "module", - "flink_agents.integrations.embedding_models.local.ollama_embedding_model") - .addInitialArgument("clazz", "OllamaEmbeddingModelSetup") + "pythonClazz", + "flink_agents.integrations.embedding_models.local.ollama_embedding_model.OllamaEmbeddingModelSetup") .addInitialArgument("connection", "embeddingConnection") .addInitialArgument("model", OLLAMA_MODEL) .build(); @@ -102,9 +100,8 @@ public class VectorStoreCrossLanguageAgent extends Agent { public static ResourceDescriptor vectorStore() { return ResourceDescriptor.Builder.newBuilder(PYTHON_COLLECTION_MANAGEABLE_VECTOR_STORE) .addInitialArgument( - "module", - "flink_agents.integrations.vector_stores.chroma.chroma_vector_store") - .addInitialArgument("clazz", "ChromaVectorStore") + "pythonClazz", + "flink_agents.integrations.vector_stores.chroma.chroma_vector_store.ChromaVectorStore") .addInitialArgument("embedding_model", "embeddingModel") .build(); } diff --git a/plan/src/main/java/org/apache/flink/agents/plan/resourceprovider/PythonResourceProvider.java b/plan/src/main/java/org/apache/flink/agents/plan/resourceprovider/PythonResourceProvider.java index ca87db9f..1f2c60e8 100644 --- a/plan/src/main/java/org/apache/flink/agents/plan/resourceprovider/PythonResourceProvider.java +++ b/plan/src/main/java/org/apache/flink/agents/plan/resourceprovider/PythonResourceProvider.java @@ -95,14 +95,22 @@ public class PythonResourceProvider extends ResourceProvider { // Extract module and class from kwargs if not provided in descriptor if (pyModule == null || pyModule.isEmpty()) { - pyModule = (String) kwargs.remove("module"); - if (pyModule == null || pyModule.isEmpty()) { - throw new IllegalArgumentException("module should not be null or empty."); + String pythonClazz = (String) kwargs.remove("pythonClazz"); + if (pythonClazz == null || pythonClazz.isEmpty()) { + throw new IllegalArgumentException("pythonClazz should not be null or empty."); } - pyClazz = (String) kwargs.remove("clazz"); - if (pyClazz == null || pyClazz.isEmpty()) { - throw new IllegalArgumentException("clazz should not be null or empty."); + int lastDotIndex = pythonClazz.lastIndexOf('.'); + if (lastDotIndex <= 0) { + throw new IllegalArgumentException( + "pythonClazz should be in format 'module.ClassName', got: " + pythonClazz); + } + pyModule = pythonClazz.substring(0, lastDotIndex); + pyClazz = pythonClazz.substring(lastDotIndex + 1); + + if (pyModule.isEmpty() || pyClazz.isEmpty()) { + throw new IllegalArgumentException( + "Invalid pythonClazz format, module or clazz is empty: " + pythonClazz); } } diff --git a/plan/src/test/java/org/apache/flink/agents/plan/AgentPlanTest.java b/plan/src/test/java/org/apache/flink/agents/plan/AgentPlanTest.java index 7a9ad41e..ad513248 100644 --- a/plan/src/test/java/org/apache/flink/agents/plan/AgentPlanTest.java +++ b/plan/src/test/java/org/apache/flink/agents/plan/AgentPlanTest.java @@ -157,8 +157,7 @@ public class AgentPlanTest { @ChatModelSetup public static ResourceDescriptor pythonChatModel() { return ResourceDescriptor.Builder.newBuilder(TestPythonResource.class.getName()) - .addInitialArgument("module", "test.module") - .addInitialArgument("clazz", "TestClazz") + .addInitialArgument("pythonClazz", "test.module.TestClazz") .build(); }
