diff --git a/CHANGELOG.md b/CHANGELOG.md
index 04832f9a2..ff5f2da2f 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,6 +1,7 @@
## Unreleased
- When the prompt opened no thought, take a thought only at the start of the reply, as llama.cpp does: any other thinking tag, such as a `` before any ``, a `` later in the reply or a second ``, is now content in generic, Llama 3, GLM 4.5, Kimi K2, LFM2, Laguna, Granite, MiniCPM5, Mistral Nemo, Apertus, Hunyuan V3 and DeepSeek R1, V3.2 and V4 replies, and after the start of a Hermes or Qwen3-Coder XML reply. The stream used to depend on how the reply was chunked and could repeat text as both content and reasoning ([#1865](https://github.com/leehack/llamadart/issues/1865)).
+- Parse Qwen3-Coder XML replies (Qwen3-Coder, Qwen3.5, StepFun3.5-Flash) as llama.cpp does: text from the first `` on that is not a valid call, such as an invalid call or text after the calls, is dropped instead of kept as content, and only the first call counts without `parallelToolCalls`. Qwen3-Coder replies have no reasoning, and StepFun3.5-Flash with thinking off ends its thought at `` or `` ([#1531](https://github.com/leehack/llamadart/issues/1531)).
## 0.19.2
diff --git a/lib/src/core/engine/chat_completion_stream_parser.dart b/lib/src/core/engine/chat_completion_stream_parser.dart
index 908763107..8a58904b7 100644
--- a/lib/src/core/engine/chat_completion_stream_parser.dart
+++ b/lib/src/core/engine/chat_completion_stream_parser.dart
@@ -14,6 +14,7 @@ import '../template/handlers/cohere2_moe_handler.dart';
import '../template/handlers/command_r7b_handler.dart';
import '../template/handlers/llama3_handler.dart';
import '../template/peg_chat_parser.dart';
+import '../template/template_internal_metadata.dart';
import '../template/thinking_utils.dart';
enum _ToolStreamingMode { undecided, raw, parsed }
@@ -105,10 +106,9 @@ class ChatCompletionStreamParser {
final markers = closedThoughtMarkers(templateResult.format);
final held = StreamIterator(_heldUntilAny(tokenStream, markers));
if (await held.moveNext()) {
- // A Cohere2 MoE or Seed-OSS reply that reaches a marker then parses as
- // after the forced-open prompt llama.cpp renders.
- if ((templateResult.format == ChatFormat.cohere2Moe.index ||
- templateResult.format == ChatFormat.seedOss.index) &&
+ // Such a reply that reaches a marker then parses as after the
+ // forced-open prompt llama.cpp renders.
+ if (reopensClosedThought(templateResult.format) &&
markers.any(held.current.contains)) {
result = _withForcedOpenThought(templateResult);
}
@@ -616,6 +616,7 @@ class ChatCompletionStreamParser {
thinkingForcedOpen: templateResult.thinkingForcedOpen,
thoughtClosedForThinkingOff: thoughtClosedForThinkingOff,
thinkingForcedClosed: thinkingForcedClosed,
+ singleToolCall: singleToolCallOf(templateResult),
parser: templateResult.parser,
tools: tools,
);
@@ -797,20 +798,23 @@ class ChatCompletionStreamParser {
/// [result] with its prompt's thought forced open.
static LlamaChatTemplateResult _withForcedOpenThought(
LlamaChatTemplateResult result,
- ) => withThinkingForcedClosed(
- LlamaChatTemplateResult(
- prompt: result.prompt,
- format: result.format,
- grammar: result.grammar,
- grammarLazy: result.grammarLazy,
- additionalStops: result.additionalStops,
- preservedTokens: result.preservedTokens,
- grammarTriggers: result.grammarTriggers,
- thinkingForcedOpen: true,
- parser: result.parser,
- tokenCount: result.tokenCount,
+ ) => withSingleToolCall(
+ withThinkingForcedClosed(
+ LlamaChatTemplateResult(
+ prompt: result.prompt,
+ format: result.format,
+ grammar: result.grammar,
+ grammarLazy: result.grammarLazy,
+ additionalStops: result.additionalStops,
+ preservedTokens: result.preservedTokens,
+ grammarTriggers: result.grammarTriggers,
+ thinkingForcedOpen: true,
+ parser: result.parser,
+ tokenCount: result.tokenCount,
+ ),
+ closed: thinkingForcedClosedOf(result),
),
- closed: thinkingForcedClosedOf(result),
+ single: singleToolCallOf(result),
);
/// [tokens] with their text held until it contains one of [markers], or
diff --git a/lib/src/core/template/chat_format_registry.dart b/lib/src/core/template/chat_format_registry.dart
index e3c8492a7..916690071 100644
--- a/lib/src/core/template/chat_format_registry.dart
+++ b/lib/src/core/template/chat_format_registry.dart
@@ -89,6 +89,7 @@ final class ChatFormatTraits {
this.keepsForcedThoughtVerbatim = false,
this.closedThoughtKeepsTagsAsContent = false,
this.takesThoughtOnlyAtReplyStart = false,
+ this.reopensThoughtClosedForThinkingOff = false,
this.forcedThoughtContentOpenings = const [],
this.mayEmbedToolEnvelopeAfterContent = false,
this.hasRepeatedContentChannels = false,
@@ -131,6 +132,11 @@ final class ChatFormatTraits {
/// only at the start of the reply, so other thinking tags are content.
final bool takesThoughtOnlyAtReplyStart;
+ /// Whether llama.cpp keeps open the thought the handler closed for thinking
+ /// off, so a reply that shows a thinking tag or one of
+ /// [forcedThoughtContentOpenings] parses as after a forced-open prompt.
+ final bool reopensThoughtClosedForThinkingOff;
+
/// Markers that, with [keepsForcedThoughtVerbatim], also end a forced-open
/// thought when they come before its end tag, and start the content.
final List forcedThoughtContentOpenings;
@@ -300,6 +306,7 @@ chatFormatRegistrations = List.unmodifiable([
qualifiesJsonSchemaTools: false,
toolCallOpening: CommandR7BHandler.toolCallOpening,
keepsForcedThoughtVerbatim: true,
+ reopensThoughtClosedForThinkingOff: true,
forcedThoughtContentOpenings:
Cohere2MoeHandler.forcedThoughtContentOpenings,
disabledByResponseSchema: true,
@@ -384,6 +391,7 @@ chatFormatRegistrations = List.unmodifiable([
toolCallOpening: XmlToolCallFormat.qwen3Coder.toolCallOpening,
closedThoughtKeepsTagsAsContent: true,
keepsForcedThoughtVerbatim: true,
+ reopensThoughtClosedForThinkingOff: true,
forcedThoughtContentOpenings: [XmlToolCallFormat.qwen3CoderScopeStart],
),
),
@@ -448,6 +456,7 @@ chatFormatRegistrations = List.unmodifiable([
qualifiesJsonSchemaTools: false,
toolCallOpening: XmlToolCallFormat.seedOss.toolCallOpening,
keepsForcedThoughtVerbatim: true,
+ reopensThoughtClosedForThinkingOff: true,
),
),
ChatFormatRegistration(
diff --git a/lib/src/core/template/chat_template_engine.dart b/lib/src/core/template/chat_template_engine.dart
index 573ce71a1..80b4142d5 100644
--- a/lib/src/core/template/chat_template_engine.dart
+++ b/lib/src/core/template/chat_template_engine.dart
@@ -759,6 +759,7 @@ class ChatTemplateEngine {
parseToolCalls: parseToolCalls,
thinkingForcedOpen: rendered.thinkingForcedOpen,
thinkingForcedClosed: thinkingForcedClosedOf(rendered),
+ singleToolCall: singleToolCallOf(rendered),
parser: rendered.parser,
tools: tools,
);
@@ -782,6 +783,7 @@ class ChatTemplateEngine {
required bool thinkingForcedOpen,
required bool thinkingForcedClosed,
bool promptOpensNoThought = false,
+ bool singleToolCall = false,
String? parser,
List? tools,
}) {
@@ -794,6 +796,7 @@ class ChatTemplateEngine {
thinkingForcedOpen: thinkingForcedOpen,
thinkingForcedClosed: thinkingForcedClosed,
promptOpensNoThought: promptOpensNoThought,
+ singleToolCall: singleToolCall,
parser: parser,
tools: tools,
);
@@ -845,6 +848,7 @@ class ChatTemplateEngine {
required bool thinkingForcedOpen,
required bool thinkingForcedClosed,
required bool promptOpensNoThought,
+ required bool singleToolCall,
String? parser,
List? tools,
}) {
@@ -910,6 +914,7 @@ class ChatTemplateEngine {
parseToolCalls: parseToolCalls,
thinkingForcedOpen: thinkingForcedOpen,
thoughtTagsAreText: thoughtTagsAreText,
+ singleToolCall: singleToolCall,
);
} else if (handler is DeepseekV3Handler) {
result = handler.parse(
@@ -1146,29 +1151,42 @@ bool takesThoughtOnlyAtReplyStart(int formatIndex) =>
).traits.takesThoughtOnlyAtReplyStart;
/// The markers that show where a reply ends a thought that a handler closed
-/// for thinking off: the format's thinking tags and, for Cohere2 MoE, where
-/// its text or action starts, as llama.cpp ends the thought it keeps open.
+/// for thinking off: the format's thinking tags and its
+/// [ChatFormatTraits.forcedThoughtContentOpenings], such as where a Cohere2
+/// MoE text or action starts, as llama.cpp ends the thought it keeps open.
List closedThoughtMarkers(int formatIndex) {
final tags = ChatTemplateEngine.thinkingTagsFor(formatIndex);
return [
tags.startTag,
tags.endTag,
- if (formatIndex == ChatFormat.cohere2Moe.index)
- ...Cohere2MoeHandler.forcedThoughtContentOpenings,
+ ..._traitsOf(formatIndex).forcedThoughtContentOpenings,
];
}
+/// Whether llama.cpp keeps open the thought that a [formatIndex] handler
+/// closed for thinking off, so that a reply showing one of
+/// [closedThoughtMarkers] parses as after a forced-open prompt.
+bool reopensClosedThought(int formatIndex) =>
+ _traitsOf(formatIndex).reopensThoughtClosedForThinkingOff;
+
+ChatFormatTraits _traitsOf(int formatIndex) =>
+ formatIndex < ChatFormat.values.length
+ ? chatFormatRegistration(ChatFormat.values[formatIndex]).traits
+ : ChatFormatTraits.none;
+
/// Parses [output] of a render of this engine, whose internal thought mark
/// [ChatTemplateEngine.parse] cannot see.
///
-/// llama.cpp keeps open the thought a Seed-OSS or Cohere2 MoE handler closed
-/// for thinking off ([thoughtClosedForThinkingOff]), so a reply that shows one
-/// of [closedThoughtMarkers] parses as after a forced-open prompt. Without it
+/// llama.cpp keeps open the thought a Seed-OSS, Cohere2 MoE or Qwen3-Coder XML
+/// handler closed for thinking off ([thoughtClosedForThinkingOff]), so a reply
+/// that shows one of [closedThoughtMarkers] parses as after a forced-open
+/// prompt. Without it
/// or [thinkingForcedOpen] the prompt opened no thought, so a Seed-OSS end tag
/// in a reply that does not start with a thought is content, a format with
/// [ChatFormatTraits.takesThoughtOnlyAtReplyStart] takes a thought only at the
/// start of the reply, and a DeepSeek V3 reply with an end tag before any
-/// start tag keeps its thinking tags as content.
+/// start tag keeps its thinking tags as content. With [singleToolCall], a
+/// Qwen3-Coder XML reply has at most one tool call.
ChatParseResult parseRenderedOutput(
int formatIndex,
String output, {
@@ -1178,6 +1196,7 @@ ChatParseResult parseRenderedOutput(
bool parseToolCalls = true,
bool thinkingForcedOpen = false,
bool thinkingForcedClosed = false,
+ bool singleToolCall = false,
String? parser,
List? tools,
}) => ChatTemplateEngine._parseOutput(
@@ -1189,11 +1208,11 @@ ChatParseResult parseRenderedOutput(
thinkingForcedOpen:
thinkingForcedOpen ||
(thoughtClosedForThinkingOff &&
- (formatIndex == ChatFormat.seedOss.index ||
- formatIndex == ChatFormat.cohere2Moe.index) &&
+ reopensClosedThought(formatIndex) &&
closedThoughtMarkers(formatIndex).any(output.contains)),
thinkingForcedClosed: thinkingForcedClosed,
promptOpensNoThought: !thoughtClosedForThinkingOff,
+ singleToolCall: singleToolCall,
parser: parser,
tools: tools,
);
diff --git a/lib/src/core/template/handlers/qwen3_coder_xml_handler.dart b/lib/src/core/template/handlers/qwen3_coder_xml_handler.dart
index 85fcead7e..74d9539a5 100644
--- a/lib/src/core/template/handlers/qwen3_coder_xml_handler.dart
+++ b/lib/src/core/template/handlers/qwen3_coder_xml_handler.dart
@@ -79,7 +79,9 @@ class Qwen3CoderXmlHandler extends ChatTemplateHandler
metadata[internalParallelToolCallsMetadataKey] == 'true';
final toolChoiceNone = toolChoice == ToolChoice.none.name;
final toolChoiceRequired = toolChoice == ToolChoice.required.name;
- final thinkingForcedClosed = isThinkingForcedClosed(prompt);
+ // llama.cpp takes no thought from a reply to a template without one.
+ final thinkingForcedClosed =
+ isThinkingForcedClosed(prompt) || !templateSource.contains('');
var thinkingForcedOpen = false;
var thoughtClosed = false;
if (isThinkingForcedOpen(prompt, startTag: '')) {
@@ -145,9 +147,12 @@ class Qwen3CoderXmlHandler extends ChatTemplateHandler
: const [],
parser: parser,
);
- return withThoughtClosedForThinkingOff(
- withThinkingForcedClosed(rendered, closed: thinkingForcedClosed),
- closed: thoughtClosed,
+ return withSingleToolCall(
+ withThoughtClosedForThinkingOff(
+ withThinkingForcedClosed(rendered, closed: thinkingForcedClosed),
+ closed: thoughtClosed,
+ ),
+ single: hasTools && !parallelToolCalls,
);
}
@@ -306,8 +311,12 @@ class Qwen3CoderXmlHandler extends ChatTemplateHandler
}
/// Parses Qwen XML using declared tool schemas when [tools] is supplied.
- /// Invalid calls remain content and cannot become executable tool deltas.
- /// With [thoughtTagsAreText], all of [output] is content and tool calls.
+ ///
+ /// As in llama.cpp, the content ends at the first ``, the calls
+ /// are those of the valid scopes that follow it, only the first with
+ /// [singleToolCall], and the rest of the reply is dropped, so an invalid
+ /// call never becomes an executable tool delta. With [thoughtTagsAreText],
+ /// all of [output] is content and tool calls.
@override
ChatParseResult parseWithTools(
String output, {
@@ -316,6 +325,7 @@ class Qwen3CoderXmlHandler extends ChatTemplateHandler
bool parseToolCalls = true,
bool thinkingForcedOpen = false,
bool thoughtTagsAreText = false,
+ bool singleToolCall = false,
}) {
final result = parseXmlToolCalls(
output,
@@ -329,6 +339,8 @@ class Qwen3CoderXmlHandler extends ChatTemplateHandler
// (`620d2225`) a forced-open thought as generated.
unescapeReasoning: false,
verbatimForcedThought: true,
+ endsAtLastCall: true,
+ maxToolCalls: singleToolCall ? 1 : null,
);
return ChatParseResult(
content: result.content.trim(),
diff --git a/lib/src/core/template/template_internal_metadata.dart b/lib/src/core/template/template_internal_metadata.dart
index 20cd9f11d..68f1f43d0 100644
--- a/lib/src/core/template/template_internal_metadata.dart
+++ b/lib/src/core/template/template_internal_metadata.dart
@@ -79,3 +79,23 @@ LlamaChatTemplateResult withLfm2AutoGrammarOf(
copy.grammar == source.grammar &&
copy.grammarLazy == source.grammarLazy,
);
+
+final Expando _singleToolCall = Expando('llamadart.singleToolCall');
+
+/// Returns [result], marked when [single] as a render whose request allows at
+/// most one tool call.
+///
+/// The Qwen3-Coder XML parse then takes only the first call, as llama.cpp's
+/// parser does without parallel tool calls. Internal engine plumbing, not part
+/// of the public API.
+LlamaChatTemplateResult withSingleToolCall(
+ LlamaChatTemplateResult result, {
+ required bool single,
+}) {
+ if (single) _singleToolCall[result] = true;
+ return result;
+}
+
+/// Whether [withSingleToolCall] marked [result].
+bool singleToolCallOf(LlamaChatTemplateResult result) =>
+ _singleToolCall[result] ?? false;
diff --git a/lib/src/core/template/thinking_utils.dart b/lib/src/core/template/thinking_utils.dart
index b52ec36ba..27aefb7df 100644
--- a/lib/src/core/template/thinking_utils.dart
+++ b/lib/src/core/template/thinking_utils.dart
@@ -290,7 +290,8 @@ final Expando _thinkingForcedClosed = Expando(
);
/// Returns [result], marked when [closed] as rendered by a template that ended
-/// the prompt with an empty thought.
+/// the prompt with an empty thought or, for Qwen3-Coder XML, that has no
+/// thinking tags.
///
/// Only the template's own render counts, not a thought a handler closes
/// because thinking is off. The DeepSeek V3, Hermes and Qwen3-Coder XML
@@ -331,14 +332,18 @@ LlamaChatTemplateResult withThoughtClosedForThinkingOff(
bool thoughtClosedForThinkingOffOf(LlamaChatTemplateResult result) =>
_thoughtClosedForThinkingOff[result] ?? false;
-/// Returns [copy] with the thought marks of [source], which it copies.
+/// Returns [copy] with the thought and tool-call marks of [source], which it
+/// copies.
LlamaChatTemplateResult withThoughtMarksOf(
LlamaChatTemplateResult copy,
LlamaChatTemplateResult source,
) => withLfm2AutoGrammarOf(
- withThoughtClosedForThinkingOff(
- withThinkingForcedClosed(copy, closed: thinkingForcedClosedOf(source)),
- closed: thoughtClosedForThinkingOffOf(source),
+ withSingleToolCall(
+ withThoughtClosedForThinkingOff(
+ withThinkingForcedClosed(copy, closed: thinkingForcedClosedOf(source)),
+ closed: thoughtClosedForThinkingOffOf(source),
+ ),
+ single: singleToolCallOf(source),
),
source,
);
diff --git a/lib/src/core/template/xml_tool_call_format.dart b/lib/src/core/template/xml_tool_call_format.dart
index 44642fb71..6602d1cb4 100644
--- a/lib/src/core/template/xml_tool_call_format.dart
+++ b/lib/src/core/template/xml_tool_call_format.dart
@@ -337,6 +337,12 @@ String _literal(String value) {
/// content and tool calls. With [verbatimForcedThought], a forced-open
/// thought is the text before the first [endThink] or tool-call scope, kept as
/// generated, and the rest is content.
+///
+/// With [endsAtLastCall], for a [XmlToolCallFormat.repeatsScope] format, the
+/// reply ends at its last tool call, as in llama.cpp's Qwen3-Coder parser: the
+/// content is the text before the first scope, the calls are those of the
+/// consecutive scopes after it that each hold one valid call, up to
+/// [maxToolCalls], and the rest is dropped.
ChatParseResult parseXmlToolCalls(
String input,
XmlToolCallFormat format, {
@@ -348,6 +354,8 @@ ChatParseResult parseXmlToolCalls(
bool unescapeReasoning = true,
bool extractsThought = true,
bool verbatimForcedThought = false,
+ bool endsAtLastCall = false,
+ int? maxToolCalls,
Map>? schemas,
}) {
String? reasoning;
@@ -414,6 +422,16 @@ ChatParseResult parseXmlToolCalls(
reasoningContent: reasoning,
);
}
+ if (endsAtLastCall) {
+ return _parseCallsEndingReply(
+ content,
+ format,
+ reasoning: reasoning,
+ schemas: schemas,
+ maxToolCalls: maxToolCalls,
+ isPartial: isPartial,
+ );
+ }
final toolCalls = [];
final parsedContent = StringBuffer();
@@ -542,6 +560,61 @@ ChatParseResult parseXmlToolCalls(
);
}
+/// Parses the scopes that end [content] for [parseXmlToolCalls] with
+/// `endsAtLastCall`.
+///
+/// A finished reply may end a valid call without its scope end, or with only
+/// the start of one, and the call counts, as llama.cpp takes it at the end of
+/// the input.
+ChatParseResult _parseCallsEndingReply(
+ String content,
+ XmlToolCallFormat format, {
+ required String? reasoning,
+ required Map>? schemas,
+ required int? maxToolCalls,
+ required bool isPartial,
+}) {
+ final scopeIdx = content.indexOf(format.scopeStart);
+ if (scopeIdx == -1) {
+ return ChatParseResult(
+ content: content.trim(),
+ reasoningContent: reasoning,
+ );
+ }
+ final toolCalls = [];
+ var pos = scopeIdx;
+ while ((maxToolCalls == null || toolCalls.length < maxToolCalls) &&
+ content.startsWith(format.scopeStart, pos)) {
+ final toolIdx = _consumeXmlWhitespace(
+ content,
+ pos + format.scopeStart.length,
+ );
+ if (!content.startsWith(format.toolStart, toolIdx)) break;
+ final call = _parseXmlToolCall(content, toolIdx, format, schemas);
+ if (call == null) break;
+ final closed = content.startsWith(format.scopeEnd, call.nextPos);
+ if (!closed &&
+ (isPartial ||
+ !format.scopeEnd.startsWith(content.substring(call.nextPos)))) {
+ break;
+ }
+ toolCalls.add(
+ ToolCallParsingUtils.createFunctionToolCall(
+ index: toolCalls.length,
+ name: call.name,
+ arguments: call.arguments,
+ ),
+ );
+ if (!closed) break;
+ pos = _consumeXmlWhitespace(content, call.nextPos + format.scopeEnd.length);
+ }
+ return ChatParseResult(
+ content: content.substring(0, scopeIdx).trim(),
+ reasoningContent: reasoning,
+ toolCalls: toolCalls,
+ );
+}
+
/// Returns where the tool call of a scope that follows the scope end at
/// [scopeEnd] in [text] starts, when only whitespace separates them.
int? _nextScopeToolStart(String text, int scopeEnd, XmlToolCallFormat format) {
diff --git a/skills/llamadart-chat-streaming/SKILL.md b/skills/llamadart-chat-streaming/SKILL.md
index afc72b4f2..706899eb2 100644
--- a/skills/llamadart-chat-streaming/SKILL.md
+++ b/skills/llamadart-chat-streaming/SKILL.md
@@ -139,9 +139,9 @@ modalities and speculative strategies before offering them.
`chunk.text`, as in llama-server. Templates that open the thought even with
thinking off (StepFun3.5-Flash, DeepSeek R1 distills, MiniMax M2, Nemotron
Nano v2) stream no `chunk.text` until `` or `` arrives or the
- reply ends, so a thought the model still writes never reaches it; Cohere2
- MoE waits likewise for a thinking tag, `<|START_TEXT|>` or
- `<|START_ACTION|>`. When the prompt opens no thought, most formats stream
+ reply ends, so a thought the model still writes never reaches it; StepFun
+ also stops waiting at ``, and Cohere2 MoE waits likewise for a
+ thinking tag, `<|START_TEXT|>` or `<|START_ACTION|>`. When the prompt opens no thought, most formats stream
only a thought that starts the reply as `chunk.thinking`; a ``
before any `` and thinking tags later in the reply stay in
`chunk.text`, as in llama-server. A boolean `enable_thinking` or `thinking` in
diff --git a/skills/llamadart-tool-calling/SKILL.md b/skills/llamadart-tool-calling/SKILL.md
index 5a8b07110..f84951516 100644
--- a/skills/llamadart-tool-calling/SKILL.md
+++ b/skills/llamadart-tool-calling/SKILL.md
@@ -171,6 +171,10 @@ description: >-
grammar. Template capability reports describe history rendering and do not
silently override that explicit request; the flag cannot add a protocol the
format or backend does not implement.
+- Qwen3-Coder XML replies (Qwen3-Coder, Qwen3.5, StepFun3.5-Flash) parse as in
+ llama-server: content ends at the first ``, only the first call
+ counts without `parallelToolCalls`, and an invalid call or text after the
+ calls is dropped, not returned as content.
- Consume all parsed Solar Open content-channel segments, preserving the
whitespace between them. Parsed and streamed completions remove channel
framing while retaining the accepted content.
diff --git a/test/fixtures/qwen3_coder_parallel_upstream.md b/test/fixtures/qwen3_coder_parallel_upstream.md
index 6dfe882f6..d0658b4df 100644
--- a/test/fixtures/qwen3_coder_parallel_upstream.md
+++ b/test/fixtures/qwen3_coder_parallel_upstream.md
@@ -19,7 +19,7 @@ the whole output; `upstream` holds its content, reasoning and tool calls.
Feeding the output one byte at a time gave the same result for every case.
Every case returned one `get_weather` call per city, in order.
-Cases where llamadart already differs from that probe for a single call are
-left out: text after the last call, which llama.cpp drops and llamadart keeps
-as content, a thought in the Qwen3-Coder template, which has no thinking, and
-a StepFun3.5-Flash thought with thinking off.
+Cases where llamadart differed from that probe for a single call were left
+out: text after the last call, a thought in the Qwen3-Coder template, which has
+no thinking, and a StepFun3.5-Flash thought with thinking off.
+`qwen3_coder_xml_upstream.json` now records them (#1531).
diff --git a/test/fixtures/qwen3_coder_xml_upstream.json b/test/fixtures/qwen3_coder_xml_upstream.json
new file mode 100644
index 000000000..5200f363c
--- /dev/null
+++ b/test/fixtures/qwen3_coder_xml_upstream.json
@@ -0,0 +1,3620 @@
+{
+ "upstream_commit": "cd959bae99ff4bed22bef2604f45241c09bbb8c8",
+ "user_prompt": "Weather in Paris?",
+ "tool": {
+ "name": "get_weather",
+ "parameter": "location"
+ },
+ "templates": [
+ {
+ "template": "test/fixtures/llama_cpp_templates/Qwen3-Coder.jinja",
+ "enable_thinking": true,
+ "parallel_tool_calls": false,
+ "cases": [
+ {
+ "name": "call",
+ "output": "\n\n\nParis\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"Paris\"}"
+ }
+ ]
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"Paris\"}"
+ }
+ ]
+ }
+ },
+ {
+ "name": "text-then-call",
+ "output": "Let me check.\n\n\n\nParis\n\n\n",
+ "upstream": {
+ "content": "Let me check.",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"Paris\"}"
+ }
+ ]
+ },
+ "upstream_partial": {
+ "content": "Let me check.",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"Paris\"}"
+ }
+ ]
+ }
+ },
+ {
+ "name": "text-after-call",
+ "output": "\n\n\nParis\n\n\n Done.",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"Paris\"}"
+ }
+ ]
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"Paris\"}"
+ }
+ ]
+ }
+ },
+ {
+ "name": "two-calls",
+ "output": "\n\n\nParis\n\n\n\n\n\n\nRome\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"Paris\"}"
+ }
+ ]
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"Paris\"}"
+ }
+ ]
+ }
+ },
+ {
+ "name": "two-calls-then-text",
+ "output": "\n\n\nParis\n\n\n\n\n\n\nRome\n\n\n\nDone.",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"Paris\"}"
+ }
+ ]
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"Paris\"}"
+ }
+ ]
+ }
+ },
+ {
+ "name": "two-functions-in-one-scope",
+ "output": "\n\n\nParis\n\n\n\n\nRome\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ }
+ },
+ {
+ "name": "two-functions-in-one-scope-then-call",
+ "output": "\n\n\nParis\n\n\n\n\nRome\n\n\n\n\n\n\nTokyo\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ }
+ },
+ {
+ "name": "empty-first-scope",
+ "output": "\n\n\n\n\nParis\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ }
+ },
+ {
+ "name": "unknown-tool-between-calls",
+ "output": "\n\n\nParis\n\n\n\n\n\n\nRome\n\n\n\n\n\n\nTokyo\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"Paris\"}"
+ }
+ ]
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"Paris\"}"
+ }
+ ]
+ }
+ },
+ {
+ "name": "later-scope-without-end",
+ "output": "\n\n\nParis\n\n\n\n\n\n\nRome\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"Paris\"}"
+ }
+ ]
+ }
+ },
+ {
+ "name": "later-scope-with-partial-end",
+ "output": "\n\n\nParis\n\n\n\n\n\n\nRome\n\n\n\n\n\nParis\n\n\n\n\n is a tag.",
+ "upstream": {
+ "content": "Plan ",
+ "reasoning_content": "",
+ "tool_calls": []
+ },
+ "upstream_partial": {
+ "content": "Plan ",
+ "reasoning_content": "",
+ "tool_calls": []
+ }
+ },
+ {
+ "name": "end-tag-then-json-call",
+ "output": "Plan.\n{\"name\": \"get_weather\", \"arguments\": {\"location\": \"Paris\"}}\n",
+ "upstream": {
+ "content": "Plan.",
+ "reasoning_content": "",
+ "tool_calls": []
+ },
+ "upstream_partial": {
+ "content": "Plan.",
+ "reasoning_content": "",
+ "tool_calls": []
+ }
+ },
+ {
+ "name": "end-tag-then-call",
+ "output": "Plan.\n\n\n\nParis\n\n\n",
+ "upstream": {
+ "content": "Plan.",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"Paris\"}"
+ }
+ ]
+ },
+ "upstream_partial": {
+ "content": "Plan.",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"Paris\"}"
+ }
+ ]
+ }
+ },
+ {
+ "name": "thought-then-text-and-call",
+ "output": "Plan.Let me check.\n\n\n\nParis\n\n\n",
+ "upstream": {
+ "content": "Plan.Let me check.",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"Paris\"}"
+ }
+ ]
+ },
+ "upstream_partial": {
+ "content": "Plan.Let me check.",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"Paris\"}"
+ }
+ ]
+ }
+ },
+ {
+ "name": "thought-then-answer",
+ "output": "Plan.Answer.",
+ "upstream": {
+ "content": "Plan.Answer.",
+ "reasoning_content": "",
+ "tool_calls": []
+ },
+ "upstream_partial": {
+ "content": "Plan.Answer.",
+ "reasoning_content": "",
+ "tool_calls": []
+ }
+ },
+ {
+ "name": "end-tag-then-text-and-end-tag",
+ "output": "Plan.AB",
+ "upstream": {
+ "content": "Plan.AB",
+ "reasoning_content": "",
+ "tool_calls": []
+ },
+ "upstream_partial": {
+ "content": "Plan.AB",
+ "reasoning_content": "",
+ "tool_calls": []
+ }
+ }
+ ]
+ },
+ {
+ "template": "test/fixtures/llama_cpp_templates/Qwen3-Coder.jinja",
+ "enable_thinking": true,
+ "parallel_tool_calls": true,
+ "cases": [
+ {
+ "name": "call",
+ "output": "\n\n\nParis\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"Paris\"}"
+ }
+ ]
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"Paris\"}"
+ }
+ ]
+ }
+ },
+ {
+ "name": "text-then-call",
+ "output": "Let me check.\n\n\n\nParis\n\n\n",
+ "upstream": {
+ "content": "Let me check.",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"Paris\"}"
+ }
+ ]
+ },
+ "upstream_partial": {
+ "content": "Let me check.",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"Paris\"}"
+ }
+ ]
+ }
+ },
+ {
+ "name": "text-after-call",
+ "output": "\n\n\nParis\n\n\n Done.",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"Paris\"}"
+ }
+ ]
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"Paris\"}"
+ }
+ ]
+ }
+ },
+ {
+ "name": "two-calls",
+ "output": "\n\n\nParis\n\n\n\n\n\n\nRome\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"Paris\"}"
+ },
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"Rome\"}"
+ }
+ ]
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"Paris\"}"
+ },
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"Rome\"}"
+ }
+ ]
+ }
+ },
+ {
+ "name": "two-calls-then-text",
+ "output": "\n\n\nParis\n\n\n\n\n\n\nRome\n\n\n\nDone.",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"Paris\"}"
+ },
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"Rome\"}"
+ }
+ ]
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"Paris\"}"
+ },
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"Rome\"}"
+ }
+ ]
+ }
+ },
+ {
+ "name": "two-functions-in-one-scope",
+ "output": "\n\n\nParis\n\n\n\n\nRome\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ }
+ },
+ {
+ "name": "two-functions-in-one-scope-then-call",
+ "output": "\n\n\nParis\n\n\n\n\nRome\n\n\n\n\n\n\nTokyo\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ }
+ },
+ {
+ "name": "empty-first-scope",
+ "output": "\n\n\n\n\nParis\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ }
+ },
+ {
+ "name": "unknown-tool-between-calls",
+ "output": "\n\n\nParis\n\n\n\n\n\n\nRome\n\n\n\n\n\n\nTokyo\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"Paris\"}"
+ }
+ ]
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"Paris\"}"
+ }
+ ]
+ }
+ },
+ {
+ "name": "later-scope-without-end",
+ "output": "\n\n\nParis\n\n\n\n\n\n\nRome\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"Paris\"}"
+ },
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"Rome\"}"
+ }
+ ]
+ }
+ },
+ {
+ "name": "later-scope-with-partial-end",
+ "output": "\n\n\nParis\n\n\n\n\n\n\nRome\n\n\n\n\n\nParis\n\n\n\n\n is a tag.",
+ "upstream": {
+ "content": "Plan ",
+ "reasoning_content": "",
+ "tool_calls": []
+ },
+ "upstream_partial": {
+ "content": "Plan ",
+ "reasoning_content": "",
+ "tool_calls": []
+ }
+ },
+ {
+ "name": "end-tag-then-json-call",
+ "output": "Plan.\n{\"name\": \"get_weather\", \"arguments\": {\"location\": \"Paris\"}}\n",
+ "upstream": {
+ "content": "Plan.",
+ "reasoning_content": "",
+ "tool_calls": []
+ },
+ "upstream_partial": {
+ "content": "Plan.",
+ "reasoning_content": "",
+ "tool_calls": []
+ }
+ },
+ {
+ "name": "end-tag-then-call",
+ "output": "Plan.\n\n\n\nParis\n\n\n",
+ "upstream": {
+ "content": "Plan.",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"Paris\"}"
+ }
+ ]
+ },
+ "upstream_partial": {
+ "content": "Plan.",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"Paris\"}"
+ }
+ ]
+ }
+ },
+ {
+ "name": "thought-then-text-and-call",
+ "output": "Plan.Let me check.\n\n\n\nParis\n\n\n",
+ "upstream": {
+ "content": "Plan.Let me check.",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"Paris\"}"
+ }
+ ]
+ },
+ "upstream_partial": {
+ "content": "Plan.Let me check.",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"Paris\"}"
+ }
+ ]
+ }
+ },
+ {
+ "name": "thought-then-answer",
+ "output": "Plan.Answer.",
+ "upstream": {
+ "content": "Plan.Answer.",
+ "reasoning_content": "",
+ "tool_calls": []
+ },
+ "upstream_partial": {
+ "content": "Plan.Answer.",
+ "reasoning_content": "",
+ "tool_calls": []
+ }
+ },
+ {
+ "name": "end-tag-then-text-and-end-tag",
+ "output": "Plan.AB",
+ "upstream": {
+ "content": "Plan.AB",
+ "reasoning_content": "",
+ "tool_calls": []
+ },
+ "upstream_partial": {
+ "content": "Plan.AB",
+ "reasoning_content": "",
+ "tool_calls": []
+ }
+ }
+ ]
+ },
+ {
+ "template": "test/fixtures/templates/Qwen3_5-0_8B.jinja",
+ "enable_thinking": true,
+ "parallel_tool_calls": false,
+ "cases": [
+ {
+ "name": "call",
+ "output": "\n\n\nParis\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"Paris\"}"
+ }
+ ]
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"Paris\"}"
+ }
+ ]
+ }
+ },
+ {
+ "name": "text-then-call",
+ "output": "Let me check.\n\n\n\nParis\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "Let me check.\n",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"Paris\"}"
+ }
+ ]
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "Let me check.\n",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"Paris\"}"
+ }
+ ]
+ }
+ },
+ {
+ "name": "text-after-call",
+ "output": "\n\n\nParis\n\n\n Done.",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"Paris\"}"
+ }
+ ]
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"Paris\"}"
+ }
+ ]
+ }
+ },
+ {
+ "name": "two-calls",
+ "output": "\n\n\nParis\n\n\n\n\n\n\nRome\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"Paris\"}"
+ }
+ ]
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"Paris\"}"
+ }
+ ]
+ }
+ },
+ {
+ "name": "two-calls-then-text",
+ "output": "\n\n\nParis\n\n\n\n\n\n\nRome\n\n\n\nDone.",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"Paris\"}"
+ }
+ ]
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"Paris\"}"
+ }
+ ]
+ }
+ },
+ {
+ "name": "two-functions-in-one-scope",
+ "output": "\n\n\nParis\n\n\n\n\nRome\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ }
+ },
+ {
+ "name": "two-functions-in-one-scope-then-call",
+ "output": "\n\n\nParis\n\n\n\n\nRome\n\n\n\n\n\n\nTokyo\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ }
+ },
+ {
+ "name": "empty-first-scope",
+ "output": "\n\n\n\n\nParis\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ }
+ },
+ {
+ "name": "unknown-tool-between-calls",
+ "output": "\n\n\nParis\n\n\n\n\n\n\nRome\n\n\n\n\n\n\nTokyo\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"Paris\"}"
+ }
+ ]
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"Paris\"}"
+ }
+ ]
+ }
+ },
+ {
+ "name": "later-scope-without-end",
+ "output": "\n\n\nParis\n\n\n\n\n\n\nRome\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"Paris\"}"
+ }
+ ]
+ }
+ },
+ {
+ "name": "later-scope-with-partial-end",
+ "output": "\n\n\nParis\n\n\n\n\n\n\nRome\n\n\n\n\n\nParis\n\n\n\n\n is a tag.",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "Plan ",
+ "tool_calls": []
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "Plan ",
+ "tool_calls": []
+ }
+ },
+ {
+ "name": "end-tag-then-json-call",
+ "output": "Plan.\n{\"name\": \"get_weather\", \"arguments\": {\"location\": \"Paris\"}}\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "Plan.",
+ "tool_calls": []
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "Plan.",
+ "tool_calls": []
+ }
+ },
+ {
+ "name": "end-tag-then-call",
+ "output": "Plan.\n\n\n\nParis\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "Plan.",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"Paris\"}"
+ }
+ ]
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "Plan.",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"Paris\"}"
+ }
+ ]
+ }
+ },
+ {
+ "name": "thought-then-text-and-call",
+ "output": "Plan.Let me check.\n\n\n\nParis\n\n\n",
+ "upstream": {
+ "content": "Let me check.",
+ "reasoning_content": "Plan.",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"Paris\"}"
+ }
+ ]
+ },
+ "upstream_partial": {
+ "content": "Let me check.",
+ "reasoning_content": "Plan.",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"Paris\"}"
+ }
+ ]
+ }
+ },
+ {
+ "name": "thought-then-answer",
+ "output": "Plan.Answer.",
+ "upstream": {
+ "content": "Answer.",
+ "reasoning_content": "Plan.",
+ "tool_calls": []
+ },
+ "upstream_partial": {
+ "content": "Answer.",
+ "reasoning_content": "Plan.",
+ "tool_calls": []
+ }
+ },
+ {
+ "name": "end-tag-then-text-and-end-tag",
+ "output": "Plan.AB",
+ "upstream": {
+ "content": "AB",
+ "reasoning_content": "Plan.",
+ "tool_calls": []
+ },
+ "upstream_partial": {
+ "content": "AB",
+ "reasoning_content": "Plan.",
+ "tool_calls": []
+ }
+ }
+ ]
+ },
+ {
+ "template": "test/fixtures/templates/Qwen3_5-0_8B.jinja",
+ "enable_thinking": true,
+ "parallel_tool_calls": true,
+ "cases": [
+ {
+ "name": "call",
+ "output": "\n\n\nParis\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"Paris\"}"
+ }
+ ]
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"Paris\"}"
+ }
+ ]
+ }
+ },
+ {
+ "name": "text-then-call",
+ "output": "Let me check.\n\n\n\nParis\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "Let me check.\n",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"Paris\"}"
+ }
+ ]
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "Let me check.\n",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"Paris\"}"
+ }
+ ]
+ }
+ },
+ {
+ "name": "text-after-call",
+ "output": "\n\n\nParis\n\n\n Done.",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"Paris\"}"
+ }
+ ]
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"Paris\"}"
+ }
+ ]
+ }
+ },
+ {
+ "name": "two-calls",
+ "output": "\n\n\nParis\n\n\n\n\n\n\nRome\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"Paris\"}"
+ },
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"Rome\"}"
+ }
+ ]
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"Paris\"}"
+ },
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"Rome\"}"
+ }
+ ]
+ }
+ },
+ {
+ "name": "two-calls-then-text",
+ "output": "\n\n\nParis\n\n\n\n\n\n\nRome\n\n\n\nDone.",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"Paris\"}"
+ },
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"Rome\"}"
+ }
+ ]
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"Paris\"}"
+ },
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"Rome\"}"
+ }
+ ]
+ }
+ },
+ {
+ "name": "two-functions-in-one-scope",
+ "output": "\n\n\nParis\n\n\n\n\nRome\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ }
+ },
+ {
+ "name": "two-functions-in-one-scope-then-call",
+ "output": "\n\n\nParis\n\n\n\n\nRome\n\n\n\n\n\n\nTokyo\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ }
+ },
+ {
+ "name": "empty-first-scope",
+ "output": "\n\n\n\n\nParis\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ }
+ },
+ {
+ "name": "unknown-tool-between-calls",
+ "output": "\n\n\nParis\n\n\n\n\n\n\nRome\n\n\n\n\n\n\nTokyo\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"Paris\"}"
+ }
+ ]
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"Paris\"}"
+ }
+ ]
+ }
+ },
+ {
+ "name": "later-scope-without-end",
+ "output": "\n\n\nParis\n\n\n\n\n\n\nRome\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"Paris\"}"
+ },
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"Rome\"}"
+ }
+ ]
+ }
+ },
+ {
+ "name": "later-scope-with-partial-end",
+ "output": "\n\n\nParis\n\n\n\n\n\n\nRome\n\n\n\n\n\nParis\n\n\n\n\n is a tag.",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "Plan ",
+ "tool_calls": []
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "Plan ",
+ "tool_calls": []
+ }
+ },
+ {
+ "name": "end-tag-then-json-call",
+ "output": "Plan.\n{\"name\": \"get_weather\", \"arguments\": {\"location\": \"Paris\"}}\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "Plan.",
+ "tool_calls": []
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "Plan.",
+ "tool_calls": []
+ }
+ },
+ {
+ "name": "end-tag-then-call",
+ "output": "Plan.\n\n\n\nParis\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "Plan.",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"Paris\"}"
+ }
+ ]
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "Plan.",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"Paris\"}"
+ }
+ ]
+ }
+ },
+ {
+ "name": "thought-then-text-and-call",
+ "output": "Plan.Let me check.\n\n\n\nParis\n\n\n",
+ "upstream": {
+ "content": "Let me check.",
+ "reasoning_content": "Plan.",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"Paris\"}"
+ }
+ ]
+ },
+ "upstream_partial": {
+ "content": "Let me check.",
+ "reasoning_content": "Plan.",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"Paris\"}"
+ }
+ ]
+ }
+ },
+ {
+ "name": "thought-then-answer",
+ "output": "Plan.Answer.",
+ "upstream": {
+ "content": "Answer.",
+ "reasoning_content": "Plan.",
+ "tool_calls": []
+ },
+ "upstream_partial": {
+ "content": "Answer.",
+ "reasoning_content": "Plan.",
+ "tool_calls": []
+ }
+ },
+ {
+ "name": "end-tag-then-text-and-end-tag",
+ "output": "Plan.AB",
+ "upstream": {
+ "content": "AB",
+ "reasoning_content": "Plan.",
+ "tool_calls": []
+ },
+ "upstream_partial": {
+ "content": "AB",
+ "reasoning_content": "Plan.",
+ "tool_calls": []
+ }
+ }
+ ]
+ },
+ {
+ "template": "test/fixtures/templates/Qwen3_5-0_8B.jinja",
+ "enable_thinking": false,
+ "parallel_tool_calls": false,
+ "cases": [
+ {
+ "name": "call",
+ "output": "\n\n\nParis\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"Paris\"}"
+ }
+ ]
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"Paris\"}"
+ }
+ ]
+ }
+ },
+ {
+ "name": "text-then-call",
+ "output": "Let me check.\n\n\n\nParis\n\n\n",
+ "upstream": {
+ "content": "Let me check.",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"Paris\"}"
+ }
+ ]
+ },
+ "upstream_partial": {
+ "content": "Let me check.",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"Paris\"}"
+ }
+ ]
+ }
+ },
+ {
+ "name": "text-after-call",
+ "output": "\n\n\nParis\n\n\n Done.",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"Paris\"}"
+ }
+ ]
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"Paris\"}"
+ }
+ ]
+ }
+ },
+ {
+ "name": "two-calls",
+ "output": "\n\n\nParis\n\n\n\n\n\n\nRome\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"Paris\"}"
+ }
+ ]
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"Paris\"}"
+ }
+ ]
+ }
+ },
+ {
+ "name": "two-calls-then-text",
+ "output": "\n\n\nParis\n\n\n\n\n\n\nRome\n\n\n\nDone.",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"Paris\"}"
+ }
+ ]
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"Paris\"}"
+ }
+ ]
+ }
+ },
+ {
+ "name": "two-functions-in-one-scope",
+ "output": "\n\n\nParis\n\n\n\n\nRome\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ }
+ },
+ {
+ "name": "two-functions-in-one-scope-then-call",
+ "output": "\n\n\nParis\n\n\n\n\nRome\n\n\n\n\n\n\nTokyo\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ }
+ },
+ {
+ "name": "empty-first-scope",
+ "output": "\n\n\n\n\nParis\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ }
+ },
+ {
+ "name": "unknown-tool-between-calls",
+ "output": "\n\n\nParis\n\n\n\n\n\n\nRome\n\n\n\n\n\n\nTokyo\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"Paris\"}"
+ }
+ ]
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"Paris\"}"
+ }
+ ]
+ }
+ },
+ {
+ "name": "later-scope-without-end",
+ "output": "\n\n\nParis\n\n\n\n\n\n\nRome\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"Paris\"}"
+ }
+ ]
+ }
+ },
+ {
+ "name": "later-scope-with-partial-end",
+ "output": "\n\n\nParis\n\n\n\n\n\n\nRome\n\n\n\n\n\nParis\n\n\n\n\n is a tag.",
+ "upstream": {
+ "content": "Plan ",
+ "reasoning_content": "",
+ "tool_calls": []
+ },
+ "upstream_partial": {
+ "content": "Plan ",
+ "reasoning_content": "",
+ "tool_calls": []
+ }
+ },
+ {
+ "name": "end-tag-then-json-call",
+ "output": "Plan.\n{\"name\": \"get_weather\", \"arguments\": {\"location\": \"Paris\"}}\n",
+ "upstream": {
+ "content": "Plan.",
+ "reasoning_content": "",
+ "tool_calls": []
+ },
+ "upstream_partial": {
+ "content": "Plan.",
+ "reasoning_content": "",
+ "tool_calls": []
+ }
+ },
+ {
+ "name": "end-tag-then-call",
+ "output": "Plan.\n\n\n\nParis\n\n\n",
+ "upstream": {
+ "content": "Plan.",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"Paris\"}"
+ }
+ ]
+ },
+ "upstream_partial": {
+ "content": "Plan.",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"Paris\"}"
+ }
+ ]
+ }
+ },
+ {
+ "name": "thought-then-text-and-call",
+ "output": "Plan.Let me check.\n\n\n\nParis\n\n\n",
+ "upstream": {
+ "content": "Plan.Let me check.",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"Paris\"}"
+ }
+ ]
+ },
+ "upstream_partial": {
+ "content": "Plan.Let me check.",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"Paris\"}"
+ }
+ ]
+ }
+ },
+ {
+ "name": "thought-then-answer",
+ "output": "Plan.Answer.",
+ "upstream": {
+ "content": "Plan.Answer.",
+ "reasoning_content": "",
+ "tool_calls": []
+ },
+ "upstream_partial": {
+ "content": "Plan.Answer.",
+ "reasoning_content": "",
+ "tool_calls": []
+ }
+ },
+ {
+ "name": "end-tag-then-text-and-end-tag",
+ "output": "Plan.AB",
+ "upstream": {
+ "content": "Plan.AB",
+ "reasoning_content": "",
+ "tool_calls": []
+ },
+ "upstream_partial": {
+ "content": "Plan.AB",
+ "reasoning_content": "",
+ "tool_calls": []
+ }
+ }
+ ]
+ },
+ {
+ "template": "test/fixtures/templates/Qwen3_5-0_8B.jinja",
+ "enable_thinking": false,
+ "parallel_tool_calls": true,
+ "cases": [
+ {
+ "name": "call",
+ "output": "\n\n\nParis\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"Paris\"}"
+ }
+ ]
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"Paris\"}"
+ }
+ ]
+ }
+ },
+ {
+ "name": "text-then-call",
+ "output": "Let me check.\n\n\n\nParis\n\n\n",
+ "upstream": {
+ "content": "Let me check.",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"Paris\"}"
+ }
+ ]
+ },
+ "upstream_partial": {
+ "content": "Let me check.",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"Paris\"}"
+ }
+ ]
+ }
+ },
+ {
+ "name": "text-after-call",
+ "output": "\n\n\nParis\n\n\n Done.",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"Paris\"}"
+ }
+ ]
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"Paris\"}"
+ }
+ ]
+ }
+ },
+ {
+ "name": "two-calls",
+ "output": "\n\n\nParis\n\n\n\n\n\n\nRome\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"Paris\"}"
+ },
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"Rome\"}"
+ }
+ ]
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"Paris\"}"
+ },
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"Rome\"}"
+ }
+ ]
+ }
+ },
+ {
+ "name": "two-calls-then-text",
+ "output": "\n\n\nParis\n\n\n\n\n\n\nRome\n\n\n\nDone.",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"Paris\"}"
+ },
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"Rome\"}"
+ }
+ ]
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"Paris\"}"
+ },
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"Rome\"}"
+ }
+ ]
+ }
+ },
+ {
+ "name": "two-functions-in-one-scope",
+ "output": "\n\n\nParis\n\n\n\n\nRome\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ }
+ },
+ {
+ "name": "two-functions-in-one-scope-then-call",
+ "output": "\n\n\nParis\n\n\n\n\nRome\n\n\n\n\n\n\nTokyo\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ }
+ },
+ {
+ "name": "empty-first-scope",
+ "output": "\n\n\n\n\nParis\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ }
+ },
+ {
+ "name": "unknown-tool-between-calls",
+ "output": "\n\n\nParis\n\n\n\n\n\n\nRome\n\n\n\n\n\n\nTokyo\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"Paris\"}"
+ }
+ ]
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"Paris\"}"
+ }
+ ]
+ }
+ },
+ {
+ "name": "later-scope-without-end",
+ "output": "\n\n\nParis\n\n\n\n\n\n\nRome\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"Paris\"}"
+ },
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"Rome\"}"
+ }
+ ]
+ }
+ },
+ {
+ "name": "later-scope-with-partial-end",
+ "output": "\n\n\nParis\n\n\n\n\n\n\nRome\n\n\n\n\n\nParis\n\n\n\n\n is a tag.",
+ "upstream": {
+ "content": "Plan ",
+ "reasoning_content": "",
+ "tool_calls": []
+ },
+ "upstream_partial": {
+ "content": "Plan ",
+ "reasoning_content": "",
+ "tool_calls": []
+ }
+ },
+ {
+ "name": "end-tag-then-json-call",
+ "output": "Plan.\n{\"name\": \"get_weather\", \"arguments\": {\"location\": \"Paris\"}}\n",
+ "upstream": {
+ "content": "Plan.",
+ "reasoning_content": "",
+ "tool_calls": []
+ },
+ "upstream_partial": {
+ "content": "Plan.",
+ "reasoning_content": "",
+ "tool_calls": []
+ }
+ },
+ {
+ "name": "end-tag-then-call",
+ "output": "Plan.\n\n\n\nParis\n\n\n",
+ "upstream": {
+ "content": "Plan.",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"Paris\"}"
+ }
+ ]
+ },
+ "upstream_partial": {
+ "content": "Plan.",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"Paris\"}"
+ }
+ ]
+ }
+ },
+ {
+ "name": "thought-then-text-and-call",
+ "output": "Plan.Let me check.\n\n\n\nParis\n\n\n",
+ "upstream": {
+ "content": "Plan.Let me check.",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"Paris\"}"
+ }
+ ]
+ },
+ "upstream_partial": {
+ "content": "Plan.Let me check.",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"Paris\"}"
+ }
+ ]
+ }
+ },
+ {
+ "name": "thought-then-answer",
+ "output": "Plan.Answer.",
+ "upstream": {
+ "content": "Plan.Answer.",
+ "reasoning_content": "",
+ "tool_calls": []
+ },
+ "upstream_partial": {
+ "content": "Plan.Answer.",
+ "reasoning_content": "",
+ "tool_calls": []
+ }
+ },
+ {
+ "name": "end-tag-then-text-and-end-tag",
+ "output": "Plan.AB",
+ "upstream": {
+ "content": "Plan.AB",
+ "reasoning_content": "",
+ "tool_calls": []
+ },
+ "upstream_partial": {
+ "content": "Plan.AB",
+ "reasoning_content": "",
+ "tool_calls": []
+ }
+ }
+ ]
+ },
+ {
+ "template": "test/fixtures/llama_cpp_templates/StepFun3.5-Flash.jinja",
+ "enable_thinking": true,
+ "parallel_tool_calls": false,
+ "cases": [
+ {
+ "name": "call",
+ "output": "\n\n\nParis\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"Paris\"}"
+ }
+ ]
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"Paris\"}"
+ }
+ ]
+ }
+ },
+ {
+ "name": "text-then-call",
+ "output": "Let me check.\n\n\n\nParis\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "Let me check.\n",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"Paris\"}"
+ }
+ ]
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "Let me check.\n",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"Paris\"}"
+ }
+ ]
+ }
+ },
+ {
+ "name": "text-after-call",
+ "output": "\n\n\nParis\n\n\n Done.",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"Paris\"}"
+ }
+ ]
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"Paris\"}"
+ }
+ ]
+ }
+ },
+ {
+ "name": "two-calls",
+ "output": "\n\n\nParis\n\n\n\n\n\n\nRome\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"Paris\"}"
+ }
+ ]
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"Paris\"}"
+ }
+ ]
+ }
+ },
+ {
+ "name": "two-calls-then-text",
+ "output": "\n\n\nParis\n\n\n\n\n\n\nRome\n\n\n\nDone.",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"Paris\"}"
+ }
+ ]
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"Paris\"}"
+ }
+ ]
+ }
+ },
+ {
+ "name": "two-functions-in-one-scope",
+ "output": "\n\n\nParis\n\n\n\n\nRome\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ }
+ },
+ {
+ "name": "two-functions-in-one-scope-then-call",
+ "output": "\n\n\nParis\n\n\n\n\nRome\n\n\n\n\n\n\nTokyo\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ }
+ },
+ {
+ "name": "empty-first-scope",
+ "output": "\n\n\n\n\nParis\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ }
+ },
+ {
+ "name": "unknown-tool-between-calls",
+ "output": "\n\n\nParis\n\n\n\n\n\n\nRome\n\n\n\n\n\n\nTokyo\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"Paris\"}"
+ }
+ ]
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"Paris\"}"
+ }
+ ]
+ }
+ },
+ {
+ "name": "later-scope-without-end",
+ "output": "\n\n\nParis\n\n\n\n\n\n\nRome\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"Paris\"}"
+ }
+ ]
+ }
+ },
+ {
+ "name": "later-scope-with-partial-end",
+ "output": "\n\n\nParis\n\n\n\n\n\n\nRome\n\n\n\n\n\nParis\n\n\n\n\n is a tag.",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "Plan ",
+ "tool_calls": []
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "Plan ",
+ "tool_calls": []
+ }
+ },
+ {
+ "name": "end-tag-then-json-call",
+ "output": "Plan.\n{\"name\": \"get_weather\", \"arguments\": {\"location\": \"Paris\"}}\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "Plan.",
+ "tool_calls": []
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "Plan.",
+ "tool_calls": []
+ }
+ },
+ {
+ "name": "end-tag-then-call",
+ "output": "Plan.\n\n\n\nParis\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "Plan.",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"Paris\"}"
+ }
+ ]
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "Plan.",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"Paris\"}"
+ }
+ ]
+ }
+ },
+ {
+ "name": "thought-then-text-and-call",
+ "output": "Plan.Let me check.\n\n\n\nParis\n\n\n",
+ "upstream": {
+ "content": "Let me check.",
+ "reasoning_content": "Plan.",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"Paris\"}"
+ }
+ ]
+ },
+ "upstream_partial": {
+ "content": "Let me check.",
+ "reasoning_content": "Plan.",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"Paris\"}"
+ }
+ ]
+ }
+ },
+ {
+ "name": "thought-then-answer",
+ "output": "Plan.Answer.",
+ "upstream": {
+ "content": "Answer.",
+ "reasoning_content": "Plan.",
+ "tool_calls": []
+ },
+ "upstream_partial": {
+ "content": "Answer.",
+ "reasoning_content": "Plan.",
+ "tool_calls": []
+ }
+ },
+ {
+ "name": "end-tag-then-text-and-end-tag",
+ "output": "Plan.AB",
+ "upstream": {
+ "content": "AB",
+ "reasoning_content": "Plan.",
+ "tool_calls": []
+ },
+ "upstream_partial": {
+ "content": "AB",
+ "reasoning_content": "Plan.",
+ "tool_calls": []
+ }
+ }
+ ]
+ },
+ {
+ "template": "test/fixtures/llama_cpp_templates/StepFun3.5-Flash.jinja",
+ "enable_thinking": true,
+ "parallel_tool_calls": true,
+ "cases": [
+ {
+ "name": "call",
+ "output": "\n\n\nParis\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"Paris\"}"
+ }
+ ]
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"Paris\"}"
+ }
+ ]
+ }
+ },
+ {
+ "name": "text-then-call",
+ "output": "Let me check.\n\n\n\nParis\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "Let me check.\n",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"Paris\"}"
+ }
+ ]
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "Let me check.\n",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"Paris\"}"
+ }
+ ]
+ }
+ },
+ {
+ "name": "text-after-call",
+ "output": "\n\n\nParis\n\n\n Done.",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"Paris\"}"
+ }
+ ]
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"Paris\"}"
+ }
+ ]
+ }
+ },
+ {
+ "name": "two-calls",
+ "output": "\n\n\nParis\n\n\n\n\n\n\nRome\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"Paris\"}"
+ },
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"Rome\"}"
+ }
+ ]
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"Paris\"}"
+ },
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"Rome\"}"
+ }
+ ]
+ }
+ },
+ {
+ "name": "two-calls-then-text",
+ "output": "\n\n\nParis\n\n\n\n\n\n\nRome\n\n\n\nDone.",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"Paris\"}"
+ },
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"Rome\"}"
+ }
+ ]
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"Paris\"}"
+ },
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"Rome\"}"
+ }
+ ]
+ }
+ },
+ {
+ "name": "two-functions-in-one-scope",
+ "output": "\n\n\nParis\n\n\n\n\nRome\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ }
+ },
+ {
+ "name": "two-functions-in-one-scope-then-call",
+ "output": "\n\n\nParis\n\n\n\n\nRome\n\n\n\n\n\n\nTokyo\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ }
+ },
+ {
+ "name": "empty-first-scope",
+ "output": "\n\n\n\n\nParis\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ }
+ },
+ {
+ "name": "unknown-tool-between-calls",
+ "output": "\n\n\nParis\n\n\n\n\n\n\nRome\n\n\n\n\n\n\nTokyo\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"Paris\"}"
+ }
+ ]
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"Paris\"}"
+ }
+ ]
+ }
+ },
+ {
+ "name": "later-scope-without-end",
+ "output": "\n\n\nParis\n\n\n\n\n\n\nRome\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"Paris\"}"
+ },
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"Rome\"}"
+ }
+ ]
+ }
+ },
+ {
+ "name": "later-scope-with-partial-end",
+ "output": "\n\n\nParis\n\n\n\n\n\n\nRome\n\n\n\n\n\nParis\n\n\n\n\n is a tag.",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "Plan ",
+ "tool_calls": []
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "Plan ",
+ "tool_calls": []
+ }
+ },
+ {
+ "name": "end-tag-then-json-call",
+ "output": "Plan.\n{\"name\": \"get_weather\", \"arguments\": {\"location\": \"Paris\"}}\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "Plan.",
+ "tool_calls": []
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "Plan.",
+ "tool_calls": []
+ }
+ },
+ {
+ "name": "end-tag-then-call",
+ "output": "Plan.\n\n\n\nParis\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "Plan.",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"Paris\"}"
+ }
+ ]
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "Plan.",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"Paris\"}"
+ }
+ ]
+ }
+ },
+ {
+ "name": "thought-then-text-and-call",
+ "output": "Plan.Let me check.\n\n\n\nParis\n\n\n",
+ "upstream": {
+ "content": "Let me check.",
+ "reasoning_content": "Plan.",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"Paris\"}"
+ }
+ ]
+ },
+ "upstream_partial": {
+ "content": "Let me check.",
+ "reasoning_content": "Plan.",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"Paris\"}"
+ }
+ ]
+ }
+ },
+ {
+ "name": "thought-then-answer",
+ "output": "Plan.Answer.",
+ "upstream": {
+ "content": "Answer.",
+ "reasoning_content": "Plan.",
+ "tool_calls": []
+ },
+ "upstream_partial": {
+ "content": "Answer.",
+ "reasoning_content": "Plan.",
+ "tool_calls": []
+ }
+ },
+ {
+ "name": "end-tag-then-text-and-end-tag",
+ "output": "Plan.AB",
+ "upstream": {
+ "content": "AB",
+ "reasoning_content": "Plan.",
+ "tool_calls": []
+ },
+ "upstream_partial": {
+ "content": "AB",
+ "reasoning_content": "Plan.",
+ "tool_calls": []
+ }
+ }
+ ]
+ },
+ {
+ "template": "test/fixtures/llama_cpp_templates/StepFun3.5-Flash.jinja",
+ "enable_thinking": false,
+ "parallel_tool_calls": false,
+ "cases": [
+ {
+ "name": "call",
+ "output": "\n\n\nParis\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"Paris\"}"
+ }
+ ]
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"Paris\"}"
+ }
+ ]
+ }
+ },
+ {
+ "name": "text-then-call",
+ "output": "Let me check.\n\n\n\nParis\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "Let me check.\n",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"Paris\"}"
+ }
+ ]
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "Let me check.\n",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"Paris\"}"
+ }
+ ]
+ }
+ },
+ {
+ "name": "text-after-call",
+ "output": "\n\n\nParis\n\n\n Done.",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"Paris\"}"
+ }
+ ]
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"Paris\"}"
+ }
+ ]
+ }
+ },
+ {
+ "name": "two-calls",
+ "output": "\n\n\nParis\n\n\n\n\n\n\nRome\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"Paris\"}"
+ }
+ ]
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"Paris\"}"
+ }
+ ]
+ }
+ },
+ {
+ "name": "two-calls-then-text",
+ "output": "\n\n\nParis\n\n\n\n\n\n\nRome\n\n\n\nDone.",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"Paris\"}"
+ }
+ ]
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"Paris\"}"
+ }
+ ]
+ }
+ },
+ {
+ "name": "two-functions-in-one-scope",
+ "output": "\n\n\nParis\n\n\n\n\nRome\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ }
+ },
+ {
+ "name": "two-functions-in-one-scope-then-call",
+ "output": "\n\n\nParis\n\n\n\n\nRome\n\n\n\n\n\n\nTokyo\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ }
+ },
+ {
+ "name": "empty-first-scope",
+ "output": "\n\n\n\n\nParis\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ }
+ },
+ {
+ "name": "unknown-tool-between-calls",
+ "output": "\n\n\nParis\n\n\n\n\n\n\nRome\n\n\n\n\n\n\nTokyo\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"Paris\"}"
+ }
+ ]
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"Paris\"}"
+ }
+ ]
+ }
+ },
+ {
+ "name": "later-scope-without-end",
+ "output": "\n\n\nParis\n\n\n\n\n\n\nRome\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"Paris\"}"
+ }
+ ]
+ }
+ },
+ {
+ "name": "later-scope-with-partial-end",
+ "output": "\n\n\nParis\n\n\n\n\n\n\nRome\n\n\n\n\n\nParis\n\n\n\n\n is a tag.",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "Plan ",
+ "tool_calls": []
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "Plan ",
+ "tool_calls": []
+ }
+ },
+ {
+ "name": "end-tag-then-json-call",
+ "output": "Plan.\n{\"name\": \"get_weather\", \"arguments\": {\"location\": \"Paris\"}}\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "Plan.",
+ "tool_calls": []
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "Plan.",
+ "tool_calls": []
+ }
+ },
+ {
+ "name": "end-tag-then-call",
+ "output": "Plan.\n\n\n\nParis\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "Plan.",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"Paris\"}"
+ }
+ ]
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "Plan.",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"Paris\"}"
+ }
+ ]
+ }
+ },
+ {
+ "name": "thought-then-text-and-call",
+ "output": "Plan.Let me check.\n\n\n\nParis\n\n\n",
+ "upstream": {
+ "content": "Let me check.",
+ "reasoning_content": "Plan.",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"Paris\"}"
+ }
+ ]
+ },
+ "upstream_partial": {
+ "content": "Let me check.",
+ "reasoning_content": "Plan.",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"Paris\"}"
+ }
+ ]
+ }
+ },
+ {
+ "name": "thought-then-answer",
+ "output": "Plan.Answer.",
+ "upstream": {
+ "content": "Answer.",
+ "reasoning_content": "Plan.",
+ "tool_calls": []
+ },
+ "upstream_partial": {
+ "content": "Answer.",
+ "reasoning_content": "Plan.",
+ "tool_calls": []
+ }
+ },
+ {
+ "name": "end-tag-then-text-and-end-tag",
+ "output": "Plan.AB",
+ "upstream": {
+ "content": "AB",
+ "reasoning_content": "Plan.",
+ "tool_calls": []
+ },
+ "upstream_partial": {
+ "content": "AB",
+ "reasoning_content": "Plan.",
+ "tool_calls": []
+ }
+ }
+ ]
+ },
+ {
+ "template": "test/fixtures/llama_cpp_templates/StepFun3.5-Flash.jinja",
+ "enable_thinking": false,
+ "parallel_tool_calls": true,
+ "cases": [
+ {
+ "name": "call",
+ "output": "\n\n\nParis\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"Paris\"}"
+ }
+ ]
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"Paris\"}"
+ }
+ ]
+ }
+ },
+ {
+ "name": "text-then-call",
+ "output": "Let me check.\n\n\n\nParis\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "Let me check.\n",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"Paris\"}"
+ }
+ ]
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "Let me check.\n",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"Paris\"}"
+ }
+ ]
+ }
+ },
+ {
+ "name": "text-after-call",
+ "output": "\n\n\nParis\n\n\n Done.",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"Paris\"}"
+ }
+ ]
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"Paris\"}"
+ }
+ ]
+ }
+ },
+ {
+ "name": "two-calls",
+ "output": "\n\n\nParis\n\n\n\n\n\n\nRome\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"Paris\"}"
+ },
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"Rome\"}"
+ }
+ ]
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"Paris\"}"
+ },
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"Rome\"}"
+ }
+ ]
+ }
+ },
+ {
+ "name": "two-calls-then-text",
+ "output": "\n\n\nParis\n\n\n\n\n\n\nRome\n\n\n\nDone.",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"Paris\"}"
+ },
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"Rome\"}"
+ }
+ ]
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"Paris\"}"
+ },
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"Rome\"}"
+ }
+ ]
+ }
+ },
+ {
+ "name": "two-functions-in-one-scope",
+ "output": "\n\n\nParis\n\n\n\n\nRome\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ }
+ },
+ {
+ "name": "two-functions-in-one-scope-then-call",
+ "output": "\n\n\nParis\n\n\n\n\nRome\n\n\n\n\n\n\nTokyo\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ }
+ },
+ {
+ "name": "empty-first-scope",
+ "output": "\n\n\n\n\nParis\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ }
+ },
+ {
+ "name": "unknown-tool-between-calls",
+ "output": "\n\n\nParis\n\n\n\n\n\n\nRome\n\n\n\n\n\n\nTokyo\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"Paris\"}"
+ }
+ ]
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"Paris\"}"
+ }
+ ]
+ }
+ },
+ {
+ "name": "later-scope-without-end",
+ "output": "\n\n\nParis\n\n\n\n\n\n\nRome\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"Paris\"}"
+ },
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"Rome\"}"
+ }
+ ]
+ }
+ },
+ {
+ "name": "later-scope-with-partial-end",
+ "output": "\n\n\nParis\n\n\n\n\n\n\nRome\n\n\n\n\n\nParis\n\n\n\n\n is a tag.",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "Plan ",
+ "tool_calls": []
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "Plan ",
+ "tool_calls": []
+ }
+ },
+ {
+ "name": "end-tag-then-json-call",
+ "output": "Plan.\n{\"name\": \"get_weather\", \"arguments\": {\"location\": \"Paris\"}}\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "Plan.",
+ "tool_calls": []
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "Plan.",
+ "tool_calls": []
+ }
+ },
+ {
+ "name": "end-tag-then-call",
+ "output": "Plan.\n\n\n\nParis\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "Plan.",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"Paris\"}"
+ }
+ ]
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "Plan.",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"Paris\"}"
+ }
+ ]
+ }
+ },
+ {
+ "name": "thought-then-text-and-call",
+ "output": "Plan.Let me check.\n\n\n\nParis\n\n\n",
+ "upstream": {
+ "content": "Let me check.",
+ "reasoning_content": "Plan.",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"Paris\"}"
+ }
+ ]
+ },
+ "upstream_partial": {
+ "content": "Let me check.",
+ "reasoning_content": "Plan.",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"Paris\"}"
+ }
+ ]
+ }
+ },
+ {
+ "name": "thought-then-answer",
+ "output": "Plan.Answer.",
+ "upstream": {
+ "content": "Answer.",
+ "reasoning_content": "Plan.",
+ "tool_calls": []
+ },
+ "upstream_partial": {
+ "content": "Answer.",
+ "reasoning_content": "Plan.",
+ "tool_calls": []
+ }
+ },
+ {
+ "name": "end-tag-then-text-and-end-tag",
+ "output": "Plan.AB",
+ "upstream": {
+ "content": "AB",
+ "reasoning_content": "Plan.",
+ "tool_calls": []
+ },
+ "upstream_partial": {
+ "content": "AB",
+ "reasoning_content": "Plan.",
+ "tool_calls": []
+ }
+ }
+ ]
+ }
+ ]
+}
diff --git a/test/fixtures/qwen3_coder_xml_upstream.md b/test/fixtures/qwen3_coder_xml_upstream.md
new file mode 100644
index 000000000..2cd4bb194
--- /dev/null
+++ b/test/fixtures/qwen3_coder_xml_upstream.md
@@ -0,0 +1,35 @@
+# Qwen3-Coder XML upstream parses
+
+`qwen3_coder_xml_upstream.json` records how llama.cpp parses Qwen3-Coder XML
+replies around their tool calls, for issue #1531. The templates are the
+vendored Qwen3-Coder (no thinking), Qwen3.5 0.8B (thinking on: the prompt opens
+the thought; off: it closes it) and StepFun3.5-Flash (the prompt opens the
+thought either way; llamadart closes it with thinking off) templates, each with
+`parallel_tool_calls` off and on.
+
+`upstream` comes from a probe built from unchanged llama.cpp
+`cd959bae99ff4bed22bef2604f45241c09bbb8c8`, the native `v0.9.0` pin. With no
+model loaded, it called `common_chat_templates_init` on the template, built a
+`common_chat_session` from one user message, the `get_weather` tool with a
+required string `location`, `tool_choice` auto, the entry's
+`parallel_tool_calls` and `enable_thinking`, and `COMMON_REASONING_FORMAT_AUTO`
+(format `peg-native`), and called `finish` on the whole output. Feeding the
+whole output first gave the same result. `upstream_partial` is
+`common_chat_peg_parse` with `is_partial` on the same output.
+
+Left out:
+
+- `upstream_partial` of a call whose scope end is missing: llama.cpp takes the
+ call while the reply is partial, and llamadart only once it finishes.
+- A reply cut off inside a call, which llama.cpp returns as a call with
+ unterminated JSON arguments, and llamadart drops.
+- Calls whose tags lack llama.cpp's exact line breaks, such as
+ `\n`, while llamadart takes the call.
+- A Qwen3-Coder `` call without ``, which llama.cpp
+ takes for that template only.
+
+Fed one byte at a time, llama.cpp's session keeps the first call of a scope
+that holds two (`two-functions-in-one-scope*`), because the final parse returns
+an empty message, which does not replace the partial one. The recorded value is
+that final parse.
diff --git a/test/integration/core/engine/qwen3_coder_xml_upstream_test.dart b/test/integration/core/engine/qwen3_coder_xml_upstream_test.dart
new file mode 100644
index 000000000..aaac1e9fe
--- /dev/null
+++ b/test/integration/core/engine/qwen3_coder_xml_upstream_test.dart
@@ -0,0 +1,165 @@
+@TestOn('vm')
+library;
+
+import 'dart:convert';
+import 'dart:io';
+
+import 'package:llamadart/src/core/engine/chat_completion_stream_parser.dart';
+import 'package:llamadart/src/core/models/chat/chat_message.dart';
+import 'package:llamadart/src/core/models/chat/chat_role.dart';
+import 'package:llamadart/src/core/models/chat/chat_template_result.dart';
+import 'package:llamadart/src/core/models/tools/tool_definition.dart';
+import 'package:llamadart/src/core/models/tools/tool_param.dart';
+import 'package:llamadart/src/core/template/chat_format.dart';
+import 'package:llamadart/src/core/template/chat_parse_result.dart';
+import 'package:llamadart/src/core/template/chat_template_engine.dart';
+import 'package:test/test.dart';
+
+final Map _fixture =
+ jsonDecode(
+ File(
+ 'test/fixtures/qwen3_coder_xml_upstream.json',
+ ).readAsStringSync(),
+ )
+ as Map;
+
+final ToolDefinition _tool = ToolDefinition(
+ name: 'get_weather',
+ description: 'w',
+ parameters: [ToolParam.string('location', required: true)],
+ handler: (_) async => 'Sunny',
+);
+
+typedef _Message = Map;
+
+List _calls(Iterable<({String? name, String? arguments})> calls) => [
+ for (final call in calls) '${call.name} ${jsonDecode(call.arguments!)}',
+];
+
+// llamadart trims some whitespace around content and reasoning that llama.cpp
+// keeps.
+_Message _upstream(Map message) => {
+ 'content': (message['content'] as String).trim(),
+ 'reasoning': (message['reasoning_content'] as String).trim(),
+ 'calls': _calls([
+ for (final call
+ in (message['tool_calls'] as List).cast',
'\n',
),
};
+ // As in llama.cpp, the reply ends before an invalid call.
for (final entry in invalid.entries) {
test('production parser atomically rejects ${entry.key}', () {
final parsed = ChatTemplateEngine.parse(
@@ -114,10 +114,23 @@ void main() {
tools: [qwenResultTool],
);
expect(parsed.toolCalls, isEmpty);
- expect(parsed.content, entry.value);
+ expect(parsed.content, isEmpty);
});
}
+ test('a call whose reply ends before its scope end counts', () {
+ final parsed = ChatTemplateEngine.parse(
+ renderQwenResultHistory().format,
+ qwenResultEnvelope.replaceFirst('', ''),
+ tools: [qwenResultTool],
+ );
+ expect(parsed.toolCalls, hasLength(1));
+ expect(
+ jsonDecode(parsed.toolCalls.single.function!.arguments!),
+ qwenResultPayload,
+ );
+ });
+
test('explicit empty tools cannot create an undeclared call', () {
final parsed = ChatTemplateEngine.parse(
renderQwenResultHistory().format,
@@ -125,7 +138,7 @@ void main() {
tools: [],
);
expect(parsed.toolCalls, isEmpty);
- expect(parsed.content, qwenResultEnvelope);
+ expect(parsed.content, isEmpty);
});
test('zero-argument and optional schemas remain valid', () {
@@ -201,10 +214,13 @@ void main() {
.map((c) => c.choices.single.delta.thinking ?? '')
.join();
expect(reasoning.trim(), thinking ? 'reason' : '');
- if (malformed || choice == ToolChoice.none) {
+ if (choice == ToolChoice.none) {
expect(calls, isEmpty);
expect(content.join().trim(), body);
- if (choice != ToolChoice.none) expect(content, [body]);
+ expect(chunks.last.choices.single.finishReason, 'stop');
+ } else if (malformed) {
+ expect(calls, isEmpty);
+ expect(content, isEmpty);
expect(chunks.last.choices.single.finishReason, 'stop');
} else {
expect(content, isEmpty);
diff --git a/test/unit/core/template/template_internal_metadata_test.dart b/test/unit/core/template/template_internal_metadata_test.dart
index 11a634991..241dca48f 100644
--- a/test/unit/core/template/template_internal_metadata_test.dart
+++ b/test/unit/core/template/template_internal_metadata_test.dart
@@ -50,6 +50,16 @@ void main() {
},
);
+ test('withSingleToolCall marks a result, and copies keep the mark', () {
+ LlamaChatTemplateResult result() => LlamaChatTemplateResult(prompt: 'p');
+ final single = withSingleToolCall(result(), single: true);
+ final unmarked = withSingleToolCall(result(), single: false);
+ expect(singleToolCallOf(single), isTrue);
+ expect(singleToolCallOf(unmarked), isFalse);
+ expect(singleToolCallOf(withThoughtMarksOf(result(), single)), isTrue);
+ expect(singleToolCallOf(withThoughtMarksOf(result(), unmarked)), isFalse);
+ });
+
group('chatTemplateKwargsFromMetadata', () {
test('decodes the stored kwargs object', () {
expect(
diff --git a/test/unit/core/template/xml_tool_call_format_test.dart b/test/unit/core/template/xml_tool_call_format_test.dart
index 5a262f56b..2fd7f12ae 100644
--- a/test/unit/core/template/xml_tool_call_format_test.dart
+++ b/test/unit/core/template/xml_tool_call_format_test.dart
@@ -3,6 +3,7 @@ import 'dart:convert';
import 'package:llamadart/src/core/models/chat/completion_chunk.dart';
import 'package:llamadart/src/core/models/tools/tool_definition.dart';
import 'package:llamadart/src/core/models/tools/tool_param.dart';
+import 'package:llamadart/src/core/template/chat_parse_result.dart';
import 'package:llamadart/src/core/template/xml_tool_call_format.dart';
import 'package:test/test.dart';
@@ -519,8 +520,9 @@ void main() {
}
// llama.cpp 620d2225 returns no call for either Qwen3-Coder output, and
- // empty content where this scan keeps the output as text. Seed-OSS differs
- // there: a scope without a line break is text to llama.cpp.
+ // empty content where this scan keeps the output as text (the Qwen3-Coder
+ // handler parses with endsAtLastCall, below). Seed-OSS differs there: a
+ // scope without a line break is text to llama.cpp.
test('an empty first Qwen3-Coder scope starts no later calls', () {
const call =
'\n\n\nParis\n'
@@ -536,4 +538,71 @@ void main() {
expect(parsed.content, output);
}
});
+
+ group('endsAtLastCall', () {
+ String call(String city) =>
+ '\n\n\n$city\n'
+ '\n\n';
+ List cities(ChatParseResult parsed) => [
+ for (final call in parsed.toolCalls)
+ (jsonDecode(call.function!.arguments!) as Map)['city'] as String,
+ ];
+ ChatParseResult parse(
+ String output, {
+ int? maxToolCalls,
+ bool isPartial = false,
+ }) => parseXmlToolCalls(
+ output,
+ XmlToolCallFormat.qwen3Coder,
+ endsAtLastCall: true,
+ maxToolCalls: maxToolCalls,
+ isPartial: isPartial,
+ );
+
+ test('keeps the text before the first scope and drops the rest', () {
+ final parsed = parse('Checking.\n${call('Paris')}\nDone.');
+
+ expect(parsed.content, 'Checking.');
+ expect(cities(parsed), ['Paris']);
+ });
+
+ test('takes consecutive scopes up to maxToolCalls', () {
+ final output = '${call('Paris')}\n${call('Rome')}';
+
+ expect(cities(parse(output)), ['Paris', 'Rome']);
+ expect(cities(parse(output, maxToolCalls: 1)), ['Paris']);
+ });
+
+ test('stops at a scope that is empty or holds two calls', () {
+ const twoCalls =
+ '\n\n\nRome\n'
+ '\n\n\n'
+ '\nOslo\n\n\n';
+ for (final (output, expected) in [
+ ('\n\n${call('Paris')}', []),
+ ('$twoCalls\n${call('Paris')}', []),
+ ('${call('Paris')}\n$twoCalls', ['Paris']),
+ ]) {
+ final parsed = parse('Hi $output');
+
+ expect(cities(parsed), expected, reason: output);
+ expect(parsed.content, 'Hi', reason: output);
+ }
+ });
+
+ test('takes a call that ends a finished reply without its scope end', () {
+ for (final cut in ['', 'tool_call>', '>']) {
+ final output = '${call('Paris')}\n${call('Rome')}';
+ final truncated = output.substring(0, output.length - cut.length);
+
+ expect(cities(parse(truncated)), ['Paris', 'Rome'], reason: cut);
+ expect(cities(parse(truncated, isPartial: true)), ['Paris']);
+ }
+ final cutInValue = '${call('Paris')}\n${call('Rome')}'.substring(
+ 0,
+ call('Paris').length + 40,
+ );
+ expect(cities(parse(cutInValue)), ['Paris']);
+ });
+ });
}
diff --git a/website/docs/changelog/recent-releases.md b/website/docs/changelog/recent-releases.md
index 99f2d058f..925828e61 100644
--- a/website/docs/changelog/recent-releases.md
+++ b/website/docs/changelog/recent-releases.md
@@ -14,6 +14,7 @@ validate against the exact release tag notes.
## Unreleased
- When the prompt opened no thought, take a thought only at the start of the reply, as llama.cpp does: any other thinking tag, such as a `` before any ``, a `` later in the reply or a second ``, is now content in generic, Llama 3, GLM 4.5, Kimi K2, LFM2, Laguna, Granite, MiniCPM5, Mistral Nemo, Apertus, Hunyuan V3 and DeepSeek R1, V3.2 and V4 replies, and after the start of a Hermes or Qwen3-Coder XML reply. The stream used to depend on how the reply was chunked and could repeat text as both content and reasoning ([#1865](https://github.com/leehack/llamadart/issues/1865)).
+- Parse Qwen3-Coder XML replies (Qwen3-Coder, Qwen3.5, StepFun3.5-Flash) as llama.cpp does: text from the first `` on that is not a valid call, such as an invalid call or text after the calls, is dropped instead of kept as content, and only the first call counts without `parallelToolCalls`. Qwen3-Coder replies have no reasoning, and StepFun3.5-Flash with thinking off ends its thought at `` or `` ([#1531](https://github.com/leehack/llamadart/issues/1531)).
## 0.19.2
diff --git a/website/docs/guides/chat-template-and-parsing.md b/website/docs/guides/chat-template-and-parsing.md
index f3ed66779..2a470bd61 100644
--- a/website/docs/guides/chat-template-and-parsing.md
+++ b/website/docs/guides/chat-template-and-parsing.md
@@ -121,13 +121,17 @@ for final answer content.
With thinking off, DeepSeek V3.1, Qwen3, QwQ and Qwen3.5 templates close the
thought in the prompt, and the reply is parsed as content, as in llama-server:
a `` block the model still writes stays in `chunk.text` and the
-message content.
+message content. The Qwen3-Coder template has no thinking, so its replies are
+parsed as content in the same way.
Templates such as StepFun3.5-Flash, DeepSeek R1 distills, MiniMax M2 and
Nemotron Nano v2 open the thought even with thinking off. llamadart closes it
in the prompt, but a thought the model still writes before `` is
reasoning, as in llama-server. So that it never streams as `chunk.text`, the
reply's text is held until `` or `` arrives, or the reply ends.
+For StepFun3.5-Flash, a `` also ends the wait, and the thought is
+the text before the first `` or `` as the model wrote it,
+`` included; the rest is content, thinking tags included.
Cohere2 MoE templates open it unless `reasoning` is false, which llamadart
sets from `enableThinking`; their reply is held until a thinking tag,
`<|START_TEXT|>` or `<|START_ACTION|>`, where llama-server ends the thought,
diff --git a/website/docs/guides/template-engine-internals.md b/website/docs/guides/template-engine-internals.md
index 3565286c0..d14ddf3a3 100644
--- a/website/docs/guides/template-engine-internals.md
+++ b/website/docs/guides/template-engine-internals.md
@@ -184,10 +184,14 @@ sequenceDiagram
Qwen XML tool calls are validated against the tools supplied to `engine.create`.
Schema-declared strings such as `"123"` retain their type. Unknown functions,
unknown or duplicate parameters, missing required values, and invalid value
-types remain response content instead of producing callable tool deltas.
-Tool calls are emitted after final validation; malformed output is preserved
-through the existing rollback behavior. Direct schema-free template parsing
-retains its legacy behavior, so pass tool definitions when validating calls.
+types never produce callable tool deltas. As in llama-server, the content ends
+at the first ``, the calls are those of the `` scopes
+after it that each hold one valid call, only the first without
+`parallelToolCalls`, and the rest of the reply is dropped: an invalid call, a
+scope with two calls and text after the calls. A finished reply may end a
+valid call without ``. Tool calls are emitted after final
+validation. Direct schema-free template parsing does not validate arguments,
+so pass tool definitions when validating calls.
Without a tool-call grammar, as with `ToolChoice.auto` on WebGPU, Qwen2.5 can
copy the double braces its GGUF template prints in the tool prompt: