You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@flink.apache.org by "wenjin272 (via GitHub)" <gi...@apache.org> on 2026/03/17 06:44:51 UTC
[PR] [runtime] Support async execution for cross language resources. [flink-agents]
wenjin272 opened a new pull request, #571:
URL: https://github.com/apache/flink-agents/pull/571
<!--
* Thank you very much for contributing to Flink Agents.
* Please add the relevant components in the PR title. E.g., [api], [runtime], [java], [python], [hotfix], etc.
-->
<!-- Please link the PR to the relevant issue(s). Hotfix doesn't need this. -->
Linked issue: #448
### Purpose of change
When invoking a Java method via Pemja from a Python async thread, if that Java method creates objects using reflection, a `ClassNotFoundException` may occur because the Python async thread lacks the necessary Java environment context.
In Flink agents, this issue occurs when the Python API calls a Java resource that depends on other Java resources in async thread. For example, the python chat model action call `chat` of a java chat model setup, and the setup will get the correspond chat model connection, which will construct the connection object by reflection.
To resolve this issue, this patch moves the construction from the python async thread to the python pemja thread.
This patch depends on https://github.com/alibaba/pemja/pull/95 in pemja. Therefore, we need to wait for the fix versions for Pemja and Flink 1.20, 2.0, 2.1, and 2.2.
### Tests
existed e2e test for cross language resources
### API
Yes. Add `open` for `Resource`
### Documentation
<!-- Do not remove this section. Check the proper box only. -->
- [ ] `doc-needed` <!-- Your PR changes impact docs -->
- [ ] `doc-not-needed` <!-- Your PR changes do not impact docs -->
- [ ] `doc-included` <!-- Your PR already contains the necessary documentation updates -->
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [runtime] Support async execution for cross language resources. [flink-agents]
Posted by "xintongsong (via GitHub)" <gi...@apache.org>.
xintongsong merged PR #571:
URL: https://github.com/apache/flink-agents/pull/571
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [runtime] Support async execution for cross language resources. [flink-agents]
Posted by "wenjin272 (via GitHub)" <gi...@apache.org>.
wenjin272 commented on PR #571:
URL: https://github.com/apache/flink-agents/pull/571#issuecomment-4087028937
After the code review is complete with no issues, I will add the corresponding documentation updates to this PR.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [runtime] Support async execution for cross language resources. [flink-agents]
Posted by "xintongsong (via GitHub)" <gi...@apache.org>.
xintongsong commented on code in PR #571:
URL: https://github.com/apache/flink-agents/pull/571#discussion_r3027149939
##########
tools/ut.sh:
##########
@@ -170,7 +170,7 @@ java_tests() {
exclude_list="!e2e-test/flink-agents-end-to-end-tests-integration,!e2e-test/flink-agents-end-to-end-tests-resource-cross-language"
- mvn -T16 --batch-mode --no-transfer-progress test -pl "${exclude_list}"
+ mvn -T16 --batch-mode --no-transfer-progress test -fn -pl "${exclude_list}"
Review Comment:
Should we use `-fae`?
##########
plan/src/main/java/org/apache/flink/agents/plan/AgentPlan.java:
##########
@@ -259,7 +259,7 @@ public Resource getResource(String name, ResourceType type) throws Exception {
// Cache the resource
resourceCache.computeIfAbsent(type, k -> new ConcurrentHashMap<>()).put(name, resource);
-
+ resource.open();
Review Comment:
`open()` is called after putting the resource into the cache, which means if `open()` fails, the corrupted resource might be left in the cache.
##########
python/flink_agents/api/chat_models/chat_model.py:
##########
@@ -133,9 +137,11 @@ class BaseChatModelSetup(Resource):
different chat configurations.
"""
- connection: str = Field(description="Name of the referenced connection.")
+ connection: str | BaseChatModelConnection = Field(
Review Comment:
We should always check that `connection` is a `BaseChatModelConnection` before using. Maybe overridding the getter? Same for other resources.r
##########
plan/src/main/java/org/apache/flink/agents/plan/actions/Utils.java:
##########
@@ -0,0 +1,97 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.flink.agents.plan.actions;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Properties;
+import java.util.StringTokenizer;
+
+public final class Utils {
+ private static final Logger LOG = LoggerFactory.getLogger(Utils.class);
+ private static final String defaultValue = "<unknown>";
Review Comment:
DEFAULT_VALUE
##########
api/src/main/java/org/apache/flink/agents/api/chat/model/BaseChatModelSetup.java:
##########
@@ -35,18 +35,44 @@
import java.util.function.BiFunction;
public abstract class BaseChatModelSetup extends Resource {
- protected final String connection;
+ protected final String connectionName;
protected String model;
protected Object prompt;
- protected List<String> tools;
+ protected List<String> toolNames;
+
+ protected BaseChatModelConnection connection;
Review Comment:
We should mark this `@Nullable`, and always check that it's not null before using it. Same for the other resources.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org