You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@flink.apache.org by "AmenAdem (via GitHub)" <gi...@apache.org> on 2025/08/06 09:05:24 UTC
[PR] WIP: [Feature][API] Introduce ChatModel,Tool and Prompt in Java [flink-agents]
AmenAdem opened a new pull request, #94:
URL: https://github.com/apache/flink-agents/pull/94
<!--
* 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: #77
### Purpose of change
This PR implements the core tool system infrastructure for Flink Agents, including:
### Tests
No unit tests implemented yet
<!-- How is this change verified? -->
### API
Yes, this change introduces new public APIs
<!-- Does this change touches any public APIs? -->
### Documentation
es, this should be documented as it provides the foundational tool execution system. Documentation will be added once the implementation is finalized and unit tests are complete.
<!-- Should this change be covered by the user documentation?-->
--
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] WIP: [Feature][API] Introduce ChatModel,Tool and Prompt in Java [flink-agents]
Posted by "xintongsong (via GitHub)" <gi...@apache.org>.
xintongsong commented on code in PR #94:
URL: https://github.com/apache/flink-agents/pull/94#discussion_r2284949946
##########
api/src/main/java/org/apache/flink/agents/api/prompt/Prompt.java:
##########
@@ -0,0 +1,95 @@
+/*
+ * 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.api.prompt;
+
+import org.apache.flink.agents.api.chat.messages.ChatMessage;
+import org.apache.flink.agents.api.chat.messages.MessageRole;
+import org.apache.flink.agents.api.resource.ResourceType;
+import org.apache.flink.agents.api.resource.SerializableResource;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+
+/**
+ * Prompt for a language model
+ *
+ * <p>The template can be either a string or a sequence of ChatMessage objects.
+ */
+public class Prompt extends SerializableResource {
Review Comment:
I'd suggest to make `PromptTemplate`, `MessagesTemplate`, `StringTemplate` private inner classes of `Prompt`. Because while these classes are in the api module, they are for internal usages and we do not want users to use them.
##########
api/src/main/java/org/apache/flink/agents/api/annotation/Tool.java:
##########
@@ -24,18 +24,34 @@
import java.lang.annotation.Target;
/**
- * Annotation to mark a field as a tool resource that should be managed by the agent plan.
+ * Annotation to mark a field or method as a tool resource that should be managed by the agent plan.
*
* <p>Fields annotated with @Tool will be scanned during agent plan creation and corresponding
- * resource providers will be created to manage the tool instances.
+ * resource providers will be created to manage the tool instances. Methods annotated with @Tool
+ * must be static and will be wrapped as FunctionTool resources.
*/
-@Target(ElementType.FIELD)
+@Target({ElementType.FIELD, ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)
public @interface Tool {
/**
- * The name of the tool resource. If not specified, the field name will be used.
+ * The name of the tool resource. If not specified, the field/method name will be used.
*
* @return the resource name
*/
String name() default "";
Review Comment:
We should not accept empty string as default name.
##########
api/src/main/java/org/apache/flink/agents/api/tools/SchemaUtils.java:
##########
@@ -0,0 +1,259 @@
+/*
+ *
+ * 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.api.tools;
+
+import org.apache.flink.agents.api.annotation.Tool;
+import org.apache.flink.agents.api.annotation.ToolParam;
+import org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.JsonNode;
+import org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.ObjectMapper;
+import org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.node.ArrayNode;
+import org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.node.ObjectNode;
+
+import java.lang.reflect.Method;
+import java.lang.reflect.Parameter;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+public class SchemaUtils {
+ private static final ObjectMapper objectMapper = new ObjectMapper();
+
+ private static final Map<Class<?>, String> TYPE_MAPPING = new HashMap<>();
+
+ static {
+ TYPE_MAPPING.put(String.class, "string");
+ TYPE_MAPPING.put(Integer.class, "integer");
+ TYPE_MAPPING.put(int.class, "integer");
+ TYPE_MAPPING.put(Long.class, "integer");
+ TYPE_MAPPING.put(long.class, "integer");
+ TYPE_MAPPING.put(Double.class, "number");
+ TYPE_MAPPING.put(double.class, "number");
+ TYPE_MAPPING.put(Float.class, "number");
+ TYPE_MAPPING.put(float.class, "number");
+ TYPE_MAPPING.put(Boolean.class, "boolean");
+ TYPE_MAPPING.put(boolean.class, "boolean");
+ TYPE_MAPPING.put(Object.class, "object");
+ TYPE_MAPPING.put(Map.class, "object");
+ TYPE_MAPPING.put(java.util.List.class, "array");
+ TYPE_MAPPING.put(java.util.Collection.class, "array");
+ }
+
+ /** Create a JSON schema from a method annotated with @Tool. */
+ public static String createSchemaFromMethod(Method method) {
Review Comment:
Never used
##########
api/src/main/java/org/apache/flink/agents/api/chat/messages/Message.java:
##########
@@ -0,0 +1,40 @@
+/*
+ * 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.api.chat.messages;
+
+import java.util.Map;
+
+public interface Message {
Review Comment:
Why do we need this abstraction? There's no implementation other than `ChatMessage`, and the methods `getMessageType()` and `getText()` are never used.
##########
api/src/main/java/org/apache/flink/agents/api/annotation/Tool.java:
##########
@@ -24,18 +24,34 @@
import java.lang.annotation.Target;
/**
- * Annotation to mark a field as a tool resource that should be managed by the agent plan.
+ * Annotation to mark a field or method as a tool resource that should be managed by the agent plan.
*
* <p>Fields annotated with @Tool will be scanned during agent plan creation and corresponding
- * resource providers will be created to manage the tool instances.
+ * resource providers will be created to manage the tool instances. Methods annotated with @Tool
+ * must be static and will be wrapped as FunctionTool resources.
*/
-@Target(ElementType.FIELD)
+@Target({ElementType.FIELD, ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)
public @interface Tool {
/**
- * The name of the tool resource. If not specified, the field name will be used.
+ * The name of the tool resource. If not specified, the field/method name will be used.
*
* @return the resource name
*/
String name() default "";
+
+ /**
+ * The description of the tool. If not provided, the field/method name will be used.
+ *
+ * @return the description of the tool
+ */
+ String description() default "";
+
+ /**
+ * Whether the tool result should be returned directly or passed back to the model.
+ *
+ * @return true if the tool result should be returned directly, false if it should be passed
+ * back to the model
+ */
+ boolean returnDirect() default false;
Review Comment:
Unused
##########
api/src/main/java/org/apache/flink/agents/api/prompt/PromptUtils.java:
##########
@@ -0,0 +1,67 @@
+/*
+ *
+ * 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.api.prompt;
+
+import java.util.Map;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+/** Formatter utility for prompt template substitution, */
+public class PromptUtils {
+
+ private static final Pattern BRACE_PATTERN = Pattern.compile("\\{([^}]+)\\}");
+
+ /** Format template string with keyword arguments */
+ public static String format(String template, Map<String, String> kwargs) {
+ if (template == null) {
+ return "";
+ }
+
+ String result = template;
+ for (Map.Entry<String, String> entry : kwargs.entrySet()) {
+ String placeholder = "{" + entry.getKey() + "}";
+ String value = entry.getValue() != null ? entry.getValue() : "";
+ result = result.replace(placeholder, value);
+ }
+ return result;
+ }
+
+ /** Extract variable names from template */
+ public static java.util.Set<String> extractVariables(String template) {
+ java.util.Set<String> variables = new java.util.HashSet<>();
+ Matcher matcher = BRACE_PATTERN.matcher(template);
+ while (matcher.find()) {
+ variables.add(matcher.group(1));
+ }
+ return variables;
+ }
+
+ /** Validate that all required variables are provided */
+ public static void validateTemplate(String template, Map<String, String> kwargs) {
Review Comment:
This method is never used. Shall we remove it?
##########
api/src/main/java/org/apache/flink/agents/api/annotation/ToolParam.java:
##########
@@ -0,0 +1,63 @@
+/*
+ *
+ * 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.api.annotation;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+@Target({ElementType.PARAMETER, ElementType.FIELD, ElementType.ANNOTATION_TYPE})
+@Retention(RetentionPolicy.RUNTIME)
+@Documented
+public @interface ToolParam {
+
+ /**
+ * Whether the tool argument is required.
+ *
+ * @return true if the argument is required, false otherwise.
+ */
+ boolean required() default true;
+
+ /**
+ * The name of the tool argument.
+ *
+ * @return a string representing the name of the argument, which can be used to identify it in
+ * the tool's context.
+ */
+ String name() default "";
Review Comment:
I'd suggest to use the parameter name, rather than introducing an extra name in the annotation.
##########
api/src/main/java/org/apache/flink/agents/api/prompt/PromptUtils.java:
##########
@@ -0,0 +1,67 @@
+/*
+ *
+ * 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.api.prompt;
+
+import java.util.Map;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+/** Formatter utility for prompt template substitution, */
+public class PromptUtils {
+
+ private static final Pattern BRACE_PATTERN = Pattern.compile("\\{([^}]+)\\}");
+
+ /** Format template string with keyword arguments */
+ public static String format(String template, Map<String, String> kwargs) {
+ if (template == null) {
+ return "";
+ }
+
+ String result = template;
+ for (Map.Entry<String, String> entry : kwargs.entrySet()) {
+ String placeholder = "{" + entry.getKey() + "}";
+ String value = entry.getValue() != null ? entry.getValue() : "";
+ result = result.replace(placeholder, value);
+ }
+ return result;
+ }
+
+ /** Extract variable names from template */
+ public static java.util.Set<String> extractVariables(String template) {
+ java.util.Set<String> variables = new java.util.HashSet<>();
+ Matcher matcher = BRACE_PATTERN.matcher(template);
+ while (matcher.find()) {
+ variables.add(matcher.group(1));
+ }
+ return variables;
+ }
Review Comment:
I'd suggest to make these methods private static methods of `Prompt`.
##########
api/src/main/java/org/apache/flink/agents/api/tools/BaseTool.java:
##########
@@ -0,0 +1,62 @@
+/*
+ * 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.api.tools;
+
+import org.apache.flink.agents.api.resource.ResourceType;
+import org.apache.flink.agents.api.resource.SerializableResource;
+
+/**
+ * Simplified base class for all tools. Focus on essential tool functionality without
+ * overcomplicated features.
+ */
+public abstract class BaseTool extends SerializableResource {
Review Comment:
I think the following classes should belong to either the plan or runtime module, because we do not support users to extend `BaseTool` with custom implementations. They can only either annotate a method as a tool, or leverage tools from a mcp server.
- BaseTool
- SchemaUtils
- ToolMetadata
- ToolParameters
- ToolResponse
- ToolType
##########
api/src/main/java/org/apache/flink/agents/api/tools/ToolException.java:
##########
@@ -0,0 +1,61 @@
+/*
+ * 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.api.tools;
+
+/**
+ * Exception thrown when tool operations fail. Provides specific error handling for tool-related
+ * failures.
+ */
+public class ToolException extends RuntimeException {
Review Comment:
Never used
##########
api/src/main/java/org/apache/flink/agents/api/tools/SchemaUtils.java:
##########
@@ -0,0 +1,259 @@
+/*
+ *
+ * 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.api.tools;
+
+import org.apache.flink.agents.api.annotation.Tool;
+import org.apache.flink.agents.api.annotation.ToolParam;
+import org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.JsonNode;
+import org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.ObjectMapper;
+import org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.node.ArrayNode;
+import org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.node.ObjectNode;
+
+import java.lang.reflect.Method;
+import java.lang.reflect.Parameter;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+public class SchemaUtils {
+ private static final ObjectMapper objectMapper = new ObjectMapper();
+
+ private static final Map<Class<?>, String> TYPE_MAPPING = new HashMap<>();
+
+ static {
+ TYPE_MAPPING.put(String.class, "string");
+ TYPE_MAPPING.put(Integer.class, "integer");
+ TYPE_MAPPING.put(int.class, "integer");
+ TYPE_MAPPING.put(Long.class, "integer");
+ TYPE_MAPPING.put(long.class, "integer");
+ TYPE_MAPPING.put(Double.class, "number");
+ TYPE_MAPPING.put(double.class, "number");
+ TYPE_MAPPING.put(Float.class, "number");
+ TYPE_MAPPING.put(float.class, "number");
+ TYPE_MAPPING.put(Boolean.class, "boolean");
+ TYPE_MAPPING.put(boolean.class, "boolean");
+ TYPE_MAPPING.put(Object.class, "object");
+ TYPE_MAPPING.put(Map.class, "object");
+ TYPE_MAPPING.put(java.util.List.class, "array");
+ TYPE_MAPPING.put(java.util.Collection.class, "array");
+ }
+
+ /** Create a JSON schema from a method annotated with @Tool. */
+ public static String createSchemaFromMethod(Method method) {
+ Tool toolAnnotation = method.getAnnotation(Tool.class);
+ if (toolAnnotation == null) {
+ throw new IllegalArgumentException("Method must be annotated with @Tool");
+ }
+
+ ObjectNode schema = objectMapper.createObjectNode();
+ schema.put("type", "object");
+
+ ObjectNode properties = objectMapper.createObjectNode();
+ ArrayNode required = objectMapper.createArrayNode();
+
+ Parameter[] parameters = method.getParameters();
+ for (Parameter parameter : parameters) {
+ ToolParam paramAnnotation = parameter.getAnnotation(ToolParam.class);
+
+ String paramName = parameter.getName();
+ ObjectNode paramSchema = createParameterSchema(parameter, paramAnnotation);
+ properties.set(paramName, paramSchema);
+
+ // Add to required if no default value and required=true
+ if (paramAnnotation == null
+ || (paramAnnotation.required() && paramAnnotation.defaultValue().isEmpty())) {
+ required.add(paramName);
+ }
+ }
+
+ schema.set("properties", properties);
+ if (required.size() > 0) {
+ schema.set("required", required);
+ }
+
+ return schema.toString();
+ }
+
+ private static ObjectNode createParameterSchema(
+ Parameter parameter, ToolParam paramAnnotation) {
+ ObjectNode paramSchema = objectMapper.createObjectNode();
+
+ Class<?> paramType = parameter.getType();
+ String jsonType = TYPE_MAPPING.getOrDefault(paramType, "string");
+ paramSchema.put("type", jsonType);
+
+ if (paramAnnotation != null) {
+ if (!paramAnnotation.description().isEmpty()) {
+ paramSchema.put("description", paramAnnotation.description());
+ }
+
+ if (!paramAnnotation.defaultValue().isEmpty()) {
+ // Convert default value based on type
+ Object defaultValue =
+ convertDefaultValue(paramAnnotation.defaultValue(), paramType);
+ if (defaultValue instanceof String) {
+ paramSchema.put("default", (String) defaultValue);
+ } else if (defaultValue instanceof Integer) {
+ paramSchema.put("default", (Integer) defaultValue);
+ } else if (defaultValue instanceof Double) {
+ paramSchema.put("default", (Double) defaultValue);
+ } else if (defaultValue instanceof Boolean) {
+ paramSchema.put("default", (Boolean) defaultValue);
+ }
+ }
+ }
+
+ return paramSchema;
+ }
+
+ private static Object convertDefaultValue(String defaultValue, Class<?> targetType) {
+ if (targetType == String.class) {
+ return defaultValue;
+ } else if (targetType == Integer.class || targetType == int.class) {
+ return Integer.parseInt(defaultValue);
+ } else if (targetType == Long.class || targetType == long.class) {
+ return Long.parseLong(defaultValue);
+ } else if (targetType == Double.class || targetType == double.class) {
+ return Double.parseDouble(defaultValue);
+ } else if (targetType == Float.class || targetType == float.class) {
+ return Float.parseFloat(defaultValue);
+ } else if (targetType == Boolean.class || targetType == boolean.class) {
+ return Boolean.parseBoolean(defaultValue);
+ }
+ return defaultValue;
+ }
+
+ /** Validate parameters against a JSON schema. */
+ public static boolean validateParameters(ToolParameters parameters, String schema) {
Review Comment:
never used
##########
api/src/main/java/org/apache/flink/agents/api/chat/messages/ToolCall.java:
##########
@@ -0,0 +1,85 @@
+/*
+ * 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.api.chat.messages;
+
+import java.util.Objects;
+
+public class ToolCall {
Review Comment:
+1
##########
plan/src/main/java/org/apache/flink/agents/plan/serializer/ResourceProviderJsonDeserializer.java:
##########
@@ -115,6 +119,24 @@ private JavaSerializableResourceProvider deserializeJavaSerializableResourceProv
name, ResourceType.fromValue(type), module, clazz);
}
+ private ToolResourceProvider deserializeToolResourceProvider(JsonNode node) {
Review Comment:
I think the serializer and deserializer should not understand anything about the tools. They should only see SerializableResource as a blackbox.
##########
plan/src/main/java/org/apache/flink/agents/plan/resourceprovider/ToolResourceProvider.java:
##########
@@ -0,0 +1,96 @@
+/*
+ *
+ * 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.resourceprovider;
+
+import org.apache.flink.agents.api.resource.Resource;
+import org.apache.flink.agents.api.resource.ResourceType;
+import org.apache.flink.agents.api.tools.ToolMetadata;
+import org.apache.flink.agents.plan.JavaFunction;
+import org.apache.flink.agents.plan.tools.FunctionTool;
+import org.apache.flink.agents.plan.tools.ToolMetadataFactory;
+
+import java.lang.reflect.Method;
+import java.util.Arrays;
+import java.util.concurrent.Callable;
+
+/**
+ * Resource provider for tools created from static Java methods annotated with @Tool. Stores the
+ * reflective identity to reconstruct a FunctionTool at runtime.
+ */
+public class ToolResourceProvider extends ResourceProvider {
Review Comment:
+1
--
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] WIP: [Feature][API] Introduce ChatModel,Tool and Prompt in Java [flink-agents]
Posted by "AmenAdem (via GitHub)" <gi...@apache.org>.
AmenAdem commented on code in PR #94:
URL: https://github.com/apache/flink-agents/pull/94#discussion_r2271339280
##########
api/src/main/java/org/apache/flink/agents/api/tool/ToolRegistry.java:
##########
@@ -0,0 +1,139 @@
+/*
+ * 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.api.tool;
+
+import org.apache.flink.agents.api.tool.annotation.Tool;
+
+import java.lang.reflect.Method;
+import java.util.*;
+import java.util.concurrent.ConcurrentHashMap;
+
+/**
+ * Registry for managing tools available to agents. Works with the merged design where BaseTool
+ * contains ToolMetadata.
+ */
+public class ToolRegistry {
+
+ private final Map<String, BaseTool> tools = new ConcurrentHashMap<>();
+
+ /** Register a tool instance directly. */
+ public void registerTool(BaseTool tool) {
+ String name = tool.getName();
+ if (tools.containsKey(name)) {
+ throw new IllegalArgumentException(
+ "Tool with name '" + name + "' is already registered");
+ }
+ tools.put(name, tool);
+ }
+
+ /** Register all @Tool annotated methods from an object instance. */
+ public void registerToolsFromObject(Object toolProvider) {
Review Comment:
Ok, but Do we want to throw an exception if someone tries to register non-static @Tool methods? or should we only look for @Tool on static methods in the initial implementation?
--
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] WIP: [Feature][API] Introduce ChatModel,Tool and Prompt in Java [flink-agents]
Posted by "xintongsong (via GitHub)" <gi...@apache.org>.
xintongsong commented on PR #94:
URL: https://github.com/apache/flink-agents/pull/94#issuecomment-3190903363
@AmenAdem Thanks for working on this. The PR currently contains commits that do not belong to it, which makes it hard to review and merge. Could you please re-organize the commits?
FYI, we use `git rebase` rather than `git merge` in this project, to keep a clear linear git history. That means PRs containing commits that are already merged in the codebase can meet conflicts during rebasing. Such conflicts are better resolved before reviewing.
--
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] WIP: [Feature][API] Introduce ChatModel,Tool and Prompt in Java [flink-agents]
Posted by "AmenAdem (via GitHub)" <gi...@apache.org>.
AmenAdem commented on code in PR #94:
URL: https://github.com/apache/flink-agents/pull/94#discussion_r2271362640
##########
api/src/main/java/org/apache/flink/agents/api/tool/ToolMetadata.java:
##########
@@ -0,0 +1,241 @@
+/*
+ * 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.api.tool;
+
+import java.lang.reflect.Method;
+import java.util.List;
+import java.util.Objects;
+
+/**
+ * Metadata for a tool including its definition, invocation method, and parameters. This class holds
+ * all the information needed to register and invoke a tool.
+ */
+public class ToolMetadata {
+
+ private final ToolDefinition definition;
+ private final ToolType type;
+ private final Method method;
+ private final Object instance;
+ private final List<ToolParameterInfo> parameters;
Review Comment:
You re absolutely right the inputSchema in ToolDefinition should be sufficient.
I added the parameters field because I was thinking about runtime performance optimization. my reasoning was:
Avoiding repeated JSON schema parsing - the List<ToolParameterInfo> would be pre-parsed parameter metadata for faster runtime access
--
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] WIP: [Feature][API] Introduce ChatModel,Tool and Prompt in Java [flink-agents]
Posted by "AmenAdem (via GitHub)" <gi...@apache.org>.
AmenAdem commented on PR #94:
URL: https://github.com/apache/flink-agents/pull/94#issuecomment-3191735231
@xintongsong thanks for pointing that out. I ve dropped the unrelated commit, and the branch now contains only the relevant changes commits are clean and ready for review.
--
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] WIP: [Feature][API] Introduce ChatModel,Tool and Prompt in Java [flink-agents]
Posted by "wenjin272 (via GitHub)" <gi...@apache.org>.
wenjin272 commented on PR #94:
URL: https://github.com/apache/flink-agents/pull/94#issuecomment-3232248319
Hi, @AmenAdem. After several rounds of review, I believe this PR is now nearly complete, with only a few minor comments remaining to be addressed. Would you happen to have time this week or next to update this PR?
FYI, we are planning to have a code freeze in early September and begin preparing for the MVP release.
--
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] WIP: [Feature][API] Introduce ChatModel,Tool and Prompt in Java [flink-agents]
Posted by "AmenAdem (via GitHub)" <gi...@apache.org>.
AmenAdem commented on PR #94:
URL: https://github.com/apache/flink-agents/pull/94#issuecomment-3255378782
Hi @wenjin272 Sorry for the delayed response I ve been quite busy lately. I ll definitely have time this weekend to address the remaining comments and get this PR updated.
--
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] WIP: [Feature][API] Introduce ChatModel,Tool and Prompt in Java [flink-agents]
Posted by "wenjin272 (via GitHub)" <gi...@apache.org>.
wenjin272 commented on code in PR #94:
URL: https://github.com/apache/flink-agents/pull/94#discussion_r2259503519
##########
api/src/main/java/org/apache/flink/agents/api/chat/messages/AbstractMessage.java:
##########
@@ -0,0 +1,137 @@
+/*
+ * 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.api.chat.messages;
+
+import org.apache.flink.agents.api.util.Resource;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.nio.charset.Charset;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Objects;
+
+/**
+ * The AbstractMessage class is an abstract implementation of the Message interface. It provides a
+ * base implementation for message content, media attachments, metadata, and message type.
+ *
+ * @see Message
+ */
+public abstract class AbstractMessage implements Message {
Review Comment:
In your implementation, there are AbstractMessage and different AbstractMessage implementation, like UserMessage, SystemMessage and ToolMessage, which is similar to langChain.
In python implementation, there is only ChatMessage with different message role, can represent all user、system、tool message, which is similar to llama_index.
I think the former is more flexible but more complex, and the latter is more simple but enough for current project.
For api compatibility between python and java, I suggest use the latter abstraction.
##########
api/src/main/java/org/apache/flink/agents/api/tool/ToolMetadata.java:
##########
@@ -0,0 +1,241 @@
+/*
+ * 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.api.tool;
+
+import java.lang.reflect.Method;
+import java.util.List;
+import java.util.Objects;
+
+/**
+ * Metadata for a tool including its definition, invocation method, and parameters. This class holds
+ * all the information needed to register and invoke a tool.
+ */
+public class ToolMetadata {
+
+ private final ToolDefinition definition;
+ private final ToolType type;
+ private final Method method;
+ private final Object instance;
+ private final List<ToolParameterInfo> parameters;
Review Comment:
What's the usage of parameters? Dose the inputSchema in ToolDefinition is enough?
##########
api/src/main/java/org/apache/flink/agents/api/tool/ToolRegistry.java:
##########
@@ -0,0 +1,139 @@
+/*
+ * 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.api.tool;
+
+import org.apache.flink.agents.api.tool.annotation.Tool;
+
+import java.lang.reflect.Method;
+import java.util.*;
+import java.util.concurrent.ConcurrentHashMap;
+
+/**
+ * Registry for managing tools available to agents. Works with the merged design where BaseTool
+ * contains ToolMetadata.
+ */
+public class ToolRegistry {
Review Comment:
Does the ToolRegistry will be used when convert a user declared Agent to AgentPlan? Maybe we need add an integration test to explain the usage of ToolRegistry like test_get_resource_in_action.py in python.
##########
api/src/main/java/org/apache/flink/agents/api/prompt/Prompt.java:
##########
@@ -0,0 +1,221 @@
+/*
+ * 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.api.prompt;
+
+import org.apache.flink.agents.api.chat.ChatOptions;
+import org.apache.flink.agents.api.chat.messages.Message;
+import org.apache.flink.agents.api.chat.messages.SystemMessage;
+import org.apache.flink.agents.api.chat.messages.UserMessage;
+import org.apache.flink.agents.api.chat.model.ChatRequest;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+import java.util.Objects;
+import java.util.Optional;
+
+/**
+ * A simplified Prompt class that represents a conversation prompt for AI models. Contains a list of
+ * messages and optional chat options.
+ */
+public class Prompt implements ChatRequest<List<Message>> {
Review Comment:
Could provide create Prompt form text string?
##########
api/src/main/java/org/apache/flink/agents/api/tool/FunctionTool.java:
##########
@@ -0,0 +1,160 @@
+/*
+ * 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.api.tool;
+
+import org.apache.flink.agents.api.tool.annotation.Tool;
+import org.apache.flink.agents.api.tool.annotation.ToolParam;
+
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Function-based tool implementation that wraps annotated methods. Now uses the merged design with
+ * ToolMetadata.
+ */
+public class FunctionTool extends BaseTool {
+
+ private final Method method;
Review Comment:
Maybe we can reuse the JavaFunction to represent the function in FunctionTool.
##########
api/src/main/java/org/apache/flink/agents/api/tool/ToolRegistry.java:
##########
@@ -0,0 +1,139 @@
+/*
+ * 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.api.tool;
+
+import org.apache.flink.agents.api.tool.annotation.Tool;
+
+import java.lang.reflect.Method;
+import java.util.*;
+import java.util.concurrent.ConcurrentHashMap;
+
+/**
+ * Registry for managing tools available to agents. Works with the merged design where BaseTool
+ * contains ToolMetadata.
+ */
+public class ToolRegistry {
+
+ private final Map<String, BaseTool> tools = new ConcurrentHashMap<>();
+
+ /** Register a tool instance directly. */
+ public void registerTool(BaseTool tool) {
+ String name = tool.getName();
+ if (tools.containsKey(name)) {
+ throw new IllegalArgumentException(
+ "Tool with name '" + name + "' is already registered");
+ }
+ tools.put(name, tool);
+ }
+
+ /** Register all @Tool annotated methods from an object instance. */
+ public void registerToolsFromObject(Object toolProvider) {
Review Comment:
Maybe we can only support static method as FunctionTool at first to simplify this pr, and add other support later if necessary.
##########
api/src/main/java/org/apache/flink/agents/api/chat/model/BaseChatModel.java:
##########
@@ -0,0 +1,31 @@
+/*
+ * 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.api.chat.model;
+
+import org.apache.flink.agents.api.prompt.Prompt;
+
+public interface BaseChatModel {
+ /**
+ * Process a chat request and return a chat response.
+ *
+ * @param request the chat request containing messages, options, etc.
+ * @return the chat response containing model outputs
+ */
+ ChatResponse call(Prompt request);
Review Comment:
Maybe we can rename this method to 'chat'.
I suggest the input and output to be consistent with python implementation, or the api compatibility between python and java will be hard to maintain.
--
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] WIP: [Feature][API] Introduce ChatModel,Tool and Prompt in Java [flink-agents]
Posted by "AmenAdem (via GitHub)" <gi...@apache.org>.
AmenAdem commented on code in PR #94:
URL: https://github.com/apache/flink-agents/pull/94#discussion_r2271404702
##########
api/src/main/java/org/apache/flink/agents/api/tool/ToolRegistry.java:
##########
@@ -0,0 +1,139 @@
+/*
+ * 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.api.tool;
+
+import org.apache.flink.agents.api.tool.annotation.Tool;
+
+import java.lang.reflect.Method;
+import java.util.*;
+import java.util.concurrent.ConcurrentHashMap;
+
+/**
+ * Registry for managing tools available to agents. Works with the merged design where BaseTool
+ * contains ToolMetadata.
+ */
+public class ToolRegistry {
Review Comment:
You're right that the integration between ToolRegistry and the Agent → AgentPlan conversion process needs clarification.
Currently, the ToolRegistry operates more as a standalone tool management system (as shown in ToolExample.java with registry.invokeTool()), but its role in the AgentPlan compilation pipeline isn't clear.
I'm working on this integration now and thinking through two possible approaches:
* AgentPlan auto-discovery: When creating an AgentPlan from an agent, automatically scan for @Tool annotated methods and register them in a plan-specific registry.
* Explicit registration: Developers register tools in a ToolRegistry first, then reference them in agents
--
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] WIP: [Feature][API] Introduce ChatModel,Tool and Prompt in Java [flink-agents]
Posted by "xintongsong (via GitHub)" <gi...@apache.org>.
xintongsong commented on PR #94:
URL: https://github.com/apache/flink-agents/pull/94#issuecomment-3273950204
Hi @AmenAdem,
@wenjin272 and I have updated the PR, based on the work you have already completed, and addressed the remaining comments.
Sorry we had to take over like this. We are approaching the target date of the first release of this project, and there are quite some subsequent tasks blocked by this PR. I hope you can understand.
--
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] WIP: [Feature][API] Introduce ChatModel,Tool and Prompt in Java [flink-agents]
Posted by "wenjin272 (via GitHub)" <gi...@apache.org>.
wenjin272 commented on code in PR #94:
URL: https://github.com/apache/flink-agents/pull/94#discussion_r2275231383
##########
api/src/main/java/org/apache/flink/agents/api/tool/ToolRegistry.java:
##########
@@ -0,0 +1,139 @@
+/*
+ * 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.api.tool;
+
+import org.apache.flink.agents.api.tool.annotation.Tool;
+
+import java.lang.reflect.Method;
+import java.util.*;
+import java.util.concurrent.ConcurrentHashMap;
+
+/**
+ * Registry for managing tools available to agents. Works with the merged design where BaseTool
+ * contains ToolMetadata.
+ */
+public class ToolRegistry {
Review Comment:
I think the both approaches are look good to me, and we can provide the first approach now, and provide the second approach later.
For the first approach, we can use a plan-specific registry to help tool register, and maybe we need store the registered tools in registry directly in AgentPlan rather than the registry for keep compatibility with python AgentPlan.
##########
api/src/main/java/org/apache/flink/agents/api/tool/ToolRegistry.java:
##########
@@ -0,0 +1,139 @@
+/*
+ * 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.api.tool;
+
+import org.apache.flink.agents.api.tool.annotation.Tool;
+
+import java.lang.reflect.Method;
+import java.util.*;
+import java.util.concurrent.ConcurrentHashMap;
+
+/**
+ * Registry for managing tools available to agents. Works with the merged design where BaseTool
+ * contains ToolMetadata.
+ */
+public class ToolRegistry {
+
+ private final Map<String, BaseTool> tools = new ConcurrentHashMap<>();
+
+ /** Register a tool instance directly. */
+ public void registerTool(BaseTool tool) {
+ String name = tool.getName();
+ if (tools.containsKey(name)) {
+ throw new IllegalArgumentException(
+ "Tool with name '" + name + "' is already registered");
+ }
+ tools.put(name, tool);
+ }
+
+ /** Register all @Tool annotated methods from an object instance. */
+ public void registerToolsFromObject(Object toolProvider) {
Review Comment:
The reason I propose only support static method currently is as a part of Flink job, the AgentPlan will be compiled in JobManager, and will be distributed to TaskManagers, so the tools in AgentPlan need to support serialization. For tools from non-static methods, the object should also be serializable, which may cause some complexity.
I think maybe we can let the ToolRegistry support register both static and non-static methods, but only support static method as Tool when declare an Agent.
##########
api/src/main/java/org/apache/flink/agents/api/tool/example/ToolExample.java:
##########
@@ -0,0 +1,131 @@
+/*
+ * 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.api.tool.example;
+
+import org.apache.flink.agents.api.tool.*;
+import org.apache.flink.agents.api.tool.annotation.Tool;
+import org.apache.flink.agents.api.tool.annotation.ToolParam;
+
+/** Example demonstrating how to create and use tools */
+public class ToolExample {
+
+ /** Example tool for mathematical calculations. */
+ @Tool(name = "calculate", description = "Performs basic mathematical operations on two numbers")
+ public double calculate(
+ @ToolParam(description = "The operation to perform: add, subtract, multiply, divide")
+ String operation,
+ @ToolParam(description = "First number") double a,
+ @ToolParam(description = "Second number") double b) {
+ switch (operation.toLowerCase()) {
+ case "add":
+ return a + b;
+ case "subtract":
+ return a - b;
+ case "multiply":
+ return a * b;
+ case "divide":
+ if (b == 0) {
+ throw new IllegalArgumentException("Cannot divide by zero");
+ }
+ return a / b;
+ default:
+ throw new IllegalArgumentException("Unknown operation: " + operation);
+ }
+ }
+
+ /** Example tool for string manipulation. */
+ @Tool(name = "format_text", description = "Formats text with various options")
+ public String formatText(
+ @ToolParam(description = "The text to format") String text,
+ @ToolParam(description = "Convert to uppercase", required = false) boolean uppercase,
+ @ToolParam(description = "Prefix to add", required = false) String prefix) {
+ String result = text;
+
+ if (uppercase) {
+ result = result.toUpperCase();
+ }
+
+ if (prefix != null && !prefix.isEmpty()) {
+ result = prefix + result;
+ }
+
+ return result;
+ }
+
+ /** Static tool example. */
+ @Tool(name = "get_timestamp", description = "Gets the current timestamp in milliseconds")
+ public static long getCurrentTimestamp() {
+ return System.currentTimeMillis();
+ }
+
+ /** Example of how to use the tool system. */
+ public static void main(String[] args) {
+ // Create tool registry
+ ToolRegistry registry = new ToolRegistry();
+
+ // Register tools from an instance
+ ToolExample example = new ToolExample();
+ registry.registerToolsFromObject(example);
+
+ // Register static tools from class
+ registry.registerToolsFromClass(ToolExample.class);
+
+ // Example 1: Use the calculate tool
+ ToolParameters calcParams = new ToolParameters();
+ calcParams.addParameter("operation", "add");
+ calcParams.addParameter("a", 10.5);
+ calcParams.addParameter("b", 5.2);
+
+ ToolResponse calcResult = registry.invokeTool("calculate", calcParams);
Review Comment:
This will cause Invalid parameters error, for parameters name is not match. The parameter name in tool is arg0, arg1 and arg2 for `method.getParameters()` in `createSchemaFromMethod` not returns the declared name in method.
##########
api/src/main/java/org/apache/flink/agents/api/tool/example/ToolExample.java:
##########
@@ -0,0 +1,131 @@
+/*
+ * 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.api.tool.example;
+
+import org.apache.flink.agents.api.tool.*;
+import org.apache.flink.agents.api.tool.annotation.Tool;
+import org.apache.flink.agents.api.tool.annotation.ToolParam;
+
+/** Example demonstrating how to create and use tools */
+public class ToolExample {
+
+ /** Example tool for mathematical calculations. */
+ @Tool(name = "calculate", description = "Performs basic mathematical operations on two numbers")
+ public double calculate(
+ @ToolParam(description = "The operation to perform: add, subtract, multiply, divide")
+ String operation,
+ @ToolParam(description = "First number") double a,
+ @ToolParam(description = "Second number") double b) {
+ switch (operation.toLowerCase()) {
+ case "add":
+ return a + b;
+ case "subtract":
+ return a - b;
+ case "multiply":
+ return a * b;
+ case "divide":
+ if (b == 0) {
+ throw new IllegalArgumentException("Cannot divide by zero");
+ }
+ return a / b;
+ default:
+ throw new IllegalArgumentException("Unknown operation: " + operation);
+ }
+ }
+
+ /** Example tool for string manipulation. */
+ @Tool(name = "format_text", description = "Formats text with various options")
+ public String formatText(
+ @ToolParam(description = "The text to format") String text,
+ @ToolParam(description = "Convert to uppercase", required = false) boolean uppercase,
+ @ToolParam(description = "Prefix to add", required = false) String prefix) {
+ String result = text;
+
+ if (uppercase) {
+ result = result.toUpperCase();
+ }
+
+ if (prefix != null && !prefix.isEmpty()) {
+ result = prefix + result;
+ }
+
+ return result;
+ }
+
+ /** Static tool example. */
+ @Tool(name = "get_timestamp", description = "Gets the current timestamp in milliseconds")
+ public static long getCurrentTimestamp() {
+ return System.currentTimeMillis();
+ }
+
+ /** Example of how to use the tool system. */
+ public static void main(String[] args) {
+ // Create tool registry
+ ToolRegistry registry = new ToolRegistry();
+
+ // Register tools from an instance
+ ToolExample example = new ToolExample();
+ registry.registerToolsFromObject(example);
+
+ // Register static tools from class
+ registry.registerToolsFromClass(ToolExample.class);
Review Comment:
This will cause already registered exception
--
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] WIP: [Feature][API] Introduce ChatModel,Tool and Prompt in Java [flink-agents]
Posted by "wenjin272 (via GitHub)" <gi...@apache.org>.
wenjin272 commented on PR #94:
URL: https://github.com/apache/flink-agents/pull/94#issuecomment-3163340759
The pr this pr depends on #91 is nearly merged. You could rebase on it.
--
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] WIP: [Feature][API] Introduce ChatModel,Tool and Prompt in Java [flink-agents]
Posted by "AmenAdem (via GitHub)" <gi...@apache.org>.
AmenAdem commented on code in PR #94:
URL: https://github.com/apache/flink-agents/pull/94#discussion_r2271299129
##########
api/src/main/java/org/apache/flink/agents/api/chat/messages/AbstractMessage.java:
##########
@@ -0,0 +1,137 @@
+/*
+ * 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.api.chat.messages;
+
+import org.apache.flink.agents.api.util.Resource;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.nio.charset.Charset;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Objects;
+
+/**
+ * The AbstractMessage class is an abstract implementation of the Message interface. It provides a
+ * base implementation for message content, media attachments, metadata, and message type.
+ *
+ * @see Message
+ */
+public abstract class AbstractMessage implements Message {
Review Comment:
To be honest, I'm not fully convinced that the single ChatMessage class approach is the most optimal design choice - I can see the benefits of the more flexible AbstractMessage hierarchy (like LangChain's approach) for extensibility and type safety.
However, for the sake of API alignment between Python and Java implementations, I agree we should go with the single ChatMessage + MessageRole pattern that matches the existing Python codebase.
done !
--
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] WIP: [Feature][API] Introduce ChatModel,Tool and Prompt in Java [flink-agents]
Posted by "wenjin272 (via GitHub)" <gi...@apache.org>.
wenjin272 commented on code in PR #94:
URL: https://github.com/apache/flink-agents/pull/94#discussion_r2281170622
##########
api/src/main/java/org/apache/flink/agents/api/util/StringUtils.java:
##########
@@ -0,0 +1,79 @@
+/*
+ * 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.api.util;
+
+/** Utility methods for String operations in the Flink Agents framework. */
+public final class StringUtils {
Review Comment:
Class 'StringUtils' is never used.
##########
api/src/main/java/org/apache/flink/agents/api/chat/messages/ChatMessage.java:
##########
@@ -0,0 +1,173 @@
+/*
+ * 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.api.chat.messages;
+
+import org.apache.flink.agents.api.resource.Resource;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+
+/**
+ * Chat message class that represents all message types (user, system, assistant, tool) with
+ * different roles
+ */
+public class ChatMessage implements Message {
+
+ /** The key for the message type in the metadata. */
+ public static final String MESSAGE_TYPE = "messageType";
+
+ private MessageRole role;
+ private String content;
+ private List<Map<String, Object>> toolCalls;
+ private Map<String, Object> extraArgs;
+
+ /** Default constructor with USER role */
+ public ChatMessage() {
+ this.role = MessageRole.USER;
Review Comment:
The default role could be System to be aligned with python implementation.
##########
api/src/main/java/org/apache/flink/agents/api/tools/BaseTool.java:
##########
@@ -0,0 +1,62 @@
+/*
+ * 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.api.tools;
+
+import org.apache.flink.agents.api.resource.ResourceType;
+import org.apache.flink.agents.api.resource.SerializableResource;
+
+/**
+ * Simplified base class for all tools. Focus on essential tool functionality without
+ * overcomplicated features.
+ */
+public abstract class BaseTool extends SerializableResource {
+
+ protected final ToolMetadata metadata;
+
+ protected BaseTool(ToolMetadata metadata) {
+ this.metadata = java.util.Objects.requireNonNull(metadata, "metadata cannot be null");
+ }
+
+ /** Get the metadata of this tool. */
+ public final ToolMetadata getMetadata() {
+ return metadata;
+ }
+
+ /** Return resource type of class. */
+ @Override
+ public final ResourceType getResourceType() {
Review Comment:
Maybe this could be static method
##########
api/src/main/java/org/apache/flink/agents/api/chat/messages/ToolCall.java:
##########
@@ -0,0 +1,85 @@
+/*
+ * 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.api.chat.messages;
+
+import java.util.Objects;
+
+public class ToolCall {
Review Comment:
Class 'ToolCall' is never used.
##########
api/src/main/java/org/apache/flink/agents/api/util/CollectionUtils.java:
##########
@@ -0,0 +1,68 @@
+/*
+ * 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.api.util;
+
+import java.util.Collection;
+import java.util.Map;
+
+/** Utility methods for Collection operations in the Flink Agents framework. */
+public final class CollectionUtils {
Review Comment:
Class 'CollectionUtils' is never used
##########
plan/src/main/java/org/apache/flink/agents/plan/resourceprovider/JavaSerializableResourceProvider.java:
##########
@@ -39,14 +41,18 @@ public JavaSerializableResourceProvider(
@Override
public Resource provide(Callable<Resource> getResource) throws Exception {
Review Comment:
For SerializableResourceProvider, we should get the SerializableResource by deserialization rather than construct it. You can refer to the PythonSerializableResourceProvider in python implementation.
##########
plan/src/main/java/org/apache/flink/agents/plan/resourceprovider/ToolResourceProvider.java:
##########
@@ -0,0 +1,96 @@
+/*
+ *
+ * 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.resourceprovider;
+
+import org.apache.flink.agents.api.resource.Resource;
+import org.apache.flink.agents.api.resource.ResourceType;
+import org.apache.flink.agents.api.tools.ToolMetadata;
+import org.apache.flink.agents.plan.JavaFunction;
+import org.apache.flink.agents.plan.tools.FunctionTool;
+import org.apache.flink.agents.plan.tools.ToolMetadataFactory;
+
+import java.lang.reflect.Method;
+import java.util.Arrays;
+import java.util.concurrent.Callable;
+
+/**
+ * Resource provider for tools created from static Java methods annotated with @Tool. Stores the
+ * reflective identity to reconstruct a FunctionTool at runtime.
+ */
+public class ToolResourceProvider extends ResourceProvider {
Review Comment:
Can we use JavaSerializableResourceProvider rather than introduce a new type of ResourceProvider, which add the complexity of the serialization/deserialization of AgentPlan and also break the AgentPlan compatibility between python and java.
You may modify the currently implementation of JavaSerializableResourceProvider and you can refer to the PythonSerializableResourceProvider in python. The key assumption is the resource in SerializableResourceProvider should be json serializable.
In our design, Tool should be regarded as SerializableResource, and be json serializable.
--
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] WIP: [Feature][API] Introduce ChatModel,Tool and Prompt in Java [flink-agents]
Posted by "xintongsong (via GitHub)" <gi...@apache.org>.
xintongsong merged PR #94:
URL: https://github.com/apache/flink-agents/pull/94
--
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