Version: 0.7.1.dev.260321
feat(agent): ✨ 重构智能排程分流与双通道交付,补齐周级预算并接入连续微调复用 - 🔀 通用路由升级为 action 分流(chat/quick_note_create/task_query/schedule_plan),路由失败直接返回内部错误,不再回落聊天 - 🧭 智能排程链路重构:统一图编排与节点职责,完善日级/周级调优协作与提示词约束 - 📊 周级预算改为“有效周保底 + 负载加权分配”,避免有效周零预算并提升资源利用率 - ⚙️ 日级并发优化细化:按天拆分 DayGroup 并发执行,低收益天(suggested<=2)跳过,单天失败仅回退该天结果并继续全局 - 🧵 周级并发优化细化:按周并发 worker 执行,单周“单步动作”循环(每轮仅 1 个 Move/Swap 或 done),失败周保留原方案不影响其它周 - 🛰️ 新增排程预览双通道:聊天主链路输出终审文本,结构化 candidate_plans 通过 /api/v1/agent/schedule-preview 拉取 - 🗃️ 增补 Redis 预览缓存读写与清理逻辑,新增对应 API、路由、模型与错误码支持 - ♻️ 接入连续对话微调复用:命中同会话历史预览时复用上轮 HybridEntries,避免每轮重跑粗排 - 🛡️ 增加复用保护:仅当本轮与上轮 task_class_ids 集合一致才复用;不一致回退全量粗排 - 🧰 扩展预览缓存字段(task_class_ids/hybrid_entries/allocated_items),支撑微调承接链路 - 🗺️ 更新 README 5.4 Mermaid(总分流图 + 智能排程流转图)并补充决策文档 - ⚠️ 新增“连续微调复用”链路我尚未完成测试,且文档状态目前较为混乱,待连续对话微调功能真正测试完成后再统一更新
This commit is contained in:
@@ -64,11 +64,19 @@ func (api *AgentHandler) ChatAgent(c *gin.Context) {
|
||||
select {
|
||||
case err, ok := <-errChan:
|
||||
if ok && err != nil {
|
||||
// 4.1 统一 SSE 错误体:
|
||||
// 4.1.1 默认按内部错误输出 message/type;
|
||||
// 4.1.2 若是 respond.Response(含业务码),额外透传 code,便于前端识别 5xxxx 等自定义错误。
|
||||
errorBody := map[string]any{
|
||||
"message": err.Error(),
|
||||
"type": "server_error",
|
||||
}
|
||||
var respErr respond.Response
|
||||
if errors.As(err, &respErr) {
|
||||
errorBody["code"] = respErr.Status
|
||||
}
|
||||
errPayload, _ := json.Marshal(map[string]any{
|
||||
"error": map[string]any{
|
||||
"message": err.Error(),
|
||||
"type": "server_error",
|
||||
},
|
||||
"error": errorBody,
|
||||
})
|
||||
_ = writeSSEData(w, string(errPayload))
|
||||
_ = writeSSEData(w, "[DONE]")
|
||||
@@ -172,3 +180,33 @@ func (api *AgentHandler) GetConversationList(c *gin.Context) {
|
||||
}
|
||||
c.JSON(http.StatusOK, respond.RespWithData(respond.Ok, resp))
|
||||
}
|
||||
|
||||
// GetSchedulePlanPreview 返回“指定会话”的排程结构化预览。
|
||||
//
|
||||
// 设计说明:
|
||||
// 1) 该接口只读 Redis 预览快照,不修改聊天主链路协议;
|
||||
// 2) 按 conversation_id + user_id 读取,避免跨用户越权访问;
|
||||
// 3) 预览受 TTL 影响,若不存在会返回业务错误码。
|
||||
func (api *AgentHandler) GetSchedulePlanPreview(c *gin.Context) {
|
||||
// 1. 参数校验:conversation_id 必填。
|
||||
conversationID := strings.TrimSpace(c.Query("conversation_id"))
|
||||
if conversationID == "" {
|
||||
c.JSON(http.StatusBadRequest, respond.MissingParam)
|
||||
return
|
||||
}
|
||||
|
||||
// 2. 从鉴权上下文取当前用户 ID,保证查询范围只在“本人会话”内。
|
||||
userID := c.GetInt("user_id")
|
||||
|
||||
// 3. 设置短超时,防止缓存抖动时占用连接过久。
|
||||
ctx, cancel := context.WithTimeout(c.Request.Context(), 1*time.Second)
|
||||
defer cancel()
|
||||
|
||||
// 4. 调 service 查询并返回统一响应结构。
|
||||
preview, err := api.svc.GetSchedulePlanPreview(ctx, userID, conversationID)
|
||||
if err != nil {
|
||||
respond.DealWithError(c, err)
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, respond.RespWithData(respond.Ok, preview))
|
||||
}
|
||||
|
||||
@@ -26,7 +26,6 @@ func (s *ScheduleAPI) GetUserTodaySchedule(c *gin.Context) {
|
||||
// 1. 从请求上下文中获取用户ID
|
||||
userID := c.GetInt("user_id")
|
||||
//2.调用服务层方法获取用户当天的日程安排
|
||||
// 创建一个带 1 秒超时的上下文
|
||||
ctx, cancel := context.WithTimeout(c.Request.Context(), 1*time.Second)
|
||||
defer cancel() // 记得释放资源
|
||||
todaySchedules, err := s.scheduleService.GetUserTodaySchedule(ctx, userID)
|
||||
@@ -133,8 +132,6 @@ func (s *ScheduleAPI) UserRevocateTaskItemFromSchedule(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
//3.调用服务层方法撤销任务块的安排
|
||||
/*ctx, cancel := context.WithTimeout(c.Request.Context(), 1*time.Second)
|
||||
defer cancel() // 记得释放资源*/
|
||||
err = s.scheduleService.RevocateUserTaskClassItem(context.Background(), userID, intEventID)
|
||||
if err != nil {
|
||||
respond.DealWithError(c, err)
|
||||
@@ -147,7 +144,7 @@ func (s *ScheduleAPI) UserRevocateTaskItemFromSchedule(c *gin.Context) {
|
||||
func (s *ScheduleAPI) SmartPlanning(c *gin.Context) {
|
||||
// 1. 从请求上下文中获取用户ID
|
||||
userID := c.GetInt("user_id")
|
||||
// 2. 从请求体中获取智能规划的参数
|
||||
// 2. 从请求参数中获取智能规划的 task_class_id
|
||||
taskClassID := c.Query("task_class_id")
|
||||
intTaskClassID, err := strconv.Atoi(taskClassID)
|
||||
if err != nil {
|
||||
@@ -165,3 +162,33 @@ func (s *ScheduleAPI) SmartPlanning(c *gin.Context) {
|
||||
//4.返回智能规划成功的响应给前端
|
||||
c.JSON(http.StatusOK, respond.RespWithData(respond.Ok, res))
|
||||
}
|
||||
|
||||
// SmartPlanningMulti 处理“多任务类智能粗排”请求。
|
||||
//
|
||||
// 职责边界:
|
||||
// 1. 只负责参数绑定、超时控制、错误透传;
|
||||
// 2. 具体业务校验与排序策略由 service 层统一处理;
|
||||
// 3. 保留已有单任务类接口,不与其互斥。
|
||||
func (s *ScheduleAPI) SmartPlanningMulti(c *gin.Context) {
|
||||
// 1. 从请求上下文中读取登录用户 ID。
|
||||
userID := c.GetInt("user_id")
|
||||
|
||||
// 2. 绑定多任务类请求体。
|
||||
var req model.UserSmartPlanningMultiRequest
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
c.JSON(http.StatusBadRequest, respond.WrongParamType)
|
||||
return
|
||||
}
|
||||
|
||||
// 3. 调用服务层执行多任务类粗排。
|
||||
ctx, cancel := context.WithTimeout(c.Request.Context(), 1*time.Second)
|
||||
defer cancel()
|
||||
res, err := s.scheduleService.SmartPlanningMulti(ctx, userID, req.TaskClassIDs)
|
||||
if err != nil {
|
||||
respond.DealWithError(c, err)
|
||||
return
|
||||
}
|
||||
|
||||
// 4. 返回成功响应。
|
||||
c.JSON(http.StatusOK, respond.RespWithData(respond.Ok, res))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user