fix(llm): 重评直连OCG上游绕过hermes agent运行时 + 全线切flash + prompt输出纪律

事故根因(2026-07-21): hermes gateway /v1/chat/completions 非透传,
每个请求创建带工具的agent会话。一次603288重评螺旋35分钟/44次
terminal调用/输入153k token, 客户端超时后服务端空转, 重试叠加
新会话自我DDoS。

- llm_client 重写: OCG直连为主(key运行时从hermes config.yaml
  ocg-key6读取, 不落盘), gateway兜底(agent模式仅应急)
- REASSESS_MODEL: pro -> flash (A/B实测新prompt下质量差距微弱,
  flash快40%)
- prompt输出纪律: 【建议仓位】不可省略(非买入写'不新建仓'),
  禁止structured_data/XML/JSON块, 禁止寒暄开场白
- batch main 双通道预检(全挂才退出)
This commit is contained in:
hmo
2026-07-21 01:00:47 +08:00
parent 5b44086c8a
commit cd530c2463
3 changed files with 139 additions and 82 deletions
+17 -6
View File
@@ -16,7 +16,7 @@ from datetime import datetime
# ── 共享 LLM 客户端 + DB 工具(profile-scripts 硬链到同目录)──
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
sys.path.insert(0, "/home/hmo/MoFin")
from llm_client import call_llm, REASSESS_MODEL, gateway_alive
from llm_client import call_llm, REASSESS_MODEL, gateway_alive, ocg_alive
from mofin_db import snapshot_strategy_history
DB = "/home/hmo/MoFin/data/mofin.db"
@@ -266,13 +266,18 @@ PE={data.get('pe','?')}(最新财报) 市值={data.get('mcap','?')}亿
【建议止损】数字
【建议止盈】数字
【建议仓位】只有综合结论"买入"才输出此项。仓位计算公式:
【建议仓位】⚠️不可省略。综合结论"买入""不新建仓";为"买入"时按以下公式:
基础仓位按RR确定:RR<1.5→不推荐,RR1.5~3→8%RR3~5→12%RR5+→15%
大盘偏弱×0.8,大盘偏强×1.15
蓝筹/白马×1.2,成长×0.85,题材/短线×0.6
最终仓位范围:5%~20%
同时考虑:现金{cash}元足够买多少手。
输出格式:"X%(理由:一句话说明为什么这个仓位)"""
输出格式:"X%(理由:一句话说明为什么这个仓位)"
⚠️ 输出纪律(必须遵守):
1. 直接以【维持或修改】开头,禁止任何寒暄、开场白、分隔线
2. 禁止输出 <structured_data> 或任何 XML/JSON/代码块
3. 所有【】节标题一个都不能少"""
def parse_response(text):
"""从LLM回复中提取策略参数"""
result = {"signal": "", "entry_low": 0, "entry_high": 0, "stop_loss": 0, "take_profit": 0, "position": ""}
@@ -420,10 +425,16 @@ def process_stock(code, force_today=False):
return True
def main():
# ── Gateway 预检:不可用则立即退出(不阻塞 cron)──
if not gateway_alive():
print("[FATAL] Hermes Gateway 不可用,退出(检查 http://127.0.0.1:8643/v1/models")
# ── 双通道预检:OCG直连 + hermes gateway 兜底,全挂才退出 ──
_ocg_ok = ocg_alive()
_gw_ok = gateway_alive()
if not _ocg_ok and not _gw_ok:
print("[FATAL] OCG上游与hermes gateway均不可用,退出")
sys.exit(1)
if not _ocg_ok:
print("[WARN] OCG直连不可用,将使用gateway兜底(agent运行时,较慢)")
if not _gw_ok:
print("[WARN] hermes gateway不可用,仅使用OCG直连")
codes = []
force_today = "--today" in sys.argv