From 519b4bfcf4cb8d8408935e953e4afe83d5c66292 Mon Sep 17 00:00:00 2001 From: ymq Date: Sat, 29 Aug 2026 16:51:48 +0800 Subject: [PATCH] =?UTF-8?q?fix(parse):=20DSML=E5=8F=8C=E7=AB=96=E7=BA=BF?= =?UTF-8?q?=E5=8F=98=E4=BD=93+=E5=8F=99=E8=BF=B0=E5=86=85=E5=B5=8Cjson?= =?UTF-8?q?=E4=BB=A3=E7=A0=81=E5=9D=97=E8=A7=A3=E6=9E=90=E2=80=94=E2=80=94?= =?UTF-8?q?=E5=AE=9E=E6=B5=8B=E4=B8=A4=E7=A7=8D=E6=96=B0=E5=A4=B1=E8=B4=A5?= =?UTF-8?q?=E5=BD=A2=E6=80=81=EF=BC=8C=E5=85=BC=E5=AE=B9=E7=AB=96=E7=BA=BF?= =?UTF-8?q?=E6=95=B0=E9=87=8F=E4=BB=BB=E6=84=8F=E5=8F=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pipeline_service/agent_loop.py | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/pipeline_service/agent_loop.py b/pipeline_service/agent_loop.py index 81c7622..d6cb05e 100644 --- a/pipeline_service/agent_loop.py +++ b/pipeline_service/agent_loop.py @@ -1766,12 +1766,13 @@ def _parse_agent_action(raw): # deepseek v4 原生格式(全角竖线):<|DSML||invoke name="...">…<|DSML||parameter name="...">value # 与旧版 同款解析:长上下文多轮时 deepseek 会自发输出该格式,不解析则全部判「未识别」→ 5 轮耗尽。 - m = re.search(r'<|DSML||invoke\s+name="([^"]+)"[^>]*>(.*?)', raw, re.DOTALL) + # ⚠️ 竖线数量会变:实测出现过单竖线 <|DSML||invoke> 和双竖线 <||DSML||invoke>,用 |+ 兼容任意数量。 + m = re.search(r'<|+DSML|+invoke\s+name="([^"]+)"[^>]*>(.*?)', raw, re.DOTALL) if m: tool = m.group(1).strip() body = m.group(2) params = {} - for pm in re.finditer(r'<|DSML||parameter\s+name="([^"]+)"[^>]*>(.*?)', body, re.DOTALL): + for pm in re.finditer(r'<|+DSML|+parameter\s+name="([^"]+)"[^>]*>(.*?)', body, re.DOTALL): val = pm.group(2).strip() try: val = json.loads(val) @@ -1809,6 +1810,20 @@ def _parse_agent_action(raw): return d except (json.JSONDecodeError, ValueError): pass + + # 叙述文本里嵌的 ```json 代码块(deepseek 常先说"我来加载技能"再贴 JSON tool_call)。 + # 上面 startswith("```") 只剥离开头的围栏,处理不了带叙述前缀的;这里全文找第一个可解析的动作 JSON。 + for fm in re.finditer(r'```(?:json)?\s*\n(.*?)\n?\s*```', raw, re.DOTALL): + try: + d = json.loads(fm.group(1).strip()) + except (json.JSONDecodeError, ValueError): + continue + if isinstance(d, dict) and 'action' in d: + return d + # 兼容 {"tool":..,"params":..} 无 action 字段的写法 + if isinstance(d, dict) and 'tool' in d: + return {"action": "tool_call", "tool": d.get("tool", ""), "params": d.get("params") or {}} + return {"action": "deliver", "result": raw}