Files
smartmate/backend/newAgent/model/state_store.go
LoveLosita 17e3615f74 Version: 0.8.8.dev.260403
后端:
1.新建Deliver节点:LLM生成任务总结,失败降级到机械格式化,伪流式输出
2.新建Confirm节点:确认卡片推送与状态持久化
3.新建Interrupt节点:追问/确认/默认中断三种处理路径
4.实现状态持久化体系:model层定义AgentStateStore接口+AgentStateSnapshot快照,dao/cache.go新增Redis CRUD,agent_nodes层每节点自动存快照、Deliver完成后清理
5.所有model struct补充JSON tags,支持Redis序列化/反序列化
前端:无
仓库:无
2026-04-03 20:36:31 +08:00

50 lines
2.0 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package model
import "context"
// 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"`
}
// 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
}