mirror of
https://github.com/CJackHwang/ds2api.git
synced 2026-05-04 08:25:26 +08:00
- 引入 parseTextKVToolCalls 解析器以处理混杂文本或带历史记录套壳(如 [TOOL_CALL_HISTORY])输出的函数调用提取。 - 将其作为 JSON 和 XML 的 fallback 解析手段集成到主流程。 - 添加单元测试用例且更新相关语义说明文档。
1.6 KiB
1.6 KiB
Tool call parsing semantics (Go canonical spec)
This document defines the cross-runtime contract for ParseToolCallsDetailed / parseToolCallsDetailed.
Output contract
calls: accepted tool calls with normalized tool names.sawToolCallSyntax: true when tool-call-like syntax is detected (tool_calls,<tool_call>,<function_call>,<invoke>) or a valid call is parsed.rejectedByPolicy: true when parser extracted call syntax but all calls are rejected by allow-list policy.rejectedToolNames: de-duplicated rejected tool names in first-seen order.
Parse pipeline
- Strip fenced code blocks for non-standalone parsing.
- Build candidates from:
- full text,
- fenced JSON snippets,
- extracted JSON objects around
tool_calls, - first
{to last}object slice.
- Parse each candidate in order:
- JSON payload parser (
tool_calls, list, single call object), - XML/Markup parser (
<tool_call>,<function_call>,<invoke>; supports attributes + nested fields), - Text KV fallback parser (
function.name: <name>...function.arguments: {json}).
- JSON payload parser (
- Stop at first candidate that yields at least one call.
Name normalization policy
When matching parsed names against configured tools:
- exact match,
- case-insensitive match,
- namespace tail match (
a.b.c=>c), - loose alnum match (remove non
[a-z0-9], compare).
Standalone mode
Standalone mode (ParseStandaloneToolCallsDetailed) parses the whole input directly (no candidate slicing), while still applying:
- example-context guard,
- JSON then markup fallback,
- the same allow-list normalization policy.