fix: _parse_agent_action 解析 deepseek XML tool_calls(原生 FC 输出格式)

This commit is contained in:
p 2026-08-14 11:04:03 +08:00
parent d89ec3c784
commit 6c878a2abf

View File

@ -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<tool_calls><invoke name="..."><parameter name="...">...</parameter></invoke></tool_calls>
m = re.search(r'<invoke\s+name="([^"]+)"\s*>(.*?)</invoke>', raw, re.DOTALL)
if m:
tool = m.group(1).strip()
body = m.group(2)
params = {}
for pm in re.finditer(r'<parameter\s+name="([^"]+)"\s*>(.*?)</parameter>', 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: