ZovOS_AI/internal/agent/memory.go
Dan4ick 460d20539f feat: initial project structure - Phase 1 MVP
- Project infrastructure: go.mod, Makefile, .gitignore, README
- Configuration system with YAML parsing and env overrides
- Structured logging with slog
- AI provider interface with Ollama, OpenAI, Anthropic implementations
- Provider manager with runtime switching
- Agent orchestrator with ReAct loop (reason-act-observe)
- Tool registry with JSON Schema descriptions
- Terminal tool: shell command execution with safety controls
- Filesystem tools: read, write, list with path access control
- Conversation memory with session management
- Web UI server with WebSocket streaming
- Modern dark theme UI with glassmorphism, animations
- Frontend: WebSocket client, markdown rendering, tool call display
2026-03-20 00:38:22 +03:00

66 lines
1.4 KiB
Go

package agent
import (
"sync"
"git.bebrik.xyz/Dan4ick/ZovOS_AI/internal/ai"
)
// Memory stores conversation history per session.
type Memory struct {
mu sync.RWMutex
sessions map[string][]ai.Message
}
// NewMemory creates a new Memory store.
func NewMemory() *Memory {
return &Memory{
sessions: make(map[string][]ai.Message),
}
}
// Get returns the message history for a session.
func (m *Memory) Get(sessionID string) []ai.Message {
m.mu.RLock()
defer m.mu.RUnlock()
msgs, ok := m.sessions[sessionID]
if !ok {
return nil
}
// Return a copy
result := make([]ai.Message, len(msgs))
copy(result, msgs)
return result
}
// Set replaces the message history for a session.
func (m *Memory) Set(sessionID string, messages []ai.Message) {
m.mu.Lock()
defer m.mu.Unlock()
m.sessions[sessionID] = messages
}
// Append adds messages to a session's history.
func (m *Memory) Append(sessionID string, msgs ...ai.Message) {
m.mu.Lock()
defer m.mu.Unlock()
m.sessions[sessionID] = append(m.sessions[sessionID], msgs...)
}
// Clear removes all messages for a session.
func (m *Memory) Clear(sessionID string) {
m.mu.Lock()
defer m.mu.Unlock()
delete(m.sessions, sessionID)
}
// ListSessions returns all active session IDs.
func (m *Memory) ListSessions() []string {
m.mu.RLock()
defer m.mu.RUnlock()
ids := make([]string, 0, len(m.sessions))
for id := range m.sessions {
ids = append(ids, id)
}
return ids
}