mirror of
https://gitee.com/wanwujie/deer-flow
synced 2026-04-17 19:44:45 +08:00
* feat(内存存储): 添加可配置的内存存储提供者支持 实现内存存储的抽象基类 MemoryStorage 和文件存储实现 FileMemoryStorage 重构内存数据加载和保存逻辑到存储提供者中 添加 storage_class 配置项以支持自定义存储提供者 * refactor(memory): 重构内存存储模块并更新相关测试 将内存存储逻辑从updater模块移动到独立的storage模块 使用存储接口模式替代直接文件操作 更新所有相关测试以使用新的存储接口 * Update backend/packages/harness/deerflow/agents/memory/storage.py Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update backend/packages/harness/deerflow/agents/memory/storage.py Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * fix(内存存储): 添加线程安全锁并增加测试用例 添加线程锁确保内存存储单例初始化的线程安全 增加对无效代理名称的验证测试 补充单例线程安全性和异常处理的测试用例 * Update backend/tests/test_memory_storage.py Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * fix(agents): 使用统一模式验证代理名称 修改代理名称验证逻辑以使用仓库中定义的AGENT_NAME_PATTERN模式,确保代码库一致性并防止路径遍历等安全问题。同时更新测试用例以覆盖更多无效名称情况。 --------- Co-authored-by: Willem Jiang <willem.jiang@gmail.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
83 lines
2.5 KiB
Python
83 lines
2.5 KiB
Python
"""Configuration for memory mechanism."""
|
|
|
|
from pydantic import BaseModel, Field
|
|
|
|
|
|
class MemoryConfig(BaseModel):
|
|
"""Configuration for global memory mechanism."""
|
|
|
|
enabled: bool = Field(
|
|
default=True,
|
|
description="Whether to enable memory mechanism",
|
|
)
|
|
storage_path: str = Field(
|
|
default="",
|
|
description=(
|
|
"Path to store memory data. "
|
|
"If empty, defaults to `{base_dir}/memory.json` (see Paths.memory_file). "
|
|
"Absolute paths are used as-is. "
|
|
"Relative paths are resolved against `Paths.base_dir` "
|
|
"(not the backend working directory). "
|
|
"Note: if you previously set this to `.deer-flow/memory.json`, "
|
|
"the file will now be resolved as `{base_dir}/.deer-flow/memory.json`; "
|
|
"migrate existing data or use an absolute path to preserve the old location."
|
|
),
|
|
)
|
|
storage_class: str = Field(
|
|
default="deerflow.agents.memory.storage.FileMemoryStorage",
|
|
description="The class path for memory storage provider",
|
|
)
|
|
debounce_seconds: int = Field(
|
|
default=30,
|
|
ge=1,
|
|
le=300,
|
|
description="Seconds to wait before processing queued updates (debounce)",
|
|
)
|
|
model_name: str | None = Field(
|
|
default=None,
|
|
description="Model name to use for memory updates (None = use default model)",
|
|
)
|
|
max_facts: int = Field(
|
|
default=100,
|
|
ge=10,
|
|
le=500,
|
|
description="Maximum number of facts to store",
|
|
)
|
|
fact_confidence_threshold: float = Field(
|
|
default=0.7,
|
|
ge=0.0,
|
|
le=1.0,
|
|
description="Minimum confidence threshold for storing facts",
|
|
)
|
|
injection_enabled: bool = Field(
|
|
default=True,
|
|
description="Whether to inject memory into system prompt",
|
|
)
|
|
max_injection_tokens: int = Field(
|
|
default=2000,
|
|
ge=100,
|
|
le=8000,
|
|
description="Maximum tokens to use for memory injection",
|
|
)
|
|
|
|
|
|
# Global configuration instance
|
|
_memory_config: MemoryConfig = MemoryConfig()
|
|
|
|
|
|
def get_memory_config() -> MemoryConfig:
|
|
"""Get the current memory configuration."""
|
|
return _memory_config
|
|
|
|
|
|
def set_memory_config(config: MemoryConfig) -> None:
|
|
"""Set the memory configuration."""
|
|
global _memory_config
|
|
_memory_config = config
|
|
|
|
|
|
def load_memory_config_from_dict(config_dict: dict) -> None:
|
|
"""Load memory configuration from a dictionary."""
|
|
global _memory_config
|
|
_memory_config = MemoryConfig(**config_dict)
|