Files
HomeAgent/config/config.go
root bc26850b50 feat: complete HomeAgent architecture v2
- IO abstraction layer with OutputChannel routing and capability validation
- Three-layer memory (Context-Document-Graph) with TF-IDF relevance pruning
- OneBot V11 QQ protocol plugin with Reverse WebSocket client
- Plugin system with hot-reload (SKILL.md + native factories)
- Knowledge system with TF-IDF vector indexing
- Personality system (personal.md)
- Text memory (JSONL with rotation)
- Change tracker (overlayfs) with rollback
- Lua adapter VM
- Design document (DESIGN.md)

Module: gitcode.com/JianFeeeee/HomeAgent
2026-07-02 12:04:36 +08:00

92 lines
2.0 KiB
Go

package config
import (
"fmt"
"os"
"path/filepath"
"time"
"gitcode.com/JianFeeeee/HomeAgent/pkg/types"
"gopkg.in/yaml.v3"
)
const DefaultConfigPath = "/etc/homeagent/config.yaml"
func DefaultConfig() types.Config {
return types.Config{
Daemon: types.DaemonConfig{
ListenAddr: ":8080",
DataDir: "/var/lib/homeagent",
HeartbeatInterval: 15 * time.Second,
CheckInterval: 30 * time.Second,
LogLevel: "info",
},
LLM: types.LLMConfig{
Provider: "openai",
Model: "deepseek-v4-flash",
BaseURL: "https://api.deepseek.com",
Temperature: 0.7,
MaxTokens: 4096,
},
Defaults: types.AgentConfig{
Image: "homeagent/agent-base:latest",
LLMEndpoints: []string{"https://api.openai.com/v1"},
SnapshotPolicy: types.SnapshotPolicy{
Interval: 10 * time.Minute,
MaxSnapshots: 20,
PreAction: true,
PostAction: false,
},
RollbackPolicy: types.RollbackPolicy{
MaxRetries: 3,
HealthThreshold: types.HealthDown,
CooldownPeriod: 30 * time.Second,
AutoRollback: true,
},
ResourceLimit: types.ResourceLimit{
CPU: "2",
Memory: "2g",
Disk: "10g",
Network: true,
},
OpenClawEnabled: true,
},
}
}
func Load(path string) (*types.Config, error) {
cfg := DefaultConfig()
data, err := os.ReadFile(path)
if err != nil {
if os.IsNotExist(err) {
return &cfg, nil
}
return nil, fmt.Errorf("read config: %w", err)
}
if err := yaml.Unmarshal(data, &cfg); err != nil {
return nil, fmt.Errorf("parse config: %w", err)
}
return &cfg, nil
}
func Save(path string, cfg *types.Config) error {
dir := filepath.Dir(path)
if err := os.MkdirAll(dir, 0755); err != nil {
return fmt.Errorf("create config dir: %w", err)
}
data, err := yaml.Marshal(cfg)
if err != nil {
return fmt.Errorf("marshal config: %w", err)
}
if err := os.WriteFile(path, data, 0644); err != nil {
return fmt.Errorf("write config: %w", err)
}
return nil
}