后端: 1.粗排结果/预览语义修复(task_item suggested 保真 + existing/嵌入识别补全) - 更新conv/schedule_state.go:LoadScheduleState 补齐 event.rel_id / schedules.embedded_task_id / task_item.embedded_time 三种“已落位”信号;嵌入任务强制 existing + 继承 host slots;补充 task_item duration/name/slot helper;Diff 相关英文注释改中文 - 更新conv/schedule_preview.go:预览层新增 shouldMarkSuggestedInPreview,pending 任务与 source=task_item 的建议态任务统一输出 suggested 2.newAgent 状态快照增强(ScheduleState/OriginalScheduleState 跨轮恢复) - 更新model/state_store.go:AgentStateSnapshot 新增 ScheduleState / OriginalScheduleState - 更新model/graph_run_state.go:AgentGraphRunInput/AgentGraphState 接入两份 schedule 状态;恢复旧快照时自动补 original clone - 更新service/agentsvc/agent_newagent.go:loadOrCreateRuntimeState 返回并恢复 schedule/original;runNewAgentGraph 透传到 graph - 更新node/agent_nodes.go:saveAgentState 一并保存 schedule/original 到 Redis 快照 3.Execute 链路纠偏(只写内存不落库 + 完整打点 + 恢复消息去重) - 更新node/execute.go:AlwaysExecute/confirm resume 路径取消 PersistScheduleChanges,仅保留内存写;新增 execute LLM 完整上下文日志;新增工具调用前后 state 摘要日志;thinking 模式改为 enabled - 更新node/chat.go:pending resume 不再重复写入同一轮 user message - 更新service/agentsvc/agent_newagent.go:新增 deliver preview write/state 摘要日志,便于排查 suggested 丢失问题 4.AlwaysExecute 贯通 Plan→Graph→Execute - 更新node/plan.go:PlanNodeInput 新增 AlwaysExecute;plan_done 后支持自动确认直接进入执行 - 更新graph/common_graph.go:branchAfterPlan 支持 PhaseExecuting/PhaseDone 分支 5.排课上下文补强(显式注入 task_class_ids,减少 Execute 误 ask_user) - 更新prompt/execute.go:Plan/ReAct 两种 execute prompt 都显式写入任务类 ID,声明“上下文已完整,无需追问” - 更新node/rough_build.go:粗排完成 pinned block 显式标注任务类 ID,避免 Execute 找不到 ID 来源 6.流式输出与预览调试工具修复 - 更新stream/emitter.go:保留换行,修复 pseudo stream 分片后文本黏连/双换行问题 - 更新infra/schedule_preview_viewer.html:升级预览工具,支持 candidate_plans / hybrid_entries 前端:无 仓库: 1.更新了infra内的html,适应了获取日程接口
72 lines
3.2 KiB
Go
72 lines
3.2 KiB
Go
package model
|
||
|
||
import (
|
||
"context"
|
||
|
||
newagenttools "github.com/LoveLosita/smartflow/backend/newAgent/tools"
|
||
)
|
||
|
||
// AgentStateSnapshot 是需要持久化的 agent 运行态最小快照。
|
||
//
|
||
// 设计说明:
|
||
// 1. 只保存恢复执行所需的 RuntimeState 和 ConversationContext;
|
||
// 2. 不保存 Request(每轮请求级,天然不跨连接);
|
||
// 3. 不保存 Deps(依赖注入,每次由 Service 层重建);
|
||
// 4. 不保存 ToolSchemas(每次请求由 Service 层重新注入)。
|
||
type AgentStateSnapshot struct {
|
||
RuntimeState *AgentRuntimeState `json:"runtime_state"`
|
||
ConversationContext *ConversationContext `json:"conversation_context"`
|
||
ScheduleState *newagenttools.ScheduleState `json:"schedule_state,omitempty"`
|
||
OriginalScheduleState *newagenttools.ScheduleState `json:"original_schedule_state,omitempty"`
|
||
}
|
||
|
||
// AgentStateStore 定义 agent 状态持久化的最小接口。
|
||
//
|
||
// 职责边界:
|
||
// 1. 只负责"存 / 取 / 删"三个原子操作;
|
||
// 2. 不负责序列化细节(由实现层决定 JSON / protobuf);
|
||
// 3. 不负责业务级状态校验,校验仍在 node / graph 层完成。
|
||
//
|
||
// 实现层:
|
||
// 1. dao/cache.go 上的 CacheDAO 隐式实现该接口(Go duck typing);
|
||
// 2. newAgent 包不直接 import dao,由 Service 层在组装 Deps 时注入。
|
||
type AgentStateStore interface {
|
||
// Save 序列化并保存一份 agent 状态快照。
|
||
//
|
||
// 语义:
|
||
// 1. 同一 conversationID 被覆盖写入,保证 Redis 里始终只有最新快照;
|
||
// 2. 实现层应设 TTL,避免已完成的任务快照永不清理。
|
||
Save(ctx context.Context, conversationID string, snapshot *AgentStateSnapshot) error
|
||
|
||
// Load 读取并反序列化 agent 状态快照。
|
||
//
|
||
// 返回值语义:
|
||
// 1. (snapshot, true, nil):命中快照,正常返回;
|
||
// 2. (nil, false, nil):未命中,不是错误,调用方应走新建对话路径;
|
||
// 3. (nil, false, error):真正的存储层错误。
|
||
Load(ctx context.Context, conversationID string) (*AgentStateSnapshot, bool, error)
|
||
|
||
// Delete 删除指定会话的 agent 状态快照。
|
||
//
|
||
// 语义:
|
||
// 1. 删除是幂等的,key 不存在也视为成功;
|
||
// 2. 典型调用时机:Deliver 节点任务完成后清理。
|
||
Delete(ctx context.Context, conversationID string) error
|
||
}
|
||
|
||
// ScheduleStateProvider 定义加载 ScheduleState 的接口。
|
||
// 由 DAO 层或 Service 层实现,注入到 AgentGraphDeps 中。
|
||
// 使用接口而非具体 DAO 类型,避免 model → dao 的循环依赖。
|
||
type ScheduleStateProvider interface {
|
||
LoadScheduleState(ctx context.Context, userID int) (*newagenttools.ScheduleState, error)
|
||
// LoadTaskClassMetas 只加载指定任务类的约束元数据,供 Plan 节点提前消费。
|
||
LoadTaskClassMetas(ctx context.Context, userID int, taskClassIDs []int) ([]newagenttools.TaskClassMeta, error)
|
||
}
|
||
|
||
// SchedulePersistor 定义持久化 ScheduleState 变更的接口。
|
||
// 由 Service 层或 DAO 层实现,注入到 AgentGraphDeps 中。
|
||
// 使用接口而非具体 DAO 类型,避免 model → dao 的循环依赖。
|
||
type SchedulePersistor interface {
|
||
PersistScheduleChanges(ctx context.Context, original, modified *newagenttools.ScheduleState, userID int) error
|
||
}
|