Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -31,109 +31,11 @@ public enum PromptEnum {
AGENT_STUCK_ERROR("AGENT_STUCK_ERROR", MessageType.SYSTEM, PromptType.AGENT, true, "agent/stuck-error.txt"),
SUMMARY_PLAN_TEMPLATE("SUMMARY_PLAN_TEMPLATE", MessageType.SYSTEM, PromptType.PLANNING, true,
"workflow/summary-plan-template.txt"),
MAPREDUCE_TOOL_DESCRIPTION("MAPREDUCE_TOOL_DESCRIPTION", MessageType.SYSTEM, PromptType.AGENT, true,
"tool/mapreduce-tool-description.txt"),
MAPREDUCE_TOOL_PARAMETERS("MAPREDUCE_TOOL_PARAMETERS", MessageType.SYSTEM, PromptType.AGENT, true,
"tool/mapreduce-tool-parameters.txt"),
AGENT_DEBUG_DETAIL_OUTPUT("AGENT_DEBUG_DETAIL_OUTPUT", MessageType.SYSTEM, PromptType.AGENT, true,
"agent/debug-detail-output.txt"),
AGENT_NORMAL_OUTPUT("AGENT_NORMAL_OUTPUT", MessageType.SYSTEM, PromptType.AGENT, true, "agent/normal-output.txt"),
AGENT_PARALLEL_TOOL_CALLS_RESPONSE("AGENT_PARALLEL_TOOL_CALLS_RESPONSE", MessageType.SYSTEM, PromptType.AGENT, true,
"agent/parallel-tool-calls-response.txt"),
FORM_INPUT_TOOL_DESCRIPTION("FORM_INPUT_TOOL_DESCRIPTION", MessageType.SYSTEM, PromptType.AGENT, true,
"tool/form-input-tool-description.txt"),
FORM_INPUT_TOOL_PARAMETERS("FORM_INPUT_TOOL_PARAMETERS", MessageType.SYSTEM, PromptType.AGENT, true,
"tool/form-input-tool-parameters.txt"),

// Bash Tool
BASH_TOOL_DESCRIPTION("BASH_TOOL_DESCRIPTION", MessageType.SYSTEM, PromptType.TOOL_DESCRIPTION, true,
"tool/bash-tool-description.txt"),
BASH_TOOL_PARAMETERS("BASH_TOOL_PARAMETERS", MessageType.SYSTEM, PromptType.TOOL_PARAMETER, true,
"tool/bash-tool-parameters.txt"),

// Text File Operator Tool
TEXTFILEOPERATOR_TOOL_DESCRIPTION("TEXTFILEOPERATOR_TOOL_DESCRIPTION", MessageType.SYSTEM,
PromptType.TOOL_DESCRIPTION, true, "tool/textfileoperator-tool-description.txt"),
TEXTFILEOPERATOR_TOOL_PARAMETERS("TEXTFILEOPERATOR_TOOL_PARAMETERS", MessageType.SYSTEM, PromptType.TOOL_PARAMETER,
true, "tool/textfileoperator-tool-parameters.txt"),

// Browser Use Tool
BROWSER_USE_TOOL_DESCRIPTION("BROWSER_USE_TOOL_DESCRIPTION", MessageType.SYSTEM, PromptType.TOOL_DESCRIPTION, true,
"tool/browser-use-tool-description.txt"),
BROWSER_USE_TOOL_PARAMETERS("BROWSER_USE_TOOL_PARAMETERS", MessageType.SYSTEM, PromptType.TOOL_PARAMETER, true,
"tool/browser-use-tool-parameters.txt"),

// Python Execute Tool
PYTHON_EXECUTE_TOOL_DESCRIPTION("PYTHON_EXECUTE_TOOL_DESCRIPTION", MessageType.SYSTEM, PromptType.TOOL_DESCRIPTION,
true, "tool/python-execute-tool-description.txt"),
PYTHON_EXECUTE_TOOL_PARAMETERS("PYTHON_EXECUTE_TOOL_PARAMETERS", MessageType.SYSTEM, PromptType.TOOL_PARAMETER,
true, "tool/python-execute-tool-parameters.txt"),

// Database Use Tool
DATABASE_USE_TOOL_DESCRIPTION("DATABASE_USE_TOOL_DESCRIPTION", MessageType.SYSTEM, PromptType.TOOL_DESCRIPTION,
true, "tool/database-use-tool-description.txt"),
DATABASE_USE_TOOL_PARAMETERS("DATABASE_USE_TOOL_PARAMETERS", MessageType.SYSTEM, PromptType.TOOL_PARAMETER, true,
"tool/database-use-tool-parameters.txt"),

// Cron Tool
CRON_TOOL_TOOL_DESCRIPTION("CRON_TOOL_TOOL_DESCRIPTION", MessageType.SYSTEM, PromptType.TOOL_DESCRIPTION, true,
"tool/cron-tool-tool-description.txt"),
CRON_TOOL_TOOL_PARAMETERS("CRON_TOOL_TOOL_PARAMETERS", MessageType.SYSTEM, PromptType.TOOL_PARAMETER, true,
"tool/cron-tool-tool-parameters.txt"),

// Inner Storage Content Tool
INNER_STORAGE_CONTENT_TOOL_TOOL_DESCRIPTION("INNER_STORAGE_CONTENT_TOOL_TOOL_DESCRIPTION", MessageType.SYSTEM,
PromptType.TOOL_DESCRIPTION, true, "tool/inner-storage-content-tool-tool-description.txt"),
INNER_STORAGE_CONTENT_TOOL_TOOL_PARAMETERS("INNER_STORAGE_CONTENT_TOOL_TOOL_PARAMETERS", MessageType.SYSTEM,
PromptType.TOOL_PARAMETER, true, "tool/inner-storage-content-tool-tool-parameters.txt"),

// Doc Loader Tool
DOC_LOADER_TOOL_DESCRIPTION("DOC_LOADER_TOOL_DESCRIPTION", MessageType.SYSTEM, PromptType.TOOL_DESCRIPTION, true,
"tool/doc-loader-tool-description.txt"),
DOC_LOADER_TOOL_PARAMETERS("DOC_LOADER_TOOL_PARAMETERS", MessageType.SYSTEM, PromptType.TOOL_PARAMETER, true,
"tool/doc-loader-tool-parameters.txt"),

// File Merge Tool
FILE_MERGE_TOOL_TOOL_DESCRIPTION("FILE_MERGE_TOOL_TOOL_DESCRIPTION", MessageType.SYSTEM,
PromptType.TOOL_DESCRIPTION, true, "tool/file-merge-tool-description.txt"),
FILE_MERGE_TOOL_TOOL_PARAMETERS("FILE_MERGE_TOOL_TOOL_PARAMETERS", MessageType.SYSTEM, PromptType.TOOL_PARAMETER,
true, "tool/file-merge-tool-parameters.txt"),

// Data Split Tool
DATA_SPLIT_TOOL_DESCRIPTION("DATA_SPLIT_TOOL_DESCRIPTION", MessageType.SYSTEM, PromptType.TOOL_DESCRIPTION, true,
"tool/data-split-tool-description.txt"),
DATA_SPLIT_TOOL_PARAMETERS("DATA_SPLIT_TOOL_PARAMETERS", MessageType.SYSTEM, PromptType.TOOL_PARAMETER, true,
"tool/data-split-tool-parameters.txt"),

// Map Output Tool
MAP_OUTPUT_TOOL_DESCRIPTION("MAP_OUTPUT_TOOL_DESCRIPTION", MessageType.SYSTEM, PromptType.TOOL_DESCRIPTION, true,
"tool/map-output-tool-description.txt"),
MAP_OUTPUT_TOOL_PARAMETERS("MAP_OUTPUT_TOOL_PARAMETERS", MessageType.SYSTEM, PromptType.TOOL_PARAMETER, true,
"tool/map-output-tool-parameters.txt"),

// Reduce Operation Tool
REDUCE_OPERATION_TOOL_DESCRIPTION("REDUCE_OPERATION_TOOL_DESCRIPTION", MessageType.SYSTEM,
PromptType.TOOL_DESCRIPTION, true, "tool/reduce-operation-tool-description.txt"),
REDUCE_OPERATION_TOOL_PARAMETERS("REDUCE_OPERATION_TOOL_PARAMETERS", MessageType.SYSTEM, PromptType.TOOL_PARAMETER,
true, "tool/reduce-operation-tool-parameters.txt"),

// Finalize Tool
FINALIZE_TOOL_DESCRIPTION("FINALIZE_TOOL_DESCRIPTION", MessageType.SYSTEM, PromptType.TOOL_DESCRIPTION, true,
"tool/finalize-tool-description.txt"),
FINALIZE_TOOL_PARAMETERS("FINALIZE_TOOL_PARAMETERS", MessageType.SYSTEM, PromptType.TOOL_PARAMETER, true,
"tool/finalize-tool-parameters.txt"),

// Terminate Tool
TERMINATE_TOOL_DESCRIPTION("TERMINATE_TOOL_DESCRIPTION", MessageType.SYSTEM, PromptType.TOOL_DESCRIPTION, true,
"tool/terminate-tool-description.txt"),
TERMINATE_TOOL_PARAMETERS("TERMINATE_TOOL_PARAMETERS", MessageType.SYSTEM, PromptType.TOOL_PARAMETER, true,
"tool/terminate-tool-parameters.txt"),

// PPT Generator Tool
PPTGENERATOROPERATOR_TOOL_DESCRIPTION("PPTGENERATOROPERATOR_TOOL_DESCRIPTION", MessageType.SYSTEM,
PromptType.TOOL_DESCRIPTION, true, "tool/ppt-generator-operator-tool-description.txt"),
PPTGENERATOROPERATOR_TOOL_PARAMETERS("PPTGENERATOROPERATOR_TOOL_PARAMETERS", MessageType.SYSTEM,
PromptType.TOOL_PARAMETER, true, "tool/ppt-generator-operator-tool-parameters.txt");
"agent/parallel-tool-calls-response.txt");

