后端: 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 迁移面
54 lines
1.8 KiB
Go
54 lines
1.8 KiB
Go
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)
|
||
}
|