feat: 记忆配置改为数据库存储,用户只可配置召回模式
- 新增 persistence/memory_config/ 模块:UserMemoryConfigRow ORM 模型 + SqlUserMemoryConfigRepository + MemoryUserMemoryConfigStore(内存兼容) - 新增 Alembic 迁移脚本 20260521_01 创建 user_memory_configs 表 - memory_config.py:USER_WRITABLE_FIELDS 从 3 个缩减为 1 个 (hindsight.recall_budget),移除文件 IO,改为进程内 cache + async DB 对接函数 - Gateway lifespan 启动时批量预热 recall_budget cache - memory router PATCH/DELETE 改用 DB 存储,支持 400 校验非法 budget 值 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
1 parent
a8a545690f
commit
d56230e04d
11 files changed
+329
-106
No files matched your search
@@ -449,6 +449,18 @@ async def lifespan(app: FastAPI) -> AsyncGenerator[None, None]:
|
||||
# Run Alembic migrations before anything else touches the schema.
|
||||
await _run_db_migrations()
|
||||
|
||||
# 预热 recall_budget cache(从 DB 批量加载,使 get_effective_memory_config 同步可读)
|
||||
try:
|
||||
from deerflow.config.memory_config import load_recall_budget_cache
|
||||
|
||||
_mc_store = getattr(app.state, "memory_config_store", None)
|
||||
if _mc_store is not None:
|
||||
_recall_budgets = await _mc_store.load_all()
|
||||
load_recall_budget_cache(_recall_budgets)
|
||||
logger.info("Memory config cache warmed: %d user override(s)", len(_recall_budgets))
|
||||
except Exception:
|
||||
logger.exception("Memory config cache warm-up failed (non-fatal)")
|
||||
|
||||
# Ensure admin user exists (auto-create on first boot)
|
||||
# Must run AFTER langgraph_runtime so app.state.store is available for thread migration
|
||||
await _ensure_admin_user(app)
|
||||
|
||||
Reference in new issue
Block a user