Files
goclaw/internal/store/memory_store.go
T
Luan Vu 2fdb791802 fix: honor per-agent DB settings for restrict, subagents, memory, sandbox (#145)
Four per-agent settings stored in the database (and configurable via UI)
were silently ignored at runtime because the tool/system layer always
used the global config defaults instead.

**restrict_to_workspace**: Tools used the global config default baked at
startup. Fix: pass per-agent value through context; tools check context
override before falling back to constructor default.

**subagents_config**: ParseSubagentsConfig() existed but was never called.
All agents shared one SubagentManager with global limits. Fix: resolve
per-agent config in the agent resolver, store it on each spawned task,
and use it for limit checks, deny lists, and system prompt generation.

**memory_config**: Only the enabled toggle was read per-agent; search
weights (vector_weight, text_weight, max_results, min_score) were
hardcoded from PGMemoryStore defaults. Fix: extend MemorySearchOptions
with weight overrides, read per-agent config from context in the
memory_search tool.

**sandbox_config**: Only workspace_access was extracted per-agent; mode,
image, memory, CPU, timeout, network settings were discarded. Fix: pass
full sandbox.Config through context; Manager.Get() accepts an optional
config override for new containers.

Co-authored-by: Luvu182 <208665161+Luvu182@users.noreply.github.com>
2026-03-11 16:05:56 +07:00

87 lines
3.0 KiB
Go

package store
import "context"
// DocumentInfo describes a memory document.
type DocumentInfo struct {
Path string `json:"path"`
Hash string `json:"hash"`
AgentID string `json:"agent_id,omitempty"`
UserID string `json:"user_id,omitempty"`
UpdatedAt int64 `json:"updated_at"`
}
// MemorySearchResult is a single result from memory search.
type MemorySearchResult struct {
Path string `json:"path"`
StartLine int `json:"start_line"`
EndLine int `json:"end_line"`
Score float64 `json:"score"`
Snippet string `json:"snippet"`
Source string `json:"source"`
Scope string `json:"scope,omitempty"` // "global" or "personal"
}
// MemorySearchOptions configures a memory search query.
type MemorySearchOptions struct {
MaxResults int
MinScore float64
Source string // "memory", "sessions", ""
PathPrefix string
VectorWeight float64 // per-agent override (0 = use store default)
TextWeight float64 // per-agent override (0 = use store default)
}
// EmbeddingProvider generates vector embeddings for text.
type EmbeddingProvider interface {
Name() string
Model() string
Embed(ctx context.Context, texts []string) ([][]float32, error)
}
// DocumentDetail provides full document info including chunk/embedding stats.
type DocumentDetail struct {
Path string `json:"path"`
Content string `json:"content"`
Hash string `json:"hash"`
UserID string `json:"user_id,omitempty"`
ChunkCount int `json:"chunk_count"`
EmbeddedCount int `json:"embedded_count"`
CreatedAt int64 `json:"created_at"`
UpdatedAt int64 `json:"updated_at"`
}
// ChunkInfo describes a single memory chunk.
type ChunkInfo struct {
ID string `json:"id"`
StartLine int `json:"start_line"`
EndLine int `json:"end_line"`
TextPreview string `json:"text_preview"`
HasEmbedding bool `json:"has_embedding"`
}
// MemoryStore manages memory documents and search.
type MemoryStore interface {
// Document CRUD
GetDocument(ctx context.Context, agentID, userID, path string) (string, error)
PutDocument(ctx context.Context, agentID, userID, path, content string) error
DeleteDocument(ctx context.Context, agentID, userID, path string) error
ListDocuments(ctx context.Context, agentID, userID string) ([]DocumentInfo, error)
// Admin queries
ListAllDocumentsGlobal(ctx context.Context) ([]DocumentInfo, error)
ListAllDocuments(ctx context.Context, agentID string) ([]DocumentInfo, error)
GetDocumentDetail(ctx context.Context, agentID, userID, path string) (*DocumentDetail, error)
ListChunks(ctx context.Context, agentID, userID, path string) ([]ChunkInfo, error)
// Search
Search(ctx context.Context, query string, agentID, userID string, opts MemorySearchOptions) ([]MemorySearchResult, error)
// Indexing
IndexDocument(ctx context.Context, agentID, userID, path string) error
IndexAll(ctx context.Context, agentID, userID string) error
SetEmbeddingProvider(provider EmbeddingProvider)
Close() error
}