Переглянути джерело

持久化 规划内容和规划步骤信息

alibct 2 місяців тому
батько
коміт
44e70a2b32
16 змінених файлів з 157 додано та 253 видалено
  1. 2 1
      pavis-module-aigc/src/main/java/com/pavis/admin/aigc/core/agent/tool/PlanningTool.java
  2. 1 1
      pavis-module-aigc/src/main/java/com/pavis/admin/aigc/model/entity/AgentPlanDO.java
  3. 1 21
      pavis-module-aigc/src/main/java/com/pavis/admin/aigc/model/entity/AgentPlanStepDO.java
  4. 6 27
      pavis-module-aigc/src/main/java/com/pavis/admin/aigc/model/query/AgentPlanStepQuery.java
  5. 3 54
      pavis-module-aigc/src/main/java/com/pavis/admin/aigc/model/req/AgentPlanReq.java
  6. 0 30
      pavis-module-aigc/src/main/java/com/pavis/admin/aigc/model/req/AgentPlanStepReq.java
  7. 1 1
      pavis-module-aigc/src/main/java/com/pavis/admin/aigc/model/resp/AgentPlanDetailResp.java
  8. 1 1
      pavis-module-aigc/src/main/java/com/pavis/admin/aigc/model/resp/AgentPlanResp.java
  9. 3 34
      pavis-module-aigc/src/main/java/com/pavis/admin/aigc/model/resp/AgentPlanStepDetailResp.java
  10. 1 25
      pavis-module-aigc/src/main/java/com/pavis/admin/aigc/model/resp/AgentPlanStepResp.java
  11. 18 2
      pavis-module-aigc/src/main/java/com/pavis/admin/aigc/service/AgentPlanService.java
  12. 11 1
      pavis-module-aigc/src/main/java/com/pavis/admin/aigc/service/AgentPlanStepService.java
  13. 68 10
      pavis-module-aigc/src/main/java/com/pavis/admin/aigc/service/impl/AgentPlanServiceImpl.java
  14. 19 6
      pavis-module-aigc/src/main/java/com/pavis/admin/aigc/service/impl/AgentPlanStepServiceImpl.java
  15. 3 14
      pavis-webapi/src/main/java/com/pavis/admin/controller/aigc/AgentPlanController.java
  16. 19 25
      pavis-webapi/src/main/resources/db/changelog/mysql/main_table.sql

+ 2 - 1
pavis-module-aigc/src/main/java/com/pavis/admin/aigc/core/agent/tool/PlanningTool.java

@@ -158,7 +158,8 @@ public class PlanningTool implements Function<Map<String, Object>, ToolExecuteRe
         // 使用创建并添加步骤
         for (int i = 0; i < steps.size(); i++) {
             AgentPlanStepResp planStepResp = new AgentPlanStepResp();
-            planStepResp.setOrder(i);
+            planStepResp.setPlanId(planId);
+            planStepResp.setStepIndex(i);
             planStepResp.setDescription(steps.get(i));
             planSteps.add(planStepResp);
         }

+ 1 - 1
pavis-module-aigc/src/main/java/com/pavis/admin/aigc/model/entity/AgentPlanDO.java

@@ -71,7 +71,7 @@ public class AgentPlanDO extends BaseDO {
     /**
      * 规划时长(秒)
      */
-    private Integer duration;
+    private Long duration;
 
     /**
      * 当前执行的步骤编号

+ 1 - 21
pavis-module-aigc/src/main/java/com/pavis/admin/aigc/model/entity/AgentPlanStepDO.java

@@ -27,26 +27,6 @@ public class AgentPlanStepDO extends BaseDO {
      */
     private Long planId;
 
-    /**
-     * 所属会话ID
-     */
-    private Long conversationId;
-
-    /**
-     * 对话消息Id
-     */
-    private Long messageId;
-
-    /**
-     * 对话消息内容
-     */
-    private String messageContent;
-
-    /**
-     * 计划主题,大模型根据用户消息生成
-     */
-    private String title;
-
     /**
      * 计划描述:[BROWSER_AGENT] 打开百度主页
      */
@@ -55,7 +35,7 @@ public class AgentPlanStepDO extends BaseDO {
     /**
      * 步骤序号
      */
-    private Integer order;
+    private Integer stepIndex;
 
     /**
      * 本次计划关联的智能体ID

+ 6 - 27
pavis-module-aigc/src/main/java/com/pavis/admin/aigc/model/query/AgentPlanStepQuery.java

@@ -31,39 +31,18 @@ public class AgentPlanStepQuery implements Serializable {
     private Long planId;
 
     /**
-     * 所属会话ID
-     */
-    @Schema(description = "所属会话ID")
-    @Query(type = QueryType.EQ)
-    private Long conversationId;
-
-    /**
-     * 对话消息Id
-     */
-    @Schema(description = "对话消息Id")
-    @Query(type = QueryType.EQ)
-    private Long messageId;
-
-    /**
-     * 对话消息内容
-     */
-    @Schema(description = "对话消息内容")
-    @Query(type = QueryType.EQ)
-    private String messageContent;
-
-    /**
-     * 计划主题,大模型根据用户消息生成
+     * 计划描述:[BROWSER_AGENT] 打开百度主页
      */
-    @Schema(description = "计划主题,大模型根据用户消息生成")
+    @Schema(description = "计划描述:[BROWSER_AGENT] 打开百度主页")
     @Query(type = QueryType.EQ)
-    private String title;
+    private String description;
 
     /**
-     * 计划描述:[BROWSER_AGENT] 打开百度主页
+     * 步骤序号
      */
-    @Schema(description = "计划描述:[BROWSER_AGENT] 打开百度主页")
+    @Schema(description = "步骤序号")
     @Query(type = QueryType.EQ)
-    private String description;
+    private Integer stepIndex;
 
     /**
      * 本次计划关联的智能体ID

+ 3 - 54
pavis-module-aigc/src/main/java/com/pavis/admin/aigc/model/req/AgentPlanReq.java

@@ -1,15 +1,12 @@
 package com.pavis.admin.aigc.model.req;
 
-import jakarta.validation.constraints.*;
-
-import lombok.Data;
-
 import io.swagger.v3.oas.annotations.media.Schema;
-
+import jakarta.validation.constraints.NotBlank;
+import lombok.Data;
 import org.hibernate.validator.constraints.Length;
+
 import java.io.Serial;
 import java.io.Serializable;
-import java.time.*;
 
 /**
  * 智能体规划记录创建或修改参数
@@ -28,21 +25,18 @@ public class AgentPlanReq implements Serializable {
      * 用户ID
      */
     @Schema(description = "用户ID")
-    @NotNull(message = "用户ID不能为空")
     private Long userId;
 
     /**
      * 所属会话ID
      */
     @Schema(description = "所属会话ID")
-    @NotNull(message = "所属会话ID不能为空")
     private Long conversationId;
 
     /**
      * 对话消息Id
      */
     @Schema(description = "对话消息Id")
-    @NotNull(message = "对话消息Id不能为空")
     private Long messageId;
 
     /**
@@ -52,49 +46,4 @@ public class AgentPlanReq implements Serializable {
     @NotBlank(message = "对话消息内容不能为空")
     @Length(max = 2147483647, message = "对话消息内容长度不能超过 {max} 个字符")
     private String messageContent;
-
-    /**
-     * 规划思考过程内容输入
-     */
-    @Schema(description = "规划思考过程内容输入")
-    @NotBlank(message = "规划思考过程内容输入不能为空")
-    @Length(max = 2147483647, message = "规划思考过程内容输入长度不能超过 {max} 个字符")
-    private String think_input;
-
-    /**
-     * 规划思考过程内容输入
-     */
-    @Schema(description = "规划思考过程内容输出")
-    @NotBlank(message = "规划思考过程内容输出不能为空")
-    @Length(max = 2147483647, message = "规划思考过程内容输出长度不能超过 {max} 个字符")
-    private String think_output;
-
-    /**
-     * 计划主题,大模型根据用户消息生成
-     */
-    @Schema(description = "计划主题,大模型根据用户消息生成")
-    @NotBlank(message = "计划主题,大模型根据用户消息生成不能为空")
-    @Length(max = 500, message = "计划主题,大模型根据用户消息生成长度不能超过 {max} 个字符")
-    private String title;
-
-    /**
-     * 开始时间
-     */
-    @Schema(description = "开始时间")
-    @NotNull(message = "开始时间不能为空")
-    private LocalDateTime startTime;
-
-    /**
-     * 创建人
-     */
-    @Schema(description = "创建人")
-    @NotNull(message = "创建人不能为空")
-    private Long createUser;
-
-    /**
-     * 创建时间
-     */
-    @Schema(description = "创建时间")
-    @NotNull(message = "创建时间不能为空")
-    private LocalDateTime createTime;
 }

+ 0 - 30
pavis-module-aigc/src/main/java/com/pavis/admin/aigc/model/req/AgentPlanStepReq.java

@@ -31,36 +31,6 @@ public class AgentPlanStepReq implements Serializable {
     @NotNull(message = "计划ID不能为空")
     private Long planId;
 
-    /**
-     * 所属会话ID
-     */
-    @Schema(description = "所属会话ID")
-    @NotNull(message = "所属会话ID不能为空")
-    private Long conversationId;
-
-    /**
-     * 对话消息Id
-     */
-    @Schema(description = "对话消息Id")
-    @NotNull(message = "对话消息Id不能为空")
-    private Long messageId;
-
-    /**
-     * 对话消息内容
-     */
-    @Schema(description = "对话消息内容")
-    @NotBlank(message = "对话消息内容不能为空")
-    @Length(max = 2147483647, message = "对话消息内容长度不能超过 {max} 个字符")
-    private String messageContent;
-
-    /**
-     * 计划主题,大模型根据用户消息生成
-     */
-    @Schema(description = "计划主题,大模型根据用户消息生成")
-    @NotBlank(message = "计划主题,大模型根据用户消息生成不能为空")
-    @Length(max = 500, message = "计划主题,大模型根据用户消息生成长度不能超过 {max} 个字符")
-    private String title;
-
     /**
      * 计划描述:[BROWSER_AGENT] 打开百度主页
      */

+ 1 - 1
pavis-module-aigc/src/main/java/com/pavis/admin/aigc/model/resp/AgentPlanDetailResp.java

@@ -94,7 +94,7 @@ public class AgentPlanDetailResp extends BaseDetailResp {
      */
     @Schema(description = "执行时长(秒)")
     @ExcelProperty(value = "执行时长(秒)")
-    private Integer duration;
+    private Long duration;
 
     /**
      * 当前执行的步骤编号

+ 1 - 1
pavis-module-aigc/src/main/java/com/pavis/admin/aigc/model/resp/AgentPlanResp.java

@@ -82,7 +82,7 @@ public class AgentPlanResp extends BaseResp {
      * 执行时长(秒)
      */
     @Schema(description = "执行时长(秒)")
-    private Integer duration;
+    private Long duration;
 
     /**
      * 当前执行的步骤编号

+ 3 - 34
pavis-module-aigc/src/main/java/com/pavis/admin/aigc/model/resp/AgentPlanStepDetailResp.java

@@ -1,15 +1,12 @@
 package com.pavis.admin.aigc.model.resp;
 
-import lombok.Data;
-
-import io.swagger.v3.oas.annotations.media.Schema;
-
 import com.alibaba.excel.annotation.ExcelIgnoreUnannotated;
 import com.alibaba.excel.annotation.ExcelProperty;
-
 import com.pavis.admin.common.model.resp.BaseDetailResp;
+import io.swagger.v3.oas.annotations.media.Schema;
+import lombok.Data;
+
 import java.io.Serial;
-import java.time.*;
 
 /**
  * 智能体规划步骤记录详情信息
@@ -32,34 +29,6 @@ public class AgentPlanStepDetailResp extends BaseDetailResp {
     @ExcelProperty(value = "计划ID")
     private Long planId;
 
-    /**
-     * 所属会话ID
-     */
-    @Schema(description = "所属会话ID")
-    @ExcelProperty(value = "所属会话ID")
-    private Long conversationId;
-
-    /**
-     * 对话消息Id
-     */
-    @Schema(description = "对话消息Id")
-    @ExcelProperty(value = "对话消息Id")
-    private Long messageId;
-
-    /**
-     * 对话消息内容
-     */
-    @Schema(description = "对话消息内容")
-    @ExcelProperty(value = "对话消息内容")
-    private String messageContent;
-
-    /**
-     * 计划主题,大模型根据用户消息生成
-     */
-    @Schema(description = "计划主题,大模型根据用户消息生成")
-    @ExcelProperty(value = "计划主题,大模型根据用户消息生成")
-    private String title;
-
     /**
      * 计划描述:[BROWSER_AGENT] 打开百度主页
      */

+ 1 - 25
pavis-module-aigc/src/main/java/com/pavis/admin/aigc/model/resp/AgentPlanStepResp.java

@@ -27,30 +27,6 @@ public class AgentPlanStepResp extends BaseResp {
     @Schema(description = "计划ID")
     private Long planId;
 
-    /**
-     * 所属会话ID
-     */
-    @Schema(description = "所属会话ID")
-    private Long conversationId;
-
-    /**
-     * 对话消息Id
-     */
-    @Schema(description = "对话消息Id")
-    private Long messageId;
-
-    /**
-     * 对话消息内容
-     */
-    @Schema(description = "对话消息内容")
-    private String messageContent;
-
-    /**
-     * 计划主题,大模型根据用户消息生成
-     */
-    @Schema(description = "计划主题,大模型根据用户消息生成")
-    private String title;
-
     /**
      * 计划描述:[BROWSER_AGENT] 打开百度主页
      */
@@ -61,7 +37,7 @@ public class AgentPlanStepResp extends BaseResp {
      * 步骤序号
      */
     @Schema(description = "步骤序号")
-    private Integer order;
+    private Integer stepIndex;
 
     /**
      * 本次计划关联的智能体ID

+ 18 - 2
pavis-module-aigc/src/main/java/com/pavis/admin/aigc/service/AgentPlanService.java

@@ -18,10 +18,10 @@ public interface AgentPlanService extends BaseService<AgentPlanResp, AgentPlanDe
     /**
      * 创建计划,仅创建不执行
      *
-     * @param context 计划上下文
+     * @param req 计划请求
      * @return 计划上下文
      */
-    PlanContext createPlan(PlanContext context);
+    PlanContext createPlan(AgentPlanReq req);
 
     /**
      * 计划执行管理,具体执行放在前端插件,这里仅做执行管理
@@ -30,4 +30,20 @@ public interface AgentPlanService extends BaseService<AgentPlanResp, AgentPlanDe
      * @return 计划上下文
      */
     PlanContext executePlan(PlanContext context);
+
+    /**
+     * 根据计划ID获取计划信息
+     *
+     * @param planId 计划ID
+     * @return 计划信息
+     */
+    AgentPlanResp getByPlanId(Long planId);
+
+    /**
+     * 保存或修改计划信息
+     *
+     * @param resp 计划信息
+     * @return 计划信息
+     */
+    AgentPlanResp saveOrUpdate(AgentPlanResp resp);
 }

+ 11 - 1
pavis-module-aigc/src/main/java/com/pavis/admin/aigc/service/AgentPlanStepService.java

@@ -6,10 +6,20 @@ import com.pavis.admin.aigc.model.req.AgentPlanStepReq;
 import com.pavis.admin.aigc.model.resp.AgentPlanStepDetailResp;
 import com.pavis.admin.aigc.model.resp.AgentPlanStepResp;
 
+import java.util.List;
+
 /**
  * 智能体规划步骤记录业务接口
  *
  * @author semi
  * @since 2025/05/29 12:50
  */
-public interface AgentPlanStepService extends BaseService<AgentPlanStepResp, AgentPlanStepDetailResp, AgentPlanStepQuery, AgentPlanStepReq> {}
+public interface AgentPlanStepService extends BaseService<AgentPlanStepResp, AgentPlanStepDetailResp, AgentPlanStepQuery, AgentPlanStepReq> {
+
+    /**
+     * 批量存储计划步骤信息
+     * @param respList  计划步骤信息
+     * @return 是存储成功
+     */
+    boolean saveBatch(List<AgentPlanStepResp> respList);
+}

+ 68 - 10
pavis-module-aigc/src/main/java/com/pavis/admin/aigc/service/impl/AgentPlanServiceImpl.java

@@ -1,18 +1,23 @@
 package com.pavis.admin.aigc.service.impl;
 
+import cn.hutool.core.bean.BeanUtil;
 import com.pavis.admin.aigc.core.agent.planner.PlanContext;
 import com.pavis.admin.aigc.core.agent.tool.PlanningTool;
 import com.pavis.admin.aigc.core.llm.LlmService;
 import com.pavis.admin.aigc.mapper.AgentPlanMapper;
 import com.pavis.admin.aigc.model.entity.AgentPlanDO;
 import com.pavis.admin.aigc.model.query.AgentPlanQuery;
+import com.pavis.admin.aigc.model.query.AgentPlanStepQuery;
 import com.pavis.admin.aigc.model.query.AgentQuery;
 import com.pavis.admin.aigc.model.req.AgentPlanReq;
 import com.pavis.admin.aigc.model.resp.AgentPlanDetailResp;
 import com.pavis.admin.aigc.model.resp.AgentPlanResp;
+import com.pavis.admin.aigc.model.resp.AgentPlanStepResp;
 import com.pavis.admin.aigc.model.resp.AgentResp;
 import com.pavis.admin.aigc.service.AgentPlanService;
+import com.pavis.admin.aigc.service.AgentPlanStepService;
 import com.pavis.admin.aigc.service.AgentService;
+import com.pavis.admin.common.context.UserContextHolder;
 import lombok.RequiredArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.ai.chat.client.ChatClient;
@@ -22,6 +27,8 @@ import org.springframework.stereotype.Service;
 import top.continew.starter.extension.crud.model.query.SortQuery;
 import top.continew.starter.extension.crud.service.BaseServiceImpl;
 
+import java.time.Duration;
+import java.time.LocalDateTime;
 import java.util.List;
 
 /**
@@ -39,25 +46,38 @@ public class AgentPlanServiceImpl extends BaseServiceImpl<AgentPlanMapper, Agent
 
     private final AgentService agentService;
 
+    private final AgentPlanStepService agentPlanStepService;
+
     @Override
-    public PlanContext createPlan(PlanContext context) {
-        Long planId = context.getPlanId();
+    public PlanContext createPlan(AgentPlanReq req) {
+        // 获取userId
+        Long userId = UserContextHolder.getUserId();
+        req.setUserId(userId);
+        // 先做持久化获取planId
+        Long planId = super.create(req);
         if (planId == null) {
             throw new IllegalArgumentException("Plan ID cannot be null or empty");
         }
+        // 创建规划上下文
+        PlanContext context = new PlanContext();
+        context.setPlanId(planId);
+        context.setConversationId(req.getConversationId());
+        context.setMessageId(req.getMessageId());
+        context.setUserMessage(req.getMessageContent());
+        AgentPlanResp currentPlan = this.getByPlanId(planId);
         try {
             // 构建所有智能体信息
             String agentsInfo = buildAgentsInfo();
-            AgentPlanResp currentPlan = null;
             // 生成计划提示
             String planPrompt = generatePlanPrompt(context.getUserMessage(), agentsInfo, planId);
+            currentPlan.setThink_input(planPrompt);
             // 使用 LLM 生成计划
             PromptTemplate promptTemplate = new PromptTemplate(planPrompt);
             Prompt prompt = promptTemplate.create();
 
             // 创建 规划工具 PlanningTool
             PlanningTool planningTool = new PlanningTool();
-
+            currentPlan.setStartTime(LocalDateTime.now());
             ChatClient.CallResponseSpec response = llmService.getPlanningChatClient()
                     .prompt(prompt)
                     .toolCallbacks(List.of(planningTool.getFunctionToolCallback()))
@@ -67,13 +87,15 @@ public class AgentPlanServiceImpl extends BaseServiceImpl<AgentPlanMapper, Agent
             String outputText = response.chatResponse().getResult().getOutput().getText();
             // 检查计划是否创建成功
             if (planId.equals(planningTool.getCurrentPlanId())) {
-                currentPlan = planningTool.getCurrentPlan();
-                log.info("Plan created successfully: {}", currentPlan);
-                currentPlan.setThink_input(planPrompt);
                 currentPlan.setThink_output(outputText);
+                currentPlan.setEndTime(LocalDateTime.now());
+                currentPlan.setDuration(Duration.between(currentPlan.getStartTime(),currentPlan.getEndTime()).getSeconds());
+                currentPlan.setTitle(planningTool.getCurrentPlan().getTitle());
+                currentPlan.setSteps(planningTool.getCurrentPlan().getSteps());
             }
-            context.setPlan(currentPlan);
-
+            // 更新或存储计划信息
+            AgentPlanResp savedPlan = this.saveOrUpdate(currentPlan);
+            context.setPlan(savedPlan);
         } catch (Exception e) {
             log.error("Error creating plan for request: {}", context.getUserMessage(), e);
             // 处理异常情况
@@ -84,7 +106,43 @@ public class AgentPlanServiceImpl extends BaseServiceImpl<AgentPlanMapper, Agent
 
     @Override
     public PlanContext executePlan(PlanContext context) {
-        return null;
+        // 获取规划信息
+        AgentPlanResp currentPlan = context.getPlan();
+        // 获取当前规划的所有执行步骤
+        List<AgentPlanStepResp> currentPlanSteps = currentPlan.getSteps();
+        // 开始按照计划步骤生成具体的执行内容
+        for (AgentPlanStepResp currentPlanStep : currentPlanSteps) {
+            log.info("Current Plan step: {}", currentPlanStep);
+        }
+        context.setSuccess(true);
+        return context;
+    }
+
+    @Override
+    public AgentPlanResp getByPlanId(Long planId) {
+        return baseMapper.lambdaQuery()
+                .eq(AgentPlanDO::getId, planId)
+                .oneOpt()
+                .map(agentPlanDO -> BeanUtil.copyProperties(agentPlanDO, AgentPlanResp.class))
+                .orElse(null);
+    }
+
+    @Override
+    public AgentPlanResp saveOrUpdate(AgentPlanResp resp) {
+        AgentPlanDO agentPlanDO = baseMapper.selectById(resp.getId());
+        BeanUtil.copyProperties(resp, agentPlanDO);
+        log.info("Copied plan: {}", agentPlanDO);
+        baseMapper.updateById(agentPlanDO);
+        // 保存计划步骤
+        boolean result = agentPlanStepService.saveBatch(resp.getSteps());
+        if (result) {
+            AgentPlanStepQuery query = new AgentPlanStepQuery();
+            query.setPlanId(resp.getId());
+            SortQuery sortQuery = new SortQuery();
+            List<AgentPlanStepResp> list = agentPlanStepService.list(query, sortQuery);
+            resp.setSteps(list);
+        }
+        return resp;
     }
 
     /**

+ 19 - 6
pavis-module-aigc/src/main/java/com/pavis/admin/aigc/service/impl/AgentPlanStepServiceImpl.java

@@ -1,10 +1,6 @@
 package com.pavis.admin.aigc.service.impl;
 
-import lombok.RequiredArgsConstructor;
-
-import org.springframework.stereotype.Service;
-
-import top.continew.starter.extension.crud.service.BaseServiceImpl;
+import cn.hutool.core.bean.BeanUtil;
 import com.pavis.admin.aigc.mapper.AgentPlanStepMapper;
 import com.pavis.admin.aigc.model.entity.AgentPlanStepDO;
 import com.pavis.admin.aigc.model.query.AgentPlanStepQuery;
@@ -12,6 +8,12 @@ import com.pavis.admin.aigc.model.req.AgentPlanStepReq;
 import com.pavis.admin.aigc.model.resp.AgentPlanStepDetailResp;
 import com.pavis.admin.aigc.model.resp.AgentPlanStepResp;
 import com.pavis.admin.aigc.service.AgentPlanStepService;
+import lombok.RequiredArgsConstructor;
+import org.springframework.stereotype.Service;
+import top.continew.starter.extension.crud.service.BaseServiceImpl;
+
+import java.util.ArrayList;
+import java.util.List;
 
 /**
  * 智能体规划步骤记录业务实现
@@ -21,4 +23,15 @@ import com.pavis.admin.aigc.service.AgentPlanStepService;
  */
 @Service
 @RequiredArgsConstructor
-public class AgentPlanStepServiceImpl extends BaseServiceImpl<AgentPlanStepMapper, AgentPlanStepDO, AgentPlanStepResp, AgentPlanStepDetailResp, AgentPlanStepQuery, AgentPlanStepReq> implements AgentPlanStepService {}
+public class AgentPlanStepServiceImpl extends BaseServiceImpl<AgentPlanStepMapper, AgentPlanStepDO, AgentPlanStepResp, AgentPlanStepDetailResp, AgentPlanStepQuery, AgentPlanStepReq> implements AgentPlanStepService {
+    @Override
+    public boolean saveBatch(List<AgentPlanStepResp> respList) {
+        List<AgentPlanStepDO> planStepDOList = new ArrayList<>();
+        for (AgentPlanStepResp planStepResp : respList) {
+            AgentPlanStepDO planStepDO = new AgentPlanStepDO();
+            BeanUtil.copyProperties(planStepResp, planStepDO);
+            planStepDOList.add(planStepDO);
+        }
+        return baseMapper.insertBatch(planStepDOList);
+    }
+}

+ 3 - 14
pavis-webapi/src/main/java/com/pavis/admin/controller/aigc/AgentPlanController.java

@@ -15,8 +15,6 @@ import org.springframework.web.bind.annotation.RestController;
 import top.continew.starter.extension.crud.annotation.CrudRequestMapping;
 import top.continew.starter.extension.crud.enums.Api;
 
-import java.util.Map;
-
 /**
  * 智能体规划记录管理 API
  *
@@ -34,21 +32,12 @@ public class AgentPlanController extends BaseController<AgentPlanService, AgentP
     /**
      * 生成计划
      *
-     * @param request 用户请求JSON信息
+     * @param req 用户请求的规划JSON信息
      * @return 计划上下文信息
      */
     @PostMapping("/generate")
-    public PlanContext generatePlan(@RequestBody Map<String, Object> request) {
-        Long conversationId = (Long) request.get("conversationId");
-        Long messageId = (Long) request.get("messageId");
-        Long planId = (Long) request.get("planId");
-        String userMessage = (String) request.get("userMessage");
-        PlanContext context = new PlanContext();
-        context.setConversationId(conversationId);
-        context.setMessageId(messageId);
-        context.setPlanId(planId);
-        context.setUserMessage(userMessage);
-        return agentPlanService.createPlan(context);
+    public PlanContext generatePlan(@RequestBody AgentPlanReq req) {
+        return agentPlanService.createPlan(req);
     }
 
 }

+ 19 - 25
pavis-webapi/src/main/resources/db/changelog/mysql/main_table.sql

@@ -892,16 +892,16 @@ CREATE TABLE IF NOT EXISTS `aigc_agent_knowledge`
 CREATE TABLE IF NOT EXISTS `aigc_agent_plan`
 (
     `id`              BIGINT UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '自增主键',
-    `user_id`         BIGINT UNSIGNED NOT NULL COMMENT '用户ID',
-    `conversation_id` BIGINT UNSIGNED NOT NULL COMMENT '所属会话ID',
-    `message_id`      BIGINT UNSIGNED NOT NULL COMMENT '对话消息Id',
+    `user_id`         BIGINT UNSIGNED DEFAULT NULL COMMENT '用户ID',
+    `conversation_id` BIGINT UNSIGNED DEFAULT NULL COMMENT '所属会话ID',
+    `message_id`      BIGINT UNSIGNED DEFAULT NULL COMMENT '对话消息Id',
     `message_content` LONGTEXT        NOT NULL COMMENT '对话消息内容',
-    `think_input`     LONGTEXT        NOT NULL COMMENT '规划思考过程内容输入',
-    `think_output`    LONGTEXT        NOT NULL COMMENT '规划思考过程内容输出',
-    `title`           VARCHAR(500)    NOT NULL COMMENT '计划主题,大模型根据用户消息生成',
-    `start_time`      DATETIME        NOT NULL COMMENT '规划开始时间',
+    `think_input`     LONGTEXT        DEFAULT NULL COMMENT '规划思考过程内容输入',
+    `think_output`    LONGTEXT        DEFAULT NULL COMMENT '规划思考过程内容输出',
+    `title`           VARCHAR(500)    DEFAULT NULL COMMENT '计划主题,大模型根据用户消息生成',
+    `start_time`      DATETIME        DEFAULT NULL COMMENT '规划开始时间',
     `end_time`        DATETIME        DEFAULT NULL COMMENT '规划结束时间',
-    `duration`        INT             DEFAULT NULL COMMENT '怪话时长(秒)',
+    `duration`        LONG             DEFAULT NULL COMMENT '怪话时长(秒)',
     `current_step_id` BIGINT UNSIGNED DEFAULT NULL COMMENT '当前执行的步骤编号',
     `completed`       TINYINT(1)      DEFAULT 0 COMMENT '计划是否完成:0未完成 1已完成',
     `summary`         TEXT            DEFAULT NULL COMMENT '规划总结',
@@ -921,24 +921,18 @@ CREATE TABLE IF NOT EXISTS `aigc_agent_plan`
 -- ------------------------------
 CREATE TABLE IF NOT EXISTS `aigc_agent_plan_step`
 (
-    `id`              BIGINT UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '自增主键',
-    `plan_id`         BIGINT UNSIGNED NOT NULL COMMENT '计划ID',
-    `conversation_id` BIGINT UNSIGNED NOT NULL COMMENT '所属会话ID',
-    `message_id`      BIGINT UNSIGNED NOT NULL COMMENT '对话消息Id',
-    `message_content` LONGTEXT        NOT NULL COMMENT '对话消息内容',
-    `title`           VARCHAR(500)    NOT NULL COMMENT '计划主题,大模型根据用户消息生成',
-    `description`     VARCHAR(500)    NOT NULL COMMENT '计划描述:[BROWSER_AGENT] 打开百度主页',
-    `order`           INT      DEFAULT NULL COMMENT '步骤序号',
-    `agent_id`        BIGINT UNSIGNED NOT NULL COMMENT '本次计划关联的智能体ID',
-    `agent_code`      VARCHAR(50)     NOT NULL COMMENT '本次计划要使用的智能体:[BROWSER_AGENT]',
-    `result`          TEXT            NOT NULL COMMENT '步骤结果',
-    `create_user`     BIGINT          NOT NULL COMMENT '创建人',
-    `create_time`     DATETIME        NOT NULL COMMENT '创建时间',
-    `update_user`     BIGINT   DEFAULT NULL COMMENT '修改人',
-    `update_time`     DATETIME DEFAULT NULL COMMENT '修改时间',
+    `id`          BIGINT UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '自增主键',
+    `plan_id`     BIGINT UNSIGNED NOT NULL COMMENT '计划ID',
+    `description` VARCHAR(500)    DEFAULT NULL COMMENT '计划描述:[BROWSER_AGENT] 打开百度主页',
+    `step_index`  INT             DEFAULT NULL COMMENT '步骤序号',
+    `agent_id`    BIGINT UNSIGNED DEFAULT NULL COMMENT '本次计划关联的智能体ID',
+    `agent_code`  VARCHAR(50)     DEFAULT NULL COMMENT '本次计划要使用的智能体:[BROWSER_AGENT]',
+    `result`      TEXT            DEFAULT NULL COMMENT '步骤结果',
+    `create_user` BIGINT          NOT NULL COMMENT '创建人',
+    `create_time` DATETIME        NOT NULL COMMENT '创建时间',
+    `update_user` BIGINT          DEFAULT NULL COMMENT '修改人',
+    `update_time` DATETIME        DEFAULT NULL COMMENT '修改时间',
     PRIMARY KEY (`id`),
-    KEY `idx_message_id` (`message_id`),
-    KEY `idx_conversation_id` (`conversation_id`),
     KEY `idx_plan_id` (`plan_id`)
 ) ENGINE = InnoDB
   DEFAULT CHARSET = utf8mb4 COMMENT ='智能体规划步骤记录表';