You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@flink.apache.org by "xintongsong (via GitHub)" <gi...@apache.org> on 2025/09/25 10:50:55 UTC

Re: [PR] [api][java] Combine add methods to add_resource. [flink-agents]

xintongsong commented on code in PR #217:
URL: https://github.com/apache/flink-agents/pull/217#discussion_r2378652520


##########
api/src/main/java/org/apache/flink/agents/api/Agent.java:
##########
@@ -89,70 +89,38 @@ public void addResourcesIfAbsent(Map<ResourceType, Map<String, Object>> resource
     }
 
     /**
-     * Add prompt to agent.
+     * Add resource to agent.
      *
-     * @param name The name indicate the prompt.
-     * @param prompt The prompt instance.
+     * @param name The name indicate the resource.
+     * @param type The type of the resource.
+     * @param instance The serializable resource object, or the resource descriptor, or the tool
+     *     method.
      */
-    public Agent addPrompt(String name, Prompt prompt) {
-        if (resources.get(ResourceType.PROMPT).containsKey(name)) {
-            throw new IllegalArgumentException(String.format("Prompt %s already defined.", name));
-        }
-        resources.get(ResourceType.PROMPT).put(name, prompt);
-        return this;
-    }
-
-    /**
-     * Add tool to agent.
-     *
-     * @param tool The tool method, should be static method and annotated with @Tool.
-     */
-    public Agent addTool(Method tool) {
-        if (!Modifier.isStatic(tool.getModifiers())) {
-            throw new IllegalArgumentException("Only static methods are supported");
-        }
-
-        Tool toolAnnotation = tool.getAnnotation(Tool.class);
-        if (toolAnnotation == null) {
-            throw new IllegalArgumentException("Method must be annotated with @Tool");
-        }
-
-        String name = tool.getName();
-
-        if (resources.get(ResourceType.TOOL).containsKey(name)) {
-            throw new IllegalArgumentException(String.format("Tool %s already defined.", name));
+    public Agent addResource(String name, ResourceType type, Object instance) {
+        if (resources.get(type).containsKey(name)) {
+            throw new IllegalArgumentException(String.format("%s %s already defined.", type, name));
         }
-        resources.get(ResourceType.TOOL).put(name, tool);
-        return this;
-    }
 
-    /**
-     * Add chat model connection to agent.
-     *
-     * @param name The name indicate the prompt.
-     * @param descriptor The resource descriptor of the chat model connection.
-     */
-    public Agent addChatModelConnection(String name, ResourceDescriptor descriptor) {
-        addResource(name, ResourceType.CHAT_MODEL_CONNECTION, descriptor);
-        return this;
-    }
-
-    /**
-     * Add chat model setup to agent.
-     *
-     * @param name The name indicate the prompt.
-     * @param descriptor The resource descriptor of the chat model setup.
-     */
-    public Agent addChatModelSetup(String name, ResourceDescriptor descriptor) {
-        addResource(name, ResourceType.CHAT_MODEL, descriptor);
-        return this;
-    }
-
-    private void addResource(String name, ResourceType type, ResourceDescriptor descriptor) {
-        if (resources.get(type).containsKey(name)) {
+        if (instance instanceof Method) {

Review Comment:
   Let's not assume all methods are tools. We may introduce a `Tool.fromMethod()` for users to explicitly passing in a tool.



-- 
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