Files
memoryweave/go/internal/api/routes/l3.go
T
xiaowei 2a350cf781 fix(distill): max_tokens 800→1200 — Agnes推理token预算不足
Agnes 2.0-flash是推理模型,推理token占大量预算。
800仍不够→JSON截断(parse error: unexpected end of JSON input)。
1200确保推理+正文都够用。
2026-08-20 01:13:06 +08:00

155 lines
4.6 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// 织忆 MemoryWeave — L3 世界模型 API
package routes
import (
"encoding/json"
"net/http"
"sync"
"time"
)
// L3 世界模型:ℰ (Entities) + ℐ (Interactions) + C (Constraints)
type WorldModel struct {
mu sync.RWMutex
Environment struct {
OS string `json:"os"`
Distro string `json:"distro"`
GPU string `json:"gpu"`
VRAM string `json:"vram"`
RAM string `json:"ram"`
CPU string `json:"cpu"`
IP string `json:"ip"`
HomeDir string `json:"home_dir"`
HermesVer string `json:"hermes_ver"`
} `json:"environment"`
Services []ServiceInfo `json:"services"` // ℐ: 服务和端口
ImplicitRules []string `json:"implicit_rules"` // C: 软约束
HardConstraints []string `json:"hard_constraints"` // C: 硬约束
Capabilities []string `json:"capabilities"`
UpdatedAt string `json:"updated_at"`
}
type ServiceInfo struct {
Name string `json:"name"`
Port int `json:"port"`
Status string `json:"status"`
DependsOn []string `json:"depends_on,omitempty"`
Provides []string `json:"provides,omitempty"`
}
var WM = &WorldModel{}
func init() {
WM.Environment.OS = "Linux"
WM.Environment.Distro = "Deepin 25"
WM.Environment.GPU = "NVIDIA RTX 3050 Laptop"
WM.Environment.VRAM = "4GB"
WM.Environment.RAM = "16GB"
WM.Environment.CPU = "Intel"
WM.Environment.IP = "192.168.123.12"
WM.Environment.HomeDir = "/home/muc"
WM.Environment.HermesVer = "0.13.0"
// ℐ: 服务拓扑
WM.Services = []ServiceInfo{
{Name: "new-api", Port: 3000, Status: "running", Provides: []string{"LLM gateway"}},
{Name: "Redis", Port: 6379, Status: "running", Provides: []string{"event bus", "cache", "rate limiting"}},
{Name: "织忆 MemoryWeave", Port: 7821, Status: "running",
DependsOn: []string{"Redis", "new-api"},
Provides: []string{"memory storage", "knowledge graph", "distillation"}},
{Name: "ComfyUI", Port: 8188, Status: "installed", Provides: []string{"image generation (SD 1.5)"}},
{Name: "Hermes webhook", Port: 8644, Status: "running", Provides: []string{"Feishu bot endpoint"}},
{Name: "OpenClaw", Port: 0, Status: "running",
DependsOn: []string{"织忆"},
Provides: []string{"code agent", "project management"}},
}
// C: 硬约束
WM.HardConstraints = []string{
"模型加载不超过 RTX 3050 4GB VRAM",
"新服务禁止占用端口: 3000, 6379, 7821, 8000, 8188, 8644",
"织忆只用一个端口 7821",
"所有 API 需 X-API-Key 认证 (除 /health 和 /metrics)",
}
// C: 软约束/隐式规则
WM.ImplicitRules = []string{
"牧尘话少直接,结论先行",
"性能可以多余,不能短缺",
"方案最大化完善,不是精简",
"先修性能再推进分布式",
"能 opencode 的不手工写代码",
"系统配置修改前需征得牧尘同意",
"牧尘对遗忘信息容忍度低——配置/位置类信息优先级记忆",
}
// 能力清单
WM.Capabilities = []string{
"飞书消息收发 (Hermes bot)",
"ComfyUI 图像生成 (SD 1.5)",
"语音合成 TTS (edge-tts)",
"语音识别 STT (faster-whisper)",
"浏览器自动化 (Playwright + agent-browser)",
"多 Agent 协作 (ao compose + 211角色)",
"定时任务调度 (cronjob)",
"代码审查与生成 (opencode + Claude Code)",
}
WM.UpdatedAt = time.Now().Format(time.RFC3339)
}
// GET /api/v1/l3/worldmodel
func (wm *WorldModel) GetHandler(w http.ResponseWriter, r *http.Request) {
wm.mu.RLock()
defer wm.mu.RUnlock()
respond(w, 200, wm)
}
// POST /api/v1/l3/worldmodel — 更新
func (wm *WorldModel) UpdateHandler(w http.ResponseWriter, r *http.Request) {
var req struct {
Environment *struct {
OS string `json:"os"`
GPU string `json:"gpu"`
VRAM string `json:"vram"`
RAM string `json:"ram"`
} `json:"environment"`
AddRules []string `json:"add_rules"`
AddCapabilities []string `json:"add_capabilities"`
}
if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
respondError(w, 400, "invalid body")
return
}
wm.mu.Lock()
defer wm.mu.Unlock()
if req.Environment != nil {
if req.Environment.OS != "" {
wm.Environment.OS = req.Environment.OS
}
if req.Environment.GPU != "" {
wm.Environment.GPU = req.Environment.GPU
}
if req.Environment.VRAM != "" {
wm.Environment.VRAM = req.Environment.VRAM
}
if req.Environment.RAM != "" {
wm.Environment.RAM = req.Environment.RAM
}
}
for _, rule := range req.AddRules {
wm.ImplicitRules = append(wm.ImplicitRules, rule)
}
for _, cap := range req.AddCapabilities {
wm.Capabilities = append(wm.Capabilities, cap)
}
wm.UpdatedAt = time.Now().Format(time.RFC3339)
respond(w, 200, wm)
}