private String promptName;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@

public enum PromptType {

LLM, PLANNING, AGENT, TOOL_DESCRIPTION, TOOL_PARAMETER
LLM, PLANNING, AGENT

}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import java.util.Map;
import java.util.concurrent.TimeUnit;

import com.alibaba.cloud.ai.example.manus.tool.ToolPromptManager;
import org.apache.hc.client5.http.classic.HttpClient;
import org.apache.hc.client5.http.config.RequestConfig;
import org.apache.hc.client5.http.impl.classic.HttpClients;
Expand Down Expand Up @@ -144,9 +143,6 @@ public class PlanningFactory implements IPlanningFactory {
@Autowired
private StreamingResponseHandler streamingResponseHandler;

@Autowired
private ToolPromptManager toolPromptManager;

@Autowired
@Lazy
private CronService cronService;
Expand Down Expand Up @@ -222,29 +218,26 @@ public Map<String, ToolCallBackContext> toolCallbackMap(String planId, String ro
return toolCallbackMap;
}
// Add all tool definitions
toolDefinitions
.add(BrowserUseTool.getInstance(chromeDriverService, innerStorageService, objectMapper, toolPromptManager));
toolDefinitions.add(DatabaseUseTool.getInstance(dataSourceService, objectMapper, toolPromptManager));
toolDefinitions.add(new TerminateTool(planId, terminateColumns, toolPromptManager));
toolDefinitions.add(new Bash(unifiedDirectoryManager, objectMapper, toolPromptManager));
toolDefinitions.add(new DocLoaderTool(toolPromptManager));
toolDefinitions
.add(new TextFileOperator(textFileService, innerStorageService, objectMapper, toolPromptManager));
toolDefinitions.add(BrowserUseTool.getInstance(chromeDriverService, innerStorageService, objectMapper));
toolDefinitions.add(DatabaseUseTool.getInstance(dataSourceService, objectMapper));
toolDefinitions.add(new TerminateTool(planId, terminateColumns));
toolDefinitions.add(new Bash(unifiedDirectoryManager, objectMapper));
toolDefinitions.add(new DocLoaderTool());
toolDefinitions.add(new TextFileOperator(textFileService, innerStorageService, objectMapper));
// toolDefinitions.add(new InnerStorageTool(unifiedDirectoryManager));
toolDefinitions
.add(new InnerStorageContentTool(unifiedDirectoryManager, summaryWorkflow, recorder, toolPromptManager));
toolDefinitions.add(new FileMergeTool(unifiedDirectoryManager, toolPromptManager));
toolDefinitions.add(new InnerStorageContentTool(unifiedDirectoryManager, summaryWorkflow, recorder));
toolDefinitions.add(new FileMergeTool(unifiedDirectoryManager));
// toolDefinitions.add(new GoogleSearch());
// toolDefinitions.add(new PythonExecute());
toolDefinitions.add(new FormInputTool(objectMapper, promptService));
toolDefinitions.add(new FormInputTool(objectMapper));
toolDefinitions
.add(new DataSplitTool(planId, manusProperties, sharedStateManager, unifiedDirectoryManager, objectMapper));
toolDefinitions.add(new MapOutputTool(planId, manusProperties, sharedStateManager, unifiedDirectoryManager,
terminateColumns, objectMapper));
toolDefinitions.add(new ReduceOperationTool(planId, manusProperties, sharedStateManager,
unifiedDirectoryManager, terminateColumns));
toolDefinitions.add(new FinalizeTool(planId, manusProperties, sharedStateManager, unifiedDirectoryManager));
toolDefinitions.add(new CronTool(cronService, objectMapper, toolPromptManager));
toolDefinitions.add(new CronTool(cronService, objectMapper));
toolDefinitions.add(pptGeneratorOperator);

List<McpServiceEntity> functionCallbacks = mcpService.getFunctionCallbacks(planId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,6 @@ public void setFilePath(String filePath) {

private static final String name = "doc_loader";

private final ToolPromptManager toolPromptManager;

public OpenAiApi.FunctionTool getToolDefinition() {
String description = getDescription();
String parameters = getParameters();
Expand All @@ -82,21 +80,21 @@ public OpenAiApi.FunctionTool getToolDefinition() {
/**
* Get FunctionToolCallback for Spring AI
*/
public static FunctionToolCallback<DocLoaderInput, ToolExecuteResult> getFunctionToolCallback(
ToolPromptManager toolPromptManager) {
public static FunctionToolCallback<DocLoaderInput, ToolExecuteResult> getFunctionToolCallback() {
return FunctionToolCallback
.<DocLoaderInput, ToolExecuteResult>builder(name,
(DocLoaderInput input,
org.springframework.ai.chat.model.ToolContext context) -> new DocLoaderTool(
toolPromptManager)
.run(input))
.description(toolPromptManager.getToolDescription("doc_loader"))
(DocLoaderInput input, org.springframework.ai.chat.model.ToolContext context) -> new DocLoaderTool()
.run(input))
.description("""
Get the content information of a local file at a specified path.
Use this tool when you want to get some related information asked by the user.
This tool accepts the file path and gets the related information content.
""")
.inputType(DocLoaderInput.class)
.build();
}

public DocLoaderTool(ToolPromptManager toolPromptManager) {
this.toolPromptManager = toolPromptManager;
public DocLoaderTool() {
}

private String lastFilePath = "";
Expand Down Expand Up @@ -145,12 +143,31 @@ public String getName() {

@Override
public String getDescription() {
return toolPromptManager.getToolDescription("doc_loader");
return """
Get the content information of a local file at a specified path.
Use this tool when you want to get some related information asked by the user.
This tool accepts the file path and gets the related information content.
""";
}

@Override
public String getParameters() {
return toolPromptManager.getToolParameters("doc_loader");
return """
{
"type": "object",
"properties": {
"file_type": {
"type": "string",
"description": "(required) File type, only support pdf file."
},
"file_path": {
"type": "string",
"description": "(required) Get the absolute path of the file from the user request."
}
},
"required": ["file_type", "file_path"]
}
""";
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
*/
package com.alibaba.cloud.ai.example.manus.tool;

import com.alibaba.cloud.ai.example.manus.dynamic.prompt.service.PromptService;
import com.alibaba.cloud.ai.example.manus.tool.code.ToolExecuteResult;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
Expand All @@ -36,28 +35,65 @@ public class FormInputTool extends AbstractBaseTool<FormInputTool.UserFormInput>

private final ObjectMapper objectMapper;

private final PromptService promptService;

private static final Logger log = LoggerFactory.getLogger(FormInputTool.class);

private String getToolParameters() {
try {
return promptService.getPromptByName("FORM_INPUT_TOOL_PARAMETERS").getPromptContent();
}
catch (Exception e) {
log.warn("Failed to load prompt-based tool parameters, using legacy configuration", e);
return LEGACY_PARAMETERS;
}
return """
{
"type": "object",
"properties": {
"description": {
"type": "string",
"description": "Description of the form and what information is being collected"
},
"inputs": {
"type": "array",
"items": {
"type": "object",
"properties": {
"name": {
"type": "string",
"description": "Name/ID of the input field"
},
"label": {
"type": "string",
"description": "Display label for the input field"
},
"type": {
"type": "string",
"enum": ["text", "number", "email", "password", "textarea", "select", "checkbox", "radio"],
"description": "Type of input field"
},
"required": {
"type": "boolean",
"description": "Whether this field is required"
},
"placeholder": {
"type": "string",
"description": "Placeholder text for the input field"
},
"options": {
"type": "array",
"items": {
"type": "string"
},
"description": "Options for select, checkbox, or radio inputs"
}
},
"required": ["name", "label", "type"]
},
"description": "Array of input field definitions"
}
},
"required": ["description", "inputs"]
}
""";
}

private String getToolDescription() {
try {
return promptService.getPromptByName("FORM_INPUT_TOOL_DESCRIPTION").getPromptContent();
}
catch (Exception e) {
log.warn("Failed to load prompt-based tool description, using legacy configuration", e);
return LEGACY_DESCRIPTION;
}
return """
Create interactive forms to collect user input. This tool allows you to define form fields and collect structured data from users through a web interface.
""";
}

private static final String LEGACY_PARAMETERS = """
Expand Down Expand Up @@ -180,9 +216,8 @@ public void setDescription(String description) {

}

public FormInputTool(ObjectMapper objectMapper, PromptService promptService) {
public FormInputTool(ObjectMapper objectMapper) {
this.objectMapper = objectMapper;
this.promptService = promptService;
}

public enum InputState {
Expand Down
Loading
Loading