| | |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.zy.ai.domain.autotune.AutoTuneTriggerType; |
| | | import com.zy.ai.entity.AiPromptTemplate; |
| | | import com.zy.ai.entity.ChatCompletionRequest; |
| | | import com.zy.ai.entity.ChatCompletionResponse; |
| | |
| | | } |
| | | |
| | | for (ChatCompletionRequest.ToolCall toolCall : toolCalls) { |
| | | Object toolOutput = callMountedTool(toolCall, runState); |
| | | Object toolOutput = callMountedTool(toolCall, runState, normalizedTriggerType); |
| | | messages.add(buildToolMessage(toolCall, toolOutput)); |
| | | } |
| | | } |
| | |
| | | return message; |
| | | } |
| | | |
| | | private Object callMountedTool(ChatCompletionRequest.ToolCall toolCall, RunState runState) { |
| | | private Object callMountedTool(ChatCompletionRequest.ToolCall toolCall, RunState runState, String triggerType) { |
| | | String toolName = resolveToolName(toolCall); |
| | | if (!ALLOWED_TOOL_NAMES.contains(toolName)) { |
| | | throw new IllegalArgumentException("Disallowed auto-tune MCP tool: " + toolName); |
| | | } |
| | | JSONObject arguments = parseArguments(toolCall); |
| | | applySchedulerTriggerType(toolName, triggerType, arguments); |
| | | try { |
| | | Object output = mcpToolManager.callTool(toolName, arguments); |
| | | runState.markToolSuccess(toolName); |
| | |
| | | } |
| | | } |
| | | |
| | | private void applySchedulerTriggerType(String toolName, String triggerType, JSONObject arguments) { |
| | | if (!TOOL_APPLY_CHANGES.equals(toolName)) { |
| | | return; |
| | | } |
| | | if (!AutoTuneTriggerType.AUTO.getCode().equals(triggerType)) { |
| | | return; |
| | | } |
| | | arguments.put("triggerType", AutoTuneTriggerType.AUTO.getCode()); |
| | | } |
| | | |
| | | private ChatCompletionRequest.Message buildToolMessage(ChatCompletionRequest.ToolCall toolCall, Object toolOutput) { |
| | | ChatCompletionRequest.Message toolMessage = new ChatCompletionRequest.Message(); |
| | | toolMessage.setRole("tool"); |