From 6c878a2abf23796b1fdafee6aa3456b7cd39d1ff Mon Sep 17 00:00:00 2001 From: p Date: Fri, 14 Aug 2026 11:04:03 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=5Fparse=5Fagent=5Faction=20=E8=A7=A3?= =?UTF-8?q?=E6=9E=90=20deepseek=20XML=20tool=5Fcalls=EF=BC=88=E5=8E=9F?= =?UTF-8?q?=E7=94=9F=20FC=20=E8=BE=93=E5=87=BA=E6=A0=BC=E5=BC=8F=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pipeline_service/agent_loop.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/pipeline_service/agent_loop.py b/pipeline_service/agent_loop.py index bd549c6..b38663f 100644 --- a/pipeline_service/agent_loop.py +++ b/pipeline_service/agent_loop.py @@ -13,6 +13,7 @@ v3.4.0 新增: import asyncio import json import os +import re import subprocess import logging @@ -465,6 +466,26 @@ def _parse_agent_action(raw): raw = (raw or "").strip() if raw.startswith("```"): raw = raw.split("\n", 1)[1].rsplit("```", 1)[0].strip() + + # deepseek 原生 function calling 输出 XML:... + m = re.search(r'(.*?)', raw, re.DOTALL) + if m: + tool = m.group(1).strip() + body = m.group(2) + params = {} + for pm in re.finditer(r'(.*?)', body, re.DOTALL): + val = pm.group(2).strip() + try: + val = json.loads(val) + except (json.JSONDecodeError, ValueError): + pass + params[pm.group(1)] = val + if tool in ('deliver', 'deliver_result', 'submit', 'finish'): + return {"action": "deliver", **params} + if tool in ('ask', 'ask_question', 'ask_user'): + return {"action": "ask", "question": params.get("question", "")} + return {"action": "tool_call", "tool": tool, "params": params} + try: d = json.loads(raw) if isinstance(d, dict) and 'action' in d: