A2 异步记忆提取:
- loop/memory.go: asyncExtractor接口(ExtractAsync)+extractMemoryAsync(60s超时,WithOutCancel,dispatch即返回,后台落库,失败仅Warn)+persistMemories共用
- run.go 三个回合落定点改异步提取; 删除run.go逐步提取(design/03'每轮后', 避免多轮工具N次LLM调用/重复写)
- cmd/cyrene/extractor.go buildMemoryExtractor: llmGroupUsable为真→LLMExtractor, 否则回落ManualExtractor(日志说明); keylessEndpoint放行loopback/私网
A4 可观测性 Tracing:
- cmd/cyrene/observability.go: newAppTraceWriter+traceFanout(多sink)+gatewaySpanSink(走gw.ObserveSpan,喂环形缓冲+LLM/subagent指标)
- wire.go 注入; 未改trace/gateway数据结构
A6 通知后端:
- internal/services/gateway/notifications.go(311行): GET /admin/notifications?type=&before=&limit= (adminAuth)
- 聚合已有源(obs.audit SQLite + s.backthink), createdAt倒序, id=source:id; 类型派生(channel/system/audit/backthink); 无新建表/无新Deps/wire零改动
- 诚实: backthink仅shouldPush计, 未注入源为空, 报错500, 未读游标后置
- 契约与前端Y一致: {id,type,title,body,source,createdAt}, before含游标(<=), type未知400
- Docs/api-client v0.33
全仓 build/vet/test绿(56包)+win/darwin/linux-arm64交叉编译绿; 新增测试(memory_async/extractor/observability/notifications)
79 lines
2.7 KiB
Go
79 lines
2.7 KiB
Go
package main
|
|
|
|
import (
|
|
"net"
|
|
"net/url"
|
|
"strings"
|
|
|
|
"git.yeij.top/AskaEth/Cyrene_v2/internal/runtime/memory"
|
|
"git.yeij.top/AskaEth/Cyrene_v2/internal/runtime/model"
|
|
)
|
|
|
|
// memoryOwnerRoleID is the role id the composition root authors extracted
|
|
// memories with; the owner is the only actor whose private memory is written
|
|
// (group/stranger conversations never extract at all, design/11 §2).
|
|
const memoryOwnerRoleID = "owner"
|
|
|
|
// buildMemoryExtractor selects the memory extractor the loop runs after each
|
|
// settled turn (design/03 §1 LLM 异步自动提取):
|
|
//
|
|
// - the LLM extractor when the provider stack has a usable active group, so
|
|
// the model denoises and deduplicates what is worth remembering;
|
|
// - the deterministic ManualExtractor otherwise, so a keyless deployment still
|
|
// records the owner's explicit "记住 X" directives instead of failing a model
|
|
// call on every turn.
|
|
//
|
|
// The loop detaches the LLM extractor to a background goroutine (ExtractAsync);
|
|
// see internal/runtime/loop/memory.go.
|
|
func (a *app) buildMemoryExtractor(personaID string) memory.Extractor {
|
|
if llmGroupUsable(a.llm) {
|
|
a.log.Info("memory extractor: llm", "model", a.llm.Model(), "provider", a.llm.Provider())
|
|
return memory.NewLLMExtractor(a.llm, personaID, memoryOwnerRoleID)
|
|
}
|
|
a.log.Warn("memory extractor: manual (no usable llm model group)")
|
|
return memory.NewManualExtractor(personaID, memoryOwnerRoleID)
|
|
}
|
|
|
|
// llmGroupUsable reports whether the active model group of the runtime stack can
|
|
// actually be called: a model and a base URL are mandatory, and either an API key
|
|
// is configured or the endpoint is a local/private address, where a keyless call
|
|
// is the normal case (a self-hosted OpenAI-compatible server).
|
|
//
|
|
// It is deliberately a cheap structural check, never a probe request: boot must
|
|
// not spend a model call. A group that looks usable but fails at call time only
|
|
// logs an extraction error (extraction failures are never fatal).
|
|
func llmGroupUsable(llm *model.RuntimeLLM) bool {
|
|
if llm == nil {
|
|
return false
|
|
}
|
|
group := llm.Group()
|
|
if strings.TrimSpace(group.Model) == "" || strings.TrimSpace(group.BaseURL) == "" {
|
|
return false
|
|
}
|
|
if strings.TrimSpace(group.APIKey) != "" {
|
|
return true
|
|
}
|
|
return keylessEndpoint(group.BaseURL)
|
|
}
|
|
|
|
// keylessEndpoint reports whether baseURL points at a loopback or private-network
|
|
// host, where a missing API key is expected rather than a misconfiguration.
|
|
func keylessEndpoint(baseURL string) bool {
|
|
parsed, err := url.Parse(strings.TrimSpace(baseURL))
|
|
if err != nil {
|
|
return false
|
|
}
|
|
host := parsed.Hostname()
|
|
if host == "" {
|
|
return false
|
|
}
|
|
if strings.EqualFold(host, "localhost") {
|
|
return true
|
|
}
|
|
ip := net.ParseIP(host)
|
|
if ip == nil {
|
|
return false
|
|
}
|
|
return ip.IsLoopback() || ip.IsPrivate()
|
|
}
|