feat: intercept literal [tool_calls] arrays in generated text and map to actual function calls

This commit is contained in:
GitHub Actions
2026-05-06 17:27:10 +08:00
parent cca9c99e22
commit 5911e4322e
2 changed files with 68 additions and 1 deletions

View File

@@ -182,6 +182,20 @@ def _json_tool_candidate_from_text(text: str) -> dict[str, Any] | None:
return None
def _extract_tool_calls_from_text(text: str) -> list[dict[str, Any]] | None:
text = text.strip()
match = re.search(r"\[tool_calls\]\s*(\[.*\])", text, re.DOTALL)
if not match:
return None
try:
parsed = json.loads(match.group(1))
if isinstance(parsed, list) and len(parsed) > 0 and isinstance(parsed[0], dict):
return parsed
except Exception:
pass
return None
def _tool_code_single_arg_name(
tools: list[dict[str, Any]] | None, forced_tool_name: str
) -> str | None: