Skip to content
Closed
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
692 changes: 692 additions & 0 deletions docs/memory_diagnostics_guide.md

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ dependencies = [
"pandas>=2.3.1",
"pillow>=11.3.0",
"playwright>=1.54.0",
"psutil>=6.0.0",
"pyarrow>=20.0.0",
"pydantic>=2.11.7",
"pypinyin>=0.54.0",
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ openai>=1.95.0
pandas>=2.3.1
pillow>=11.3.0
playwright>=1.54.0
psutil>=6.0.0
pyarrow>=20.0.0
pydantic>=2.11.7
pypinyin>=0.54.0
Expand Down
5 changes: 3 additions & 2 deletions src/config/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
LEGACY_ENV_PATH: Path = (PROJECT_ROOT / ".env").resolve().absolute()
A_MEMORIX_LEGACY_CONFIG_PATH: Path = (CONFIG_DIR / "a_memorix.toml").resolve().absolute()
MMC_VERSION: str = "1.0.0-pre.21"
CONFIG_VERSION: str = "8.12.10"
CONFIG_VERSION: str = "8.12.11"
MODEL_CONFIG_VERSION: str = "1.17.0"

logger = get_logger("config")
Expand Down Expand Up @@ -645,7 +645,8 @@ def write_config_to_file(

if isinstance(config, Config):
try:
a_memorix_web = full_config_data["a_memorix"]["web"]
a_memorix_table = cast(Any, full_config_data["a_memorix"])
a_memorix_web = cast(Any, a_memorix_table["web"])
if "import_config" in a_memorix_web and "import" not in a_memorix_web:
a_memorix_web["import"] = a_memorix_web.pop("import_config")
except Exception:
Expand Down
118 changes: 118 additions & 0 deletions src/config/official_configs.py
Original file line number Diff line number Diff line change
Expand Up @@ -3022,6 +3022,124 @@ class DebugConfig(ConfigBase):
)
"""是否记录 LLM prompt cache 调试统计,默认关闭"""

enable_memory_diagnostics: bool = Field(
default=False,
json_schema_extra={
"x-widget": "switch",
"x-icon": "memory-stick",
"advanced": True,
},
)
"""是否启用长时间运行内存诊断,默认关闭"""

memory_diagnostics_interval_seconds: int = Field(
default=300,
ge=10,
json_schema_extra={
"x-widget": "number",
"x-icon": "timer",
"advanced": True,
},
)
"""内存诊断采样间隔,单位秒"""

memory_diagnostics_top_sessions: int = Field(
default=20,
ge=1,
json_schema_extra={
"x-widget": "number",
"x-icon": "list-ordered",
"advanced": True,
},
)
"""内存诊断输出的高占用会话数量"""

memory_diagnostics_jsonl_path: str = Field(
default="logs/memory_diagnostics/memory_diagnostics.jsonl",
json_schema_extra={
"x-widget": "input",
"x-icon": "file-json",
"advanced": True,
},
)
"""内存诊断 JSONL 输出路径"""

memory_diagnostics_enable_tracemalloc: bool = Field(
default=False,
json_schema_extra={
"x-widget": "switch",
"x-icon": "search-code",
"advanced": True,
},
)
"""是否启用 tracemalloc Python 分配快照诊断"""

memory_diagnostics_snapshot_growth_mb: int = Field(
default=100,
ge=1,
json_schema_extra={
"x-widget": "number",
"x-icon": "trending-up",
"advanced": True,
},
)
"""RSS 增长超过该阈值时输出 tracemalloc 差异,单位 MB"""

memory_diagnostics_binary_scan_message_limit: int = Field(
default=5000,
ge=0,
json_schema_extra={
"x-widget": "number",
"x-icon": "scan-search",
"advanced": True,
},
)
"""每轮最多扫描多少条缓存消息来估算二进制滞留;此为全量 session 共享预算,非单 session 上限,0 表示不扫描"""

memory_diagnostics_jsonl_max_total_size_mb: int = Field(
default=50,
ge=1,
json_schema_extra={
"x-widget": "number",
"x-icon": "hard-drive",
"advanced": True,
},
)
"""内存诊断 JSONL 当前文件和历史轮转文件的总大小上限,单位 MB"""

memory_diagnostics_warn_runtime_count: int = Field(
default=0,
ge=0,
json_schema_extra={
"x-widget": "number",
"x-icon": "message-circle-warning",
"advanced": True,
},
)
"""runtime 数量超过该阈值时输出 WARNING,0 表示不告警"""

memory_diagnostics_warn_message_cache_count: int = Field(
default=0,
ge=0,
json_schema_extra={
"x-widget": "number",
"x-icon": "message-circle-warning",
"advanced": True,
},
)
"""message_cache 总量超过该阈值时输出 WARNING,0 表示不告警"""

memory_diagnostics_warn_voice_binary_mb: int = Field(
default=0,
ge=0,
json_schema_extra={
"x-widget": "number",
"x-icon": "message-circle-warning",
"advanced": True,
},
)
"""语音二进制估算超过该阈值时输出 WARNING,单位 MB,0 表示不告警"""


class ExtraPromptItem(ConfigBase):
platform: str = Field(
Expand Down
4 changes: 4 additions & 0 deletions src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from src.manager.async_task_manager import async_task_manager
from src.plugin_runtime.integration import get_plugin_runtime_manager
from src.prompt.prompt_manager import prompt_manager
from src.services.memory_diagnostics_service import MemoryDiagnosticsTask, is_memory_diagnostics_enabled
from src.services.memory_flow_service import memory_automation_service

# from src.api.main import start_api_server
Expand Down Expand Up @@ -113,6 +114,9 @@ async def _init_components(self) -> None:

logger.info(t("startup.chat_manager_initialized"))
await memory_automation_service.start()
if is_memory_diagnostics_enabled():
await async_task_manager.add_task(MemoryDiagnosticsTask())
logger.info("内存诊断任务已启用")

# await asyncio.sleep(0.5) #防止logger输出飞了

Expand Down
Loading
Loading