Files
X-Agents/server/internal/service/memory_service.go
DESKTOP-72TV0V4\caoxiaozhu fc1204a033 feat: 新增 Agent、Memory、Skill 模块
- handler: agent_handler, memory_handler, skill_handler
- model: agent.go, skill.go
- repository: agent_repo, skill_repo
- service: agent_service, memory_service, skill_service
- 新增 migrations 目录

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-11 16:25:48 +08:00

51 lines
1.2 KiB
Go

package service
import (
"x-agents/server/internal/repository"
"x-agents/server/internal/model"
)
// MemoryService 记忆服务
type MemoryService struct {
agentRepo *repository.AgentRepository
}
// NewMemoryService 创建记忆服务
func NewMemoryService(agentRepo *repository.AgentRepository) *MemoryService {
return &MemoryService{
agentRepo: agentRepo,
}
}
// CreateMemory 创建记忆
func (s *MemoryService) CreateMemory(agentID, userID, content, memoryType string, importance int) (*model.AgentMemory, error) {
memory := &model.AgentMemory{
AgentID: agentID,
UserID: userID,
Content: content,
MemoryType: memoryType,
Importance: importance,
}
err := s.agentRepo.CreateMemory(memory)
if err != nil {
return nil, err
}
return memory, nil
}
// GetMemories 获取记忆列表
func (s *MemoryService) GetMemories(agentID string, userID string, limit int) ([]model.AgentMemory, error) {
if userID != "" {
return s.agentRepo.FindMemoriesByUserID(agentID, userID, limit)
}
return s.agentRepo.FindMemoriesByAgentID(agentID, limit)
}
// DeleteMemory 删除记忆
func (s *MemoryService) DeleteMemory(memoryID string) error {
return s.agentRepo.DeleteMemory(memoryID)
}