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>
This commit is contained in:
50
server/internal/service/memory_service.go
Normal file
50
server/internal/service/memory_service.go
Normal file
@@ -0,0 +1,50 @@
|
||||
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)
|
||||
}
|
||||
Reference in New Issue
Block a user