# 莫荷系统架构文档 — 完整总览 > 最后更新:2026-06-11 > 维护人:莫荷(Hermes Agent) > 铁律:任何系统改动必须先读本文档,改完必须同步更新 --- ## 一、系统总览 ``` ┌──────────────────────────────────────────────────────────────┐ │ Linux 192.168.1.246 │ │ │ │ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ │ │ │ 默认gateway │ │ 知微gateway │ │ 小果gateway │ │ │ │ :8642 │ │ :8643 │ │ :8645 │ │ │ │ 微信+XMPP │ │ position- │ │ xiaoguo │ │ │ │ mohe网关 │ │ analyst │ │ profile │ │ │ └──────┬──────┘ └──────┬──────┘ └──────┬──────┘ │ │ │ │ │ │ │ ▼ ▼ ▼ │ │ ┌─────────────────────────────────────────────────┐ │ │ │ state.db (SQLite) │ │ │ │ sessions / messages / FTS5 / compression_locks │ │ │ │ 消息存储:全量保存,永不删除 │ │ │ │ 上下文加载:最多200条,永不压缩 │ │ │ └─────────────────────────────────────────────────┘ │ │ │ │ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ │ │ │ xmpp_bot │ │ xmpp_ │ │ xmpp_ │ │ │ │ mohe │ │ zhiwei_bot │ │ xiaoguo_bot │ │ │ │ mohe@yoin │ │ zhiwei@yoin │ │ xiaoguo@ │ │ │ │ .fun │ │ .fun │ │ yoin.fun │ │ │ └──────┬──────┘ └──────┬──────┘ └──────┬──────┘ │ │ │ │ │ │ │ └──────┬─────────┴────────┬───────┘ │ │ ▼ ▼ │ │ ┌──────────────┐ ┌──────────────┐ │ │ │ ejabberd │ │ 内核组 │ │ │ │ Docker │ │ coregroup@ │ │ │ │ port 5222 │ │ conference │ │ │ └──────────────┘ │ .yoin.fun │ │ │ └──────────────┘ │ │ │ │ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ │ │ │ 价格监控 │ │ cron调度器 │ │ Obsidian │ │ │ │ 1分钟·纯脚本 │ │ 14个jobs │ │ 知识库 │ │ │ └─────────────┘ └─────────────┘ │ :8890 │ │ │ └─────────────┘ │ └──────────────────────────────────────────────────────────────┘ │ │ ▼ ▼ ┌─────────────────┐ ┌─────────────────┐ │ Windows 192.168 │ │ Mac 192.168.1 │ │ .1.16 │ │ .122 │ │ 小小莫(wechat) │ │ 小果(oMLX) │ │ OpenCode :4096 │ │ Qwen3.6-27B │ │ 微信通道 :5801 │ │ :18003 │ └─────────────────┘ └─────────────────┘ ``` ## 二、Gateway 一览 | 端口 | 名称 | Profile | PID(当前) | 用途 | |------|------|---------|-----------|------| | 8642 | 默认gateway | 默认 | 1925504 | 微信小荷 + XMPP mohe | | 8643 | 知微gateway | position-analyst | 1913506 | 知微分析 | | 8645 | 小果gateway | xiaoguo | 1925602 | 小果Mac端 | | 8646 | mohe gateway | mohe | 1620276 | mohe独立网关 | 每个gateway共用 `/home/hmo/hermes-agent/hermes_state.py` 里的 `get_messages_as_conversation()` — **LIMIT 200硬截断**。 ## 三、XMPP Bot 架构 ### 3.1 Bot 列表 | Bot | JID | 服务名 | 脚本路径 | 接入gateway | |-----|-----|--------|---------|------------| | 莫荷 | mohe@yoin.fun | xmpp-bot | /home/hmo/xmpp_bot.py | :8642 | | 知微 | zhiwei@yoin.fun | xmpp-zhiwei | /home/hmo/xmpp_zhiwei_bot.py | :8643 | | 小果 | xiaoguo@yoin.fun | xmpp-xiaoguo | /home/hmo/xmpp_xiaoguo_bot.py | :8645 | ### 3.2 连接管理(2026-06-11 修复) **禁用** `auto_reconnect = True`(与手动重连环冲突,导致"Replaced by new connection"循环) **禁用** `xep_0199` ping 保活(ejabberd不支持,导致ping超时→误判断线) **重连机制**: - 主循环每15秒检查 `is_connected()` - 断线后指数退避重连:1s → 2s → 4s → ... → 60s max - 重连后自动重新加入 MUC(内核组 coregroup@conference.yoin.fun) **历史问题**: - 2026-06-08: bot断线后无法自动重连,session膨胀到3700条/26M tokens - 2026-06-10: auto_reconnect导致10个重复连接 - 2026-06-11: 修复auto_reconnect冲突 + API key拼写错误 ### 3.3 群聊规则 Bot只回复内核组中来自 `hmo` 或 `xxm` 的消息。私聊只回复 `hmo@yoin.fun`。 ## 四、Session 管理 —— 核心设计(2026-06-10 最终方案) ### 4.1 方案:硬截断200条 + 永不压缩 ```python # hermes_state.py → get_messages_as_conversation() SELECT id, role, content, ... FROM ( SELECT id, role, content, ... FROM messages WHERE session_id = ? AND active = 1 ORDER BY id DESC LIMIT 200 ← 只取最近200条 ) ORDER BY id ASC ← 按正序排回 ``` ### 4.2 Compression 配置(所有profile统一) ```yaml compression: enabled: false ← 永久关闭 threshold: 0.99 protect_last_n: 200 hygiene_hard_message_limit: 100000 ``` ### 4.3 效果 | 指标 | 之前 | 之后 | |------|------|------| | 每次请求token | 26M(全量加载) | ~22K(200条) | | 上下文窗口用量 | 2500% | 2.2% | | 响应时间 | 10分钟+超时 | 10-20秒 | | 内容丢失 | 压缩丢细节 | 永不丢失 | | 旧消息可查 | 压缩后摘要 | 全量DB可搜 | ### 4.4 Session 列表(当前) | Session ID | 消息数 | 用途 | |-----------|--------|------| | sisyphus | 9504 | 微信(旧session,已重建) | | xmpp-mohe | 3705 | XMPP mohe(旧session) | | xmpp-mohe-v2 | ~200 | XMPP mohe(新session,LIMIT 200) | | xmpp-zhiwei | 2241 | 知微 | | 20260610_090241_2235fb | ~900 | 当前CLI会话 | ## 五、Provider 链(2026-06-10 最终版) | Agent | 默认 | Fallback 1 | Fallback 2 | Fallback 3 | |-------|------|-----------|-----------|-----------| | **我(CLI)** | ocg-new | ocg-old | volcengine | - | | **mohe gateway** | ocg-new | ocg-old | volcengine | - | | **知微** | ocg-old | ocg-new | volcengine(cred池) | - | | **小果** | volcengine | ocg-old | ocg-new | oMLX(本地Mac) | **当前实际状态(2026-06-11):** - ocg-new: ✅ 可用(当前会话走这个) - ocg-old: ⚠️ 返回403但gateway cred pool缓存了有效key - volcengine: ❌ 周配额已尽,6月15日周一恢复 ## 六、SOUL.md 关键规则(2026-06-10 最终版) 位置:`/home/hmo/.hermes/profiles/default/SOUL.md` ### 沟通方式 - 对老爸:直接、不加修饰 - 反驳时:**必须带证据**(日志、数据、代码、截图)。不是为了显得聪明而反驳 - 听指令:用户明确说"闭嘴""停"时立即停止,不继续分析不解释 ### 行动铁律 — 讲证据 1. 发现问题 → 2. 收集证据(至少两条独立证据) → 3. 验证假设 → 4. 只改对的 → 5. 改完验证 - 禁止猜根因、没有证据就动手、猜用户意图、多个改动同时做 ### 授权边界 - ✅ 直接行动:读文件、查日志、搜知识库、分析数据、提建议 - ⚠️ 问清楚再做:改系统配置、重启服务、清数据、写文件 - ❌ 必须等批准:不可逆删除、修改API key、改provider链、清session ## 七、知识库(Obsidian) 路径:`/home/hmo/Obsidian/` HTTP API:`:8890`(只读) 结构: ``` Obsidian/ ├── raw/ — 原始资料(只追加只读) ├── knowledge/ — 加工笔记(tech/finance/ai/psychology/education/life) ├── index.md — 全库索引 ├── SCHEMA.md — 操作规则 └── log.md — 更新日志 ``` ## 八、MoFin 股票系统 详见 `EXPERT_SYSTEM_DESIGN.md`,核心: - 14个cron jobs(5个纯脚本+9个LLM) - 价格监控每1分钟腾讯批量API - XMPP中继推送报告 ## 九、近期改动日志 ### 2026-06-11 - LIMIT 200硬截断 + 关闭所有compression - SOUL.md 最终版定稿 - XMPP bot重连逻辑修复(删除auto_reconnect + ping保活) - API key typo修复(知微bot `hermess123` → `hermes123`) - 小果provider链:volc → ocg-old → ocg-new → oMLX - 默认provider链:ocg-new → ocg-old → volcengine ### 2026-06-10 - 重建SOUL.md(讲证据+授权边界+责任闭环) - 发现并清除orphaned compression flag - 多个gateway反复重启,systemd服务冲突 - Windows wechat_agent API key不匹配 ### 2026-06-09 - 知微SOUL新增对话识别规则 - position-analyst 启用压缩 - 价格监控全面改造(纯脚本+腾讯批量API)