Files
smartmate/backend/dao/agent_state_store_adapter.go
Losita d7184b776b Version: 0.9.75.dev.260505
后端:
1.收口阶段 6 agent 结构迁移,将 newAgent 内核与 agentsvc 编排层迁入 services/agent
- 切换 Agent 启动装配与 HTTP handler 直连 agent sv,移除旧 service agent bridge
- 补齐 Agent 对 memory、task、task-class、schedule 的 RPC 适配与契约字段
- 扩展 schedule、task、task-class RPC/contract 支撑 Agent 查询、写入与 provider 切流
- 更新迁移文档、README 与相关注释,明确 agent 当前切流点和剩余 memory 迁移面
2026-05-05 16:00:57 +08:00

54 lines
1.8 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 dao
import (
"context"
"errors"
agentmodel "github.com/LoveLosita/smartflow/backend/services/agent/model"
)
// AgentStateStoreAdapter 将 CacheDAO 适配为 agent 的 AgentStateStore 接口。
//
// 职责边界:
// 1. CacheDAO 的 LoadAgentState 使用 out-parameter 模式,需要适配到返回值模式;
// 2. CacheDAO 的 SaveAgentState 接受 any需要适配到 *AgentStateSnapshot
// 3. DeleteAgentState 签名已匹配,直接转发。
type AgentStateStoreAdapter struct {
cache *CacheDAO
}
// NewAgentStateStoreAdapter 创建适配器。
func NewAgentStateStoreAdapter(cache *CacheDAO) *AgentStateStoreAdapter {
return &AgentStateStoreAdapter{cache: cache}
}
// Save 序列化并保存 agent 状态快照。
func (a *AgentStateStoreAdapter) Save(ctx context.Context, conversationID string, snapshot *agentmodel.AgentStateSnapshot) error {
if a == nil || a.cache == nil {
return errors.New("agent state store adapter is not initialized")
}
return a.cache.SaveAgentState(ctx, conversationID, snapshot)
}
// Load 读取并反序列化 agent 状态快照。
func (a *AgentStateStoreAdapter) Load(ctx context.Context, conversationID string) (*agentmodel.AgentStateSnapshot, bool, error) {
if a == nil || a.cache == nil {
return nil, false, errors.New("agent state store adapter is not initialized")
}
var snapshot agentmodel.AgentStateSnapshot
ok, err := a.cache.LoadAgentState(ctx, conversationID, &snapshot)
if err != nil || !ok {
return nil, ok, err
}
return &snapshot, true, nil
}
// Delete 删除 agent 状态快照。
func (a *AgentStateStoreAdapter) Delete(ctx context.Context, conversationID string) error {
if a == nil || a.cache == nil {
return errors.New("agent state store adapter is not initialized")
}
return a.cache.DeleteAgentState(ctx, conversationID)
}