后端: 1. conv 并行迁移与切流接线(旧目录下沉到 newAgent/conv) - 新建 newAgent/conv/schedule_provider.go、schedule_state.go、schedule_preview.go、schedule_persist.go,保持原有排程转换/预览/持久化能力; - 删除旧目录 conv/schedule_provider.go、schedule_state.go、schedule_preview.go、schedule_persist.go; - 更新 cmd/start.go 与 service/agentsvc/agent_newagent.go,ScheduleProvider/SchedulePersistor 与 preview 转换统一切到 newAgent/conv; - 删除旧 conv/schedule_state_test.go(迁移期测试文件清理)。 2. execute 循环上下文收口增强(历史归档 + 当前轮清晰化) - 更新 node/chat.go:仅在 completed 收口时写 execute_loop_closed marker,供后续 prompt 分层归档; - 更新 prompt/execute_context.go:msg1/msg2 升级为 V3,按收口标记拆分“历史归档 loop / 当前活跃 loop”,并增加 msg1 长度预算裁剪; - 更新 node/execute.go:新增 execute 置顶上下文同步(execution_context/current_step),在轮次开始与 next_plan 后即时刷新; - 更新 prompt/execute.go + execute_context.go:补齐“当前计划步骤 + done_when”强约束,禁止未达成判定时提前 next_plan。 3. 图路由与执行策略微调 - 更新 graph/common_graph.go:Plan/Confirm 分支允许直接进入 Deliver 收口; - 更新 node/plan.go:always_execute 链路下补发计划摘要并写入历史,保证自动执行与手动确认文案一致; - 更新 model/common_state.go:DefaultMaxRounds 从 30 提升到 60。 4. 复合工具规划器重构(去重实现,复用 logic 公共能力) - 更新 tools/compound_tools.go:min_context_switch / spread_even 改为调用 backend/logic 规划器(PlanMinContextSwitchMoves / PlanEvenSpreadMoves); - 新增 state_id↔logic_id 映射层,统一入参与回填,避免工具层与规划层 ID 语义耦合; - 删除 compound_tools 内部重复的规划/归一化/分组/打分实现,减少第三份复制逻辑。 5. 同步调试与文档 - 更新 newAgent/Log.txt 调试日志; - 新增 memory/记忆模块实施计划.md(面试优先版到产品可用版的落地路线)。 前端:无 仓库:无
122 lines
3.2 KiB
Go
122 lines
3.2 KiB
Go
package newagentconv
|
||
|
||
import (
|
||
"fmt"
|
||
"time"
|
||
|
||
"github.com/LoveLosita/smartflow/backend/model"
|
||
newagenttools "github.com/LoveLosita/smartflow/backend/newAgent/tools"
|
||
)
|
||
|
||
// ScheduleStateToPreview 将 newAgent 的 ScheduleState 转换为前端预览缓存格式。
|
||
//
|
||
// 职责边界:
|
||
// 1. 只做数据格式转换,不做业务逻辑;
|
||
// 2. 将每个 ScheduleTask 的每个 TaskSlot 转为一条 HybridScheduleEntry;
|
||
// 3. Day → (Week, DayOfWeek) 通过 ScheduleState.DayToWeekDay 转换;
|
||
// 4. 转换失败的 slot(day_index 无效)静默跳过。
|
||
func ScheduleStateToPreview(
|
||
state *newagenttools.ScheduleState,
|
||
userID int,
|
||
conversationID string,
|
||
taskClassIDs []int,
|
||
summary string,
|
||
) *model.SchedulePlanPreviewCache {
|
||
if state == nil {
|
||
return nil
|
||
}
|
||
|
||
entries := make([]model.HybridScheduleEntry, 0, len(state.Tasks))
|
||
for i := range state.Tasks {
|
||
t := &state.Tasks[i]
|
||
// 待安排且无位置的任务不生成 entry。
|
||
if newagenttools.IsPendingTask(*t) {
|
||
continue
|
||
}
|
||
|
||
for _, slot := range t.Slots {
|
||
week, dayOfWeek, ok := state.DayToWeekDay(slot.Day)
|
||
if !ok {
|
||
continue
|
||
}
|
||
|
||
entry := model.HybridScheduleEntry{
|
||
Week: week,
|
||
DayOfWeek: dayOfWeek,
|
||
SectionFrom: slot.SlotStart,
|
||
SectionTo: slot.SlotEnd,
|
||
Name: t.Name,
|
||
}
|
||
|
||
// Type 映射。
|
||
if t.Source == "event" {
|
||
if t.EventType != "" {
|
||
entry.Type = t.EventType
|
||
} else {
|
||
entry.Type = "course"
|
||
}
|
||
} else {
|
||
entry.Type = "task"
|
||
}
|
||
|
||
// Status 映射:existing 不变,suggested / 兼容建议态统一输出为 suggested。
|
||
if shouldMarkSuggestedInPreview(*t) {
|
||
entry.Status = "suggested"
|
||
} else {
|
||
entry.Status = "existing"
|
||
}
|
||
|
||
// ID 映射。
|
||
if t.Source == "event" {
|
||
entry.EventID = t.SourceID
|
||
} else {
|
||
entry.TaskItemID = t.SourceID
|
||
}
|
||
|
||
// 嵌入与阻塞语义。
|
||
entry.CanBeEmbedded = t.CanEmbed
|
||
if t.Source == "event" && t.CanEmbed && t.EmbeddedBy == nil {
|
||
// 可嵌入且当前无嵌入任务 → 不阻塞 suggested 占位。
|
||
entry.BlockForSuggested = false
|
||
} else {
|
||
entry.BlockForSuggested = true
|
||
}
|
||
|
||
entries = append(entries, entry)
|
||
}
|
||
}
|
||
|
||
// 生成摘要(若调用方未提供)。
|
||
if summary == "" {
|
||
existingCount := 0
|
||
suggestedCount := 0
|
||
for _, e := range entries {
|
||
if e.Status == "existing" {
|
||
existingCount++
|
||
} else {
|
||
suggestedCount++
|
||
}
|
||
}
|
||
summary = fmt.Sprintf("共 %d 个日程条目,其中已确定 %d 个,新安排 %d 个。", len(entries), existingCount, suggestedCount)
|
||
}
|
||
|
||
return &model.SchedulePlanPreviewCache{
|
||
UserID: userID,
|
||
ConversationID: conversationID,
|
||
Summary: summary,
|
||
HybridEntries: entries,
|
||
TaskClassIDs: taskClassIDs,
|
||
GeneratedAt: time.Now(),
|
||
}
|
||
}
|
||
|
||
// shouldMarkSuggestedInPreview 判断某条 ScheduleTask 在预览层是否应标记为 suggested。
|
||
//
|
||
// 规则说明:
|
||
// 1. 新语义下,显式 suggested 直接输出为建议态;
|
||
// 2. 兼容旧快照:pending+Slots、existing+Duration>0 的 task_item 也继续按 suggested 输出;
|
||
// 3. 这样前端预览口径可以在迁移期保持稳定,不会因为状态枚举切换而抖动。
|
||
func shouldMarkSuggestedInPreview(t newagenttools.ScheduleTask) bool {
|
||
return newagenttools.IsSuggestedTask(t)
|
||
}
|