diff --git a/CHANGELOG.md b/CHANGELOG.md
index 3033bf1b0..83af7947f 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -3,6 +3,8 @@ Releases before 0.10.0 are in the
## Unreleased
+- Parse Qwen3-Coder XML tool calls as llama.cpp does: a call needs a line break after each tag and around each value (a CRLF or compact `` not followed by a line break. Nemotron 3 Nano now parses as Qwen3-Coder XML, so a `` also ends its thought, and the tool-call grammar of these templates now requires that shape and starts at `` ([#1898](https://github.com/leehack/llamadart/issues/1898)).
+
## 0.19.4
- Keep the default WebGPU bridge assets at `v0.1.83` (unchanged from 0.19.3).
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 9cfc59f12..3f546669f 100644
--- a/lib/src/core/template/handlers/qwen3_coder_xml_handler.dart
+++ b/lib/src/core/template/handlers/qwen3_coder_xml_handler.dart
@@ -1,5 +1,7 @@
import 'package:dinja/dinja.dart';
+import '../../grammar/json_schema_converter.dart';
+
import '../../models/chat/chat_message.dart';
import '../../models/chat/chat_template_result.dart';
import '../../models/inference/tool_choice.dart';
@@ -7,10 +9,10 @@ import '../../models/tools/tool_definition.dart';
import '../chat_format.dart';
import '../chat_parse_result.dart';
import '../chat_template_handler.dart';
-import '../peg_parser_builder.dart';
+import '../tool_call_grammar_utils.dart';
+import 'specialized_handler_utils.dart';
import '../template_internal_metadata.dart';
import '../thinking_utils.dart';
-import '../tool_call_parsing_utils.dart';
import '../tool_schema_utils.dart';
import '../xml_tool_call_format.dart';
@@ -30,13 +32,6 @@ class Qwen3CoderXmlHandler extends ChatTemplateHandler
'',
];
- static const List _nemotronV3PreservedTokens = [
- '',
- '',
- '',
- '',
- ];
-
@override
ChatFormat get format => ChatFormat.qwen3CoderXml;
@@ -73,11 +68,9 @@ class Qwen3CoderXmlHandler extends ChatTemplateHandler
},
);
- final isNemotronV3 = _isNemotronV3Template(templateSource);
final toolChoice = metadata[internalToolChoiceMetadataKey];
final parallelToolCalls =
metadata[internalParallelToolCallsMetadataKey] == 'true';
- final toolChoiceNone = toolChoice == ToolChoice.none.name;
final toolChoiceRequired = toolChoice == ToolChoice.required.name;
// llama.cpp takes no thought from a reply to a template without one, and
// its first call may then leave out ``, as Qwen3-Coder does.
@@ -99,62 +92,26 @@ class Qwen3CoderXmlHandler extends ChatTemplateHandler
}
final hasTools = tools != null && tools.isNotEmpty;
- final nemotronAllowToolCalls = isNemotronV3 && hasTools && !toolChoiceNone;
- final bareFirstCall =
- hasTools && toolChoiceRequired && !isNemotronV3 && !templateHasThought;
- final parser = isNemotronV3
- ? _buildNemotronV3Parser(
- tools,
- enableThinking: enableThinking,
- thinkingForcedOpen: thinkingForcedOpen,
- allowToolCalls: nemotronAllowToolCalls,
- minToolCalls: toolChoiceRequired ? 1 : 0,
- maxToolCalls: parallelToolCalls ? -1 : 1,
- )
- : null;
- final resultFormat = isNemotronV3
- ? ChatFormat.pegConstructed.index
- : format.index;
- final grammar = buildXmlToolCallGrammar(
- tools,
- XmlToolCallFormat.qwen3Coder,
- parallelToolCalls: parallelToolCalls,
- textBeforeCalls: toolChoiceRequired && !isNemotronV3,
- bareFirstCall: bareFirstCall,
- );
-
+ final bareFirstCall = hasTools && toolChoiceRequired && !templateHasThought;
final rendered = LlamaChatTemplateResult(
prompt: prompt,
- format: resultFormat,
- grammar: isNemotronV3
- ? (nemotronAllowToolCalls
- ? requiredGrammarAfterThought(
- grammar,
- metadata: metadata,
- thinkingForcedOpen: thinkingForcedOpen,
- )
- : null)
- : grammar,
- grammarLazy: isNemotronV3
- ? (nemotronAllowToolCalls && !toolChoiceRequired)
- : hasTools,
+ format: format.index,
+ grammar: _callGrammar(
+ tools,
+ parallelToolCalls: parallelToolCalls,
+ textBeforeCalls: toolChoiceRequired,
+ bareFirstCall: bareFirstCall,
+ ),
+ grammarLazy: hasTools,
thinkingForcedOpen: thinkingForcedOpen,
additionalStops: getStops(
hasTools: hasTools,
enableThinking: enableThinking,
),
- preservedTokens: isNemotronV3
- ? _nemotronV3PreservedTokens
- : preservedTokens,
- grammarTriggers: (isNemotronV3 ? nemotronAllowToolCalls : hasTools)
- ? [
- GrammarTrigger(
- type: 0,
- value: isNemotronV3 ? '' : '\n')]
: const [],
- parser: parser,
);
return withBareFirstCall(
withSingleToolCall(
@@ -168,143 +125,225 @@ class Qwen3CoderXmlHandler extends ChatTemplateHandler
);
}
- bool _isNemotronV3Template(String templateSource) {
- return templateSource.contains('truncate_history_thinking') &&
- templateSource.contains('') &&
- templateSource.contains('') &&
- templateSource.contains('') &&
- templateSource.contains('');
- }
-
- String _buildNemotronV3Parser(
+ /// llama.cpp's Qwen3-Coder call grammar for [tools].
+ ///
+ /// Each call is in its own `` scope, only one without
+ /// [parallelToolCalls], and framed by line breaks as the parser reads it:
+ /// the required arguments first, in any order up to six of them, then the
+ /// optional ones, in any order and possibly repeated. A value that may be a
+ /// string is any text up to the first `\n\n`; any other is
+ /// JSON for its schema. With [textBeforeCalls], text without a call opening
+ /// precedes the calls, and with [bareFirstCall], the first call may leave
+ /// out `\n` and a declared tool's `` is a call
+ /// opening.
+ static String? _callGrammar(
List? tools, {
- required bool enableThinking,
- required bool thinkingForcedOpen,
- required bool allowToolCalls,
- required int minToolCalls,
- required int maxToolCalls,
+ required bool parallelToolCalls,
+ bool textBeforeCalls = false,
+ bool bareFirstCall = false,
}) {
- final p = ChatPegConstructedBuilder();
- final hasTools = tools != null && tools.isNotEmpty;
-
- PegParser reasoning = p.eps();
- if (enableThinking) {
- final reasoningContent =
- p.reasoning(p.until('')) + (p.literal('') | p.end());
- if (thinkingForcedOpen) {
- reasoning = reasoningContent;
- }
+ if (tools == null || tools.isEmpty) {
+ return null;
}
-
- if (!hasTools || !allowToolCalls) {
- p.setRoot(reasoning + p.content(p.rest()));
- return p.save();
+ const format = XmlToolCallFormat.qwen3Coder;
+ const valueEnd = '\n\n';
+ final literal = ToolCallGrammarUtils.literal;
+ final converter = JsonSchemaConverter();
+ final rules = [];
+ final valuesAtEnd = {};
+ String atValueEnd(String rule) {
+ valuesAtEnd.add(rule);
+ return '$rule$_atValueEnd';
}
- PegParser toolChoice = p.choice([]);
- for (final tool in tools) {
- final name = tool.name;
+ String? stringValue;
+ final toolRules = [];
+ for (var toolIndex = 0; toolIndex < tools.length; toolIndex++) {
+ final tool = tools[toolIndex];
final schema = tool.toJsonSchema();
- final requiredParameters = _requiredParameters(schema);
- final properties = _schemaProperties(schema);
-
- PegParser args = p.eps();
- for (final entry in properties.entries) {
- final paramName = entry.key;
- final paramSchema = entry.value;
- final isRequired = requiredParameters.contains(paramName);
- final ruleName = 'tool-$name-arg-$paramName';
-
- final argOpen = p.toolArgOpen(
- p.literal('\n'),
+ converter.resolveRefs(schema, schema);
+ final requiredNames = schemaRequired(schema);
+ final requiredRules = [];
+ final optionalRules = [];
+ var argumentIndex = 0;
+ for (final MapEntry(:key, :value) in schemaProperties(schema).entries) {
+ final argumentRule = 'tool-$toolIndex-arg-${argumentIndex++}';
+ final valueRule = _mayBeString(value)
+ ? stringValue ??= addThroughRules(rules, 'xml-arg-string', valueEnd)
+ : '${atValueEnd(converter.visit(value, '$argumentRule-schema'))} '
+ '${literal(valueEnd)}';
+ rules.add(
+ '$argumentRule ::= ${literal('\n')} $valueRule',
);
- final argClose = p.toolArgClose(p.literal('\n'));
-
- final argValue = _resolvesToString(paramSchema)
- ? p.toolArgStringValue(
- p.untilOneOf([
- '\n',
- '\n',
- ]),
- ) +
- p.literal('\n')
- : p.toolArgJsonValue(
- p.schema(p.json(), '$ruleName-schema', paramSchema),
- );
-
- final argRule = p.rule(
- ruleName,
- argOpen + argValue + p.optional(argClose),
+ (requiredNames.contains(key) ? requiredRules : optionalRules).add(
+ argumentRule,
);
- args += p.repeat(argRule, isRequired ? 1 : 0, 1);
}
-
- final toolRule = p.rule(
- 'tool-$name',
- p.toolOpen(
- p.literal('\n'),
- ) +
- args +
- p.toolClose(p.literal('\n')),
+ final arguments = [
+ if (requiredRules.isNotEmpty)
+ _permuted(rules, 'tool-$toolIndex-args', requiredRules),
+ if (optionalRules.isNotEmpty) '(${optionalRules.join(' | ')})*',
+ ];
+ final toolRule = 'tool-$toolIndex';
+ rules.add(
+ '$toolRule ::= ${literal('\n')} '
+ '${arguments.isEmpty ? '' : '${arguments.join(' ')} '}'
+ '${literal('\n')}',
);
- toolChoice |= toolRule;
+ toolRules.add(toolRule);
}
- final toolCall = p.rule(
- 'tool-call',
- p.literal('\n') +
- toolChoice +
- p.literal('') +
- p.space(),
- );
- final toolCalls = p.triggerRule(
- 'tool-call-root',
- p.repeat(toolCall, minToolCalls, maxToolCalls),
- );
+ final body =
+ '(${toolRules.join(' | ')}) ${literal(format.scopeEnd)} tool-call-space';
+ final scopeStart = literal('${format.scopeStart}\n');
+ final firstCall = bareFirstCall ? 'tool-call-first' : 'tool-call';
+ final buffer = StringBuffer()
+ ..writeln(
+ 'root ::= ${textBeforeCalls ? 'text-before-calls ' : ''}$firstCall'
+ '${parallelToolCalls ? ' tool-call*' : ''}',
+ )
+ ..writeln('tool-call ::= $scopeStart $body');
+ if (bareFirstCall) {
+ buffer.writeln('tool-call-first ::= $scopeStart? $body');
+ }
+ if (textBeforeCalls) {
+ ToolCallGrammarUtils.excludingRules('text-before-calls', [
+ format.scopeStart,
+ if (bareFirstCall)
+ for (final tool in tools) format.bareCallOpening(tool.name),
+ ]).forEach(buffer.writeln);
+ }
+ buffer.writeln(r'tool-call-space ::= | " " | "\n"{1,2} [ \t]{0,20}');
+ rules.forEach(buffer.writeln);
+ final jsonRules = converter.rules.entries.toList(growable: false)
+ ..sort((a, b) => a.key.compareTo(b.key));
+ for (final MapEntry(:key, :value) in jsonRules) {
+ buffer.writeln('$key ::= $value');
+ }
+ // llama.cpp's argument value ends where its JSON does, so
+ // `\n\n` follows it directly, as the parser requires. Values
+ // nested inside it keep the converter's whitespace.
+ final written = {};
+ void writeAtEnd(String rule) {
+ if (!written.add(rule)) return;
+ final body = _withoutTrailingSpace(converter.rules[rule]!, (last) {
+ if (!converter.rules.containsKey(last) || last == 'space') return null;
+ writeAtEnd(last);
+ return '$last$_atValueEnd';
+ });
+ buffer.writeln('$rule$_atValueEnd ::= $body');
+ }
- p.setRoot(reasoning + p.content(p.until('')) + toolCalls);
- return p.save();
+ valuesAtEnd.forEach(writeAtEnd);
+ return buffer.toString();
}
- Set _requiredParameters(Map schema) {
- final required = schema['required'];
- if (required is! List) {
- return const {};
+ static const _atValueEnd = '-at-value-end';
+
+ /// [body] with the `space` that ends each of its alternatives removed, and
+ /// an alternative's last rule reference replaced by what [atEnd] returns for
+ /// it, unless null.
+ static String _withoutTrailingSpace(
+ String body,
+ String? Function(String rule) atEnd,
+ ) {
+ final alternatives = [];
+ var depth = 0;
+ var start = 0;
+ for (var i = 0; i < body.length; i++) {
+ switch (body[i]) {
+ case '"':
+ i = _closing(body, i, '"');
+ case '[':
+ i = _closing(body, i, ']');
+ case '(':
+ depth++;
+ case ')':
+ depth--;
+ case '|' when depth == 0:
+ alternatives.add(body.substring(start, i));
+ start = i + 1;
+ }
+ }
+ alternatives.add(body.substring(start));
+ return alternatives
+ .map((alternative) {
+ final trimmed = alternative.trim();
+ if (trimmed.endsWith(' space')) {
+ return trimmed.substring(0, trimmed.length - ' space'.length);
+ }
+ final last = RegExp(r'[A-Za-z0-9-]+$').stringMatch(trimmed);
+ final replacement = last == null ? null : atEnd(last);
+ return replacement == null
+ ? trimmed
+ : '${trimmed.substring(0, trimmed.length - last!.length)}'
+ '$replacement';
+ })
+ .join(' | ');
+ }
+
+ /// The index of the unescaped [close] that ends the literal or class
+ /// opening at [open] in [body].
+ static int _closing(String body, int open, String close) {
+ var i = open + 1;
+ while (i < body.length && body[i] != close) {
+ i += body[i] == r'\' ? 2 : 1;
}
- return required.map((item) => item.toString()).toSet();
+ return i;
}
- Map> _schemaProperties(
- Map schema,
+ /// [arguments] in any order, as llama.cpp's `permute`, which keeps the
+ /// declaration order beyond six of them.
+ static String _permuted(
+ List rules,
+ String prefix,
+ List arguments,
) {
- final propertiesRaw = schema['properties'];
- if (propertiesRaw is! Map) {
- return const >{};
+ if (arguments.length == 1 || arguments.length > 6) {
+ return arguments.join(' ');
}
- final result = >{};
- for (final entry in propertiesRaw.entries) {
- final value = ToolCallParsingUtils.coerceMap(entry.value);
- if (value != null) {
- result[entry.key.toString()] = value;
- }
+ String remaining(int mask) {
+ final name = '$prefix-$mask';
+ if (rules.any((rule) => rule.startsWith('$name ::= '))) return name;
+ final alternatives = [
+ for (var index = 0; index < arguments.length; index++)
+ if (mask & (1 << index) != 0)
+ mask == 1 << index
+ ? arguments[index]
+ : '${arguments[index]} ${remaining(mask & ~(1 << index))}',
+ ];
+ rules.add('$name ::= ${alternatives.join(' | ')}');
+ return name;
}
- return result;
+
+ return remaining((1 << arguments.length) - 1);
}
- bool _resolvesToString(Map schema) {
+ /// Whether a value of [schema] may be a string, which llama.cpp's grammar
+ /// then takes as any text.
+ static bool _mayBeString(Map schema) {
final type = schema['type'];
- if (type is String) {
- return type == 'string';
+ if (type is String) return type == 'string';
+ if (type is List) return type.contains('string');
+ if (schema.containsKey('const')) return schema['const'] is String;
+ final values = schema['enum'];
+ if (values is List) return values.any((value) => value is String);
+ for (final key in const ['anyOf', 'oneOf']) {
+ final children = schema[key];
+ if (children is List) {
+ return children.any(
+ (child) =>
+ child is! Map || _mayBeString(child.cast()),
+ );
+ }
}
- if (type is List) {
- return type.length == 1 && type.first == 'string';
+ final children = schema['allOf'];
+ if (children is List) {
+ return children.every(
+ (child) => child is! Map || _mayBeString(child.cast()),
+ );
}
- return false;
+ return true;
}
@override
@@ -390,6 +429,6 @@ class Qwen3CoderXmlHandler extends ChatTemplateHandler
@override
String? buildGrammar(List? tools) {
- return buildXmlToolCallGrammar(tools, XmlToolCallFormat.qwen3Coder);
+ return _callGrammar(tools, parallelToolCalls: true);
}
}
diff --git a/lib/src/core/template/handlers/specialized_handler_utils.dart b/lib/src/core/template/handlers/specialized_handler_utils.dart
index 826417966..c5711d51e 100644
--- a/lib/src/core/template/handlers/specialized_handler_utils.dart
+++ b/lib/src/core/template/handlers/specialized_handler_utils.dart
@@ -235,6 +235,42 @@ String addUntilRules(List rules, String name, String delimiter) {
return name;
}
+/// Adds rules accepting content up to and including the first [delimiter],
+/// as llama.cpp's `p.ac` emits them.
+String addThroughRules(List rules, String name, String delimiter) {
+ final pattern = delimiter.runes
+ .map(String.fromCharCode)
+ .toList(growable: false);
+ final alphabet = [];
+ for (final character in pattern) {
+ if (!alphabet.contains(character)) {
+ alphabet.add(character);
+ }
+ }
+ final fallback = '[^${alphabet.map(_escapeGbnfCharClass).join()}]';
+ String state(int index) => '$name-$index';
+
+ for (var index = 0; index < pattern.length; index++) {
+ final alternatives = [];
+ for (final character in alphabet) {
+ final candidate = [...pattern.take(index), character];
+ var next = candidate.length;
+ while (next > 0 &&
+ !_endsWithCharacters(candidate, pattern.take(next).toList())) {
+ next--;
+ }
+ final literal = ToolCallGrammarUtils.literal(character);
+ alternatives.add(
+ next == pattern.length ? literal : '$literal ${state(next)}',
+ );
+ }
+ alternatives.add('$fallback ${state(0)}');
+ rules.add('${state(index)} ::= ${alternatives.join(' | ')}');
+ }
+ rules.add('$name ::= ${state(0)}');
+ return name;
+}
+
bool _endsWithCharacters(List value, List suffix) {
if (suffix.length > value.length) {
return false;
diff --git a/lib/src/core/template/xml_tool_call_format.dart b/lib/src/core/template/xml_tool_call_format.dart
index fba29bba5..75eba46a3 100644
--- a/lib/src/core/template/xml_tool_call_format.dart
+++ b/lib/src/core/template/xml_tool_call_format.dart
@@ -2,7 +2,6 @@ import '../models/tools/tool_definition.dart';
import '../models/chat/completion_chunk.dart';
import 'chat_parse_result.dart';
import 'thinking_utils.dart';
-import 'tool_call_grammar_utils.dart';
import 'tool_call_parsing_utils.dart';
import 'tool_schema_utils.dart';
@@ -213,18 +212,11 @@ class XmlToolCallFormat {
///
/// The root of a format that [XmlToolCallFormat.repeatsScope] admits one tool
/// call per scope, in consecutive scopes, as llama.cpp's grammar does; when
-/// [parallelToolCalls] is false, exactly one. With [textBeforeCalls], text
-/// without a call opening may precede them, as in llama.cpp's grammar for a
-/// required call. With [bareFirstCall], the first call may leave out the
-/// scope start, and a declared tool's opening, such as
-/// ``, is a call opening. Other formats ignore these
-/// options.
+/// [parallelToolCalls] is false, exactly one. Other formats ignore it.
String? buildXmlToolCallGrammar(
List? tools,
XmlToolCallFormat format, {
bool parallelToolCalls = true,
- bool textBeforeCalls = false,
- bool bareFirstCall = false,
}) {
if (tools == null || tools.isEmpty) {
return null;
@@ -265,33 +257,15 @@ obj ::= "{" space (string ":" space value ("," space string ":" space value)*)?
''';
if (format.repeatsScope) {
- // Qwen and Seed-OSS emit the XML envelope with line breaks between tags. Lazy grammar
+ // Seed-OSS emits the XML envelope with line breaks between tags. Lazy grammar
// activation replays that exact trigger text, so whitespace must be valid
// in the grammar rather than relying on eager constrained decoding to
// remove it.
final scope = 'xml-space tool-call ${_literal(format.scopeEnd)} xml-space';
- final firstScope = bareFirstCall
- ? 'first-tool-call-scope'
- : 'tool-call-scope';
- final scopes = !parallelToolCalls
- ? firstScope
- : bareFirstCall
- ? '$firstScope tool-call-scope*'
- : 'tool-call-scope+';
- final extraRules = [
- if (bareFirstCall)
- 'first-tool-call-scope ::= ${_literal(format.scopeStart)}? $scope',
- if (textBeforeCalls)
- ...ToolCallGrammarUtils.excludingRules('text-before-calls', [
- format.scopeStart,
- if (bareFirstCall)
- for (final name in toolNames) format.bareCallOpening(name),
- ]),
- ].map((rule) => '$rule\n').join();
return '''
-root ::= ${textBeforeCalls ? 'text-before-calls ' : ''}$scopes
+root ::= ${parallelToolCalls ? 'tool-call-scope+' : 'tool-call-scope'}
tool-call-scope ::= ${_literal(format.scopeStart)} $scope
-${extraRules}tool-call ::= ${_literal(format.toolStart)} tool-name ${_literal(format.toolSep)} xml-space param* ${_literal(format.toolEnd)} xml-space
+tool-call ::= ${_literal(format.toolStart)} tool-name ${_literal(format.toolSep)} xml-space param* ${_literal(format.toolEnd)} xml-space
param ::= ${_literal(format.keyStart)} param-name ${_literal(format.keyValSep)} xml-value ${_literal(format.valEnd)} xml-space
tool-name ::= $toolNameRule
param-name ::= $paramNameRule
@@ -594,9 +568,13 @@ 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.
+/// Each scope holds one call framed by line breaks as in llama.cpp's
+/// Qwen3-Coder parser: `\n\n`, then each argument
+/// as `\n` and its value up to the first
+/// `\n\n`, then `\n`. 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. A
+/// partial reply holds back the start of a scope it may still complete.
ChatParseResult _parseCallsEndingReply(
String content,
XmlToolCallFormat format, {
@@ -607,21 +585,23 @@ ChatParseResult _parseCallsEndingReply(
}) {
final scopeIdx = content.indexOf(format.scopeStart);
if (scopeIdx == -1) {
+ final held = isPartial
+ ? _trailingPrefixLength(content, format.scopeStart)
+ : 0;
return ChatParseResult(
- content: content.trim(),
+ content: content.substring(0, content.length - held).trim(),
reasoningContent: reasoning,
);
}
final toolCalls = [];
var pos = scopeIdx;
while ((maxToolCalls == null || toolCalls.length < maxToolCalls) &&
- content.startsWith(format.scopeStart, pos)) {
- final toolIdx = _consumeXmlWhitespace(
+ content.startsWith('${format.scopeStart}\n', pos)) {
+ final call = _parseLineFramedCall(
content,
- pos + format.scopeStart.length,
+ pos + format.scopeStart.length + 1,
+ schemas,
);
- 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 &&
@@ -646,6 +626,133 @@ ChatParseResult _parseCallsEndingReply(
);
}
+/// llama.cpp takes the required arguments of a call in any order only up to
+/// this many, and in declaration order beyond it.
+const _maxPermutedRequiredArguments = 6;
+
+/// Parses the Qwen3-Coder call that opens at [start] with `>? schemas,
+) {
+ const functionOpen = '\n', nameStart);
+ if (nameEnd == -1) return null;
+ final name = content.substring(nameStart, nameEnd);
+ final schema = schemas?[name];
+ if (name.isEmpty ||
+ name.contains('\n') ||
+ (schemas != null && schema == null)) {
+ return null;
+ }
+ final properties = schema == null ? null : schemaProperties(schema);
+ final requiredNames = schema == null
+ ? const {}
+ : schemaRequired(schema);
+ final requiredOrder = [
+ for (final key in properties?.keys ?? const [])
+ if (requiredNames.contains(key)) key,
+ ];
+ final args = {};
+ var pos = nameEnd + 2;
+ var requiredSeen = 0;
+ while (true) {
+ final argument = _parseLineFramedArgument(content, pos, properties);
+ final key = argument?.key;
+ if (requiredSeen < requiredOrder.length) {
+ final expected = requiredOrder.length > _maxPermutedRequiredArguments
+ ? {requiredOrder[requiredSeen]}
+ : requiredOrder.where((name) => !args.containsKey(name)).toSet();
+ if (argument == null || !expected.contains(key)) return null;
+ requiredSeen++;
+ } else if (argument == null ||
+ (properties != null && requiredNames.contains(key))) {
+ break;
+ }
+ args[key!] = argument.value;
+ pos = argument.nextPos;
+ }
+ if (!content.startsWith(functionClose, pos)) return null;
+ pos += functionClose.length;
+ if (pos < content.length) {
+ if (content.codeUnitAt(pos) != 0x0A) return null;
+ pos++;
+ }
+ return _ParsedXmlToolCall(name: name, arguments: args, nextPos: pos);
+}
+
+/// Parses the argument that opens at [start] with `>? properties,
+) {
+ const parameterOpen = '\n', keyStart);
+ if (keyEnd == -1) return null;
+ final key = content.substring(keyStart, keyEnd);
+ final schema = properties?[key];
+ if (key.isEmpty ||
+ key.contains('\n') ||
+ (properties != null && schema == null)) {
+ return null;
+ }
+ final valueStart = keyEnd + 2;
+ final valueEndIdx = content.indexOf(valueEnd, valueStart);
+ if (valueEndIdx == -1) return null;
+ final raw = content.substring(valueStart, valueEndIdx);
+ final Object? value;
+ if (schema == null) {
+ value = ToolCallParsingUtils.decodeJsonValueOrString(raw);
+ } else {
+ final decoded = _decodeLineFramedValue(raw, schema);
+ if (!decoded.valid) return null;
+ value = decoded.value;
+ }
+ return (key: key, value: value, nextPos: valueEndIdx + valueEnd.length);
+}
+
+/// Decodes the raw value [raw] of an argument with [schema].
+///
+/// As llama.cpp does, a value that may be a string is JSON only when it is a
+/// JSON value other than a string, and otherwise the text as generated.
+ToolSchemaValueResult _decodeLineFramedValue(
+ String raw,
+ Map schema,
+) {
+ if (schemaResolvesToString(schema)) {
+ return validateToolSchemaValue(raw, schema);
+ }
+ // llama.cpp's JSON value has no whitespace around it.
+ if (raw.isNotEmpty && raw.trim() == raw) {
+ final decoded = raw == 'null'
+ ? (value: null)
+ : switch (ToolCallParsingUtils.decodeJsonValue(raw)) {
+ null => null,
+ final Object value => (value: value),
+ };
+ if (decoded != null && decoded.value is! String) {
+ final result = validateToolSchemaValue(decoded.value, schema);
+ if (result.valid) return result;
+ }
+ }
+ return validateToolSchemaValue(raw, schema);
+}
+
/// 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-tool-calling/SKILL.md b/skills/llamadart-tool-calling/SKILL.md
index 3ad5ab4d3..907d14eec 100644
--- a/skills/llamadart-tool-calling/SKILL.md
+++ b/skills/llamadart-tool-calling/SKILL.md
@@ -170,10 +170,12 @@ 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. With `ToolChoice.required`, a
+- Qwen3-Coder XML replies (Qwen3-Coder, Qwen3.5, StepFun3.5-Flash, Nemotron 3
+ Nano) 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. A call needs a
+ line break after each tag and around each value, and its required
+ arguments before its optional ones. With `ToolChoice.required`, a
thought and text may precede the calls, so leave room in `maxTokens`, and
the Qwen3-Coder template's first call may leave out `` and start
at ``. With `ToolChoice.auto` that tag is text.
diff --git a/test/e2e/template/specialized_tool_grammar_validation_e2e_test.dart b/test/e2e/template/specialized_tool_grammar_validation_e2e_test.dart
index 3706d3e6d..ff670af49 100644
--- a/test/e2e/template/specialized_tool_grammar_validation_e2e_test.dart
+++ b/test/e2e/template/specialized_tool_grammar_validation_e2e_test.dart
@@ -576,8 +576,8 @@ void main() {
final compact =
'<$scope>Paris'
'$scope>';
- // As in llama.cpp, a Seed-OSS scope starts with a line break.
- final isSeed = scope == 'seed:tool_call';
+ // As in llama.cpp, a scope starts with a line break, and a
+ // Qwen3-Coder call keeps the line breaks between its tags.
for (final parallel in [true, false]) {
final rendered = ChatTemplateEngine.render(
templateSource: File(template).readAsStringSync(),
@@ -616,15 +616,12 @@ void main() {
valid: [
call('Paris'),
'${call('Paris')}\n',
- if (!isSeed) compact,
if (parallel) ...repeated,
],
invalid: [
- if (isSeed) ...[
- compact,
- call('Paris').replaceFirst('>\n', '> '),
- '${call('Paris')}\n${call('Rome').replaceFirst('>\n', '>')}',
- ],
+ compact,
+ call('Paris').replaceFirst('>\n', '> '),
+ '${call('Paris')}\n${call('Rome').replaceFirst('>\n', '>')}',
if (!parallel) ...repeated,
'${call('Paris')}\nThen ${call('Rome')}',
'${call('Paris')}\n${call('Rome', name: 'unknown')}',
diff --git a/test/fixtures/forced_open_thought_upstream.json b/test/fixtures/forced_open_thought_upstream.json
index 40bf0d4f4..8b420ddac 100644
--- a/test/fixtures/forced_open_thought_upstream.json
+++ b/test/fixtures/forced_open_thought_upstream.json
@@ -187,7 +187,7 @@
"template": "test/fixtures/templates/Qwen3_5-0_8B.jinja",
"format": "qwen3CoderXml",
"generation_prompt": "<|im_start|>assistant\n\n",
- "required_grammar_start": "root ::= text-before-calls tool-call-scope",
+ "required_grammar_start": "root ::= text-before-calls tool-call",
"cases": [
{
"name": "escaped-newline-in-ended-thought",
diff --git a/test/fixtures/qwen3_coder_call_body_upstream.json b/test/fixtures/qwen3_coder_call_body_upstream.json
new file mode 100644
index 000000000..7fc0de0a5
--- /dev/null
+++ b/test/fixtures/qwen3_coder_call_body_upstream.json
@@ -0,0 +1,7145 @@
+{
+ "upstream_commit": "cd959bae99ff4bed22bef2604f45241c09bbb8c8",
+ "user_prompt": "Weather in Paris?",
+ "tools": [
+ {
+ "type": "function",
+ "function": {
+ "name": "get_weather",
+ "description": "w",
+ "parameters": {
+ "type": "object",
+ "properties": {
+ "location": {
+ "type": "string"
+ }
+ },
+ "required": [
+ "location"
+ ]
+ }
+ }
+ },
+ {
+ "type": "function",
+ "function": {
+ "name": "get_time",
+ "description": "t",
+ "parameters": {
+ "type": "object",
+ "properties": {
+ "tz": {
+ "type": "string"
+ },
+ "days": {
+ "type": "integer"
+ }
+ },
+ "required": [
+ "tz"
+ ]
+ }
+ }
+ }
+ ],
+ "templates": [
+ {
+ "template": "test/fixtures/llama_cpp_templates/Qwen3-Coder.jinja",
+ "enable_thinking": true,
+ "parallel_tool_calls": false,
+ "cases": [
+ {
+ "name": "req-then-opt",
+ "output": "\n\n\nUTC\n\n\n3\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_time",
+ "arguments": "{\"tz\":\"UTC\",\"days\":3}"
+ }
+ ]
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_time",
+ "arguments": "{\"tz\":\"UTC\",\"days\":3}"
+ }
+ ]
+ }
+ },
+ {
+ "name": "opt-before-req",
+ "output": "\n\n\n3\n\n\nUTC\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ }
+ },
+ {
+ "name": "opt-before-req-then-call",
+ "output": "\n\n\n3\n\n\nUTC\n\n\n\n\n\n\nParis\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ }
+ },
+ {
+ "name": "call-then-opt-before-req",
+ "output": "\n\n\nParis\n\n\n\n\n\n\n3\n\n\nUTC\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": "opt-only",
+ "output": "\n\n\n3\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ }
+ },
+ {
+ "name": "opt-dup",
+ "output": "\n\n\nUTC\n\n\n3\n\n\n4\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_time",
+ "arguments": "{\"tz\":\"UTC\",\"days\":3,\"days\":4}"
+ }
+ ]
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_time",
+ "arguments": "{\"tz\":\"UTC\",\"days\":3,\"days\":4}"
+ }
+ ]
+ }
+ },
+ {
+ "name": "inline-param-end",
+ "output": "\n\n\nA B\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"A B\"}"
+ }
+ ]
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"A B\"}"
+ }
+ ]
+ }
+ },
+ {
+ "name": "inline-param-end-tail",
+ "output": "\n\n\nA B\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"A B\"}"
+ }
+ ]
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"A B\"}"
+ }
+ ]
+ }
+ },
+ {
+ "name": "inline-param-end-nl-before",
+ "output": "\n\n\nA\n B\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"A\\n B\"}"
+ }
+ ]
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"A\\n B\"}"
+ }
+ ]
+ }
+ },
+ {
+ "name": "inline-param-end-at-end",
+ "output": "\n\n\nA \n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"A \"}"
+ }
+ ]
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"A \"}"
+ }
+ ]
+ }
+ },
+ {
+ "name": "inline-param-end-then-opt",
+ "output": "\n\n\nU TC\n\n\n3\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_time",
+ "arguments": "{\"tz\":\"U TC\",\"days\":3}"
+ }
+ ]
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_time",
+ "arguments": "{\"tz\":\"U TC\",\"days\":3}"
+ }
+ ]
+ }
+ },
+ {
+ "name": "value-fn-end",
+ "output": "\n\n\nA B\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"A B\"}"
+ }
+ ]
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"A B\"}"
+ }
+ ]
+ }
+ },
+ {
+ "name": "value-lt",
+ "output": "\n\n\na < b\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"a < b\"}"
+ }
+ ]
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"a < b\"}"
+ }
+ ]
+ }
+ },
+ {
+ "name": "value-param-open",
+ "output": "\n\n\n\nx\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"\\nx\"}"
+ }
+ ]
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"\\nx\"}"
+ }
+ ]
+ }
+ },
+ {
+ "name": "value-spaces",
+ "output": "\n\n\n Paris \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": "value-blank-lines",
+ "output": "\n\n\n\nParis\n\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"\\nParis\\n\"}"
+ }
+ ]
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"\\nParis\\n\"}"
+ }
+ ]
+ }
+ },
+ {
+ "name": "int-spaces",
+ "output": "\n\n\nUTC\n\n\n 3 \n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ }
+ },
+ {
+ "name": "int-no-nl",
+ "output": "\n\n\nUTC\n\n3\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ }
+ },
+ {
+ "name": "int-inline-end",
+ "output": "\n\n\nUTC\n\n\n3 \n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ }
+ },
+ {
+ "name": "crlf",
+ "output": "\r\n\r\n\r\nParis\r\n\r\n\r\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ }
+ },
+ {
+ "name": "crlf-text",
+ "output": "Hi.\r\n\r\n\r\n\r\nParis\r\n\r\n\r\n",
+ "upstream": {
+ "content": "Hi.\r",
+ "reasoning_content": "",
+ "tool_calls": []
+ },
+ "upstream_partial": {
+ "content": "Hi.\r",
+ "reasoning_content": "",
+ "tool_calls": []
+ }
+ },
+ {
+ "name": "no-nl-all",
+ "output": "Paris",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ }
+ },
+ {
+ "name": "no-nl-after-scope",
+ "output": "\n\nParis\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ }
+ },
+ {
+ "name": "no-nl-after-fn",
+ "output": "\n\nParis\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ }
+ },
+ {
+ "name": "no-nl-after-param-open",
+ "output": "\n\nParis\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ }
+ },
+ {
+ "name": "no-nl-after-fn-end",
+ "output": "\n\n\nParis\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ }
+ },
+ {
+ "name": "no-nl-value-both",
+ "output": "\n\nParis\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ }
+ },
+ {
+ "name": "space-after-scope",
+ "output": " \n\n\nParis\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ }
+ },
+ {
+ "name": "blank-after-scope",
+ "output": "\n\n\n\nParis\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ }
+ },
+ {
+ "name": "blank-after-fn",
+ "output": "\n\n\n\nParis\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ }
+ },
+ {
+ "name": "blank-after-param-end",
+ "output": "\n\n\nParis\n\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ }
+ },
+ {
+ "name": "space-before-fn-end",
+ "output": "\n\n\nParis\n\n \n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ }
+ },
+ {
+ "name": "blank-before-scope-end",
+ "output": "\n\n\nParis\n\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ }
+ },
+ {
+ "name": "second-call-crlf",
+ "output": "\n\n\nParis\n\n\n\n\r\n\r\n\r\nRome\r\n\r\n\r\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": "second-call-no-nl",
+ "output": "\n\n\nParis\n\n\n\nRome",
+ "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": "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-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": "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": "plain",
+ "output": "Hello there.",
+ "upstream": {
+ "content": "Hello there.",
+ "reasoning_content": "",
+ "tool_calls": []
+ },
+ "upstream_partial": {
+ "content": "Hello there.",
+ "reasoning_content": "",
+ "tool_calls": []
+ }
+ },
+ {
+ "name": "forced-plain-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": "forced-think-call",
+ "output": "Plan\n\n\n\n\n\nParis\n\n\n",
+ "upstream": {
+ "content": "Plan\n",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"Paris\"}"
+ }
+ ]
+ },
+ "upstream_partial": {
+ "content": "Plan\n",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"Paris\"}"
+ }
+ ]
+ }
+ },
+ {
+ "name": "forced-think-text",
+ "output": "Plan\n\n\nAnswer.",
+ "upstream": {
+ "content": "Plan\n\n\nAnswer.",
+ "reasoning_content": "",
+ "tool_calls": []
+ },
+ "upstream_partial": {
+ "content": "Plan\n\n\nAnswer.",
+ "reasoning_content": "",
+ "tool_calls": []
+ }
+ },
+ {
+ "name": "call-no-think-end",
+ "output": "Let me plan.\n\n\n\nParis\n\n\n",
+ "upstream": {
+ "content": "Let me plan.",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"Paris\"}"
+ }
+ ]
+ },
+ "upstream_partial": {
+ "content": "Let me plan.",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"Paris\"}"
+ }
+ ]
+ }
+ }
+ ]
+ },
+ {
+ "template": "test/fixtures/llama_cpp_templates/Qwen3-Coder.jinja",
+ "enable_thinking": true,
+ "parallel_tool_calls": true,
+ "tool_choice": "required",
+ "cases": [
+ {
+ "name": "req-then-opt",
+ "output": "\n\n\nUTC\n\n\n3\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_time",
+ "arguments": "{\"tz\":\"UTC\",\"days\":3}"
+ }
+ ]
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_time",
+ "arguments": "{\"tz\":\"UTC\",\"days\":3}"
+ }
+ ]
+ }
+ },
+ {
+ "name": "call-then-opt-before-req",
+ "output": "\n\n\nParis\n\n\n\n\n\n\n3\n\n\nUTC\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": "opt-dup",
+ "output": "\n\n\nUTC\n\n\n3\n\n\n4\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_time",
+ "arguments": "{\"tz\":\"UTC\",\"days\":3,\"days\":4}"
+ }
+ ]
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_time",
+ "arguments": "{\"tz\":\"UTC\",\"days\":3,\"days\":4}"
+ }
+ ]
+ }
+ },
+ {
+ "name": "inline-param-end",
+ "output": "\n\n\nA B\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"A B\"}"
+ }
+ ]
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"A B\"}"
+ }
+ ]
+ }
+ },
+ {
+ "name": "inline-param-end-tail",
+ "output": "\n\n\nA B\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"A B\"}"
+ }
+ ]
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"A B\"}"
+ }
+ ]
+ }
+ },
+ {
+ "name": "inline-param-end-nl-before",
+ "output": "\n\n\nA\n B\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"A\\n B\"}"
+ }
+ ]
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"A\\n B\"}"
+ }
+ ]
+ }
+ },
+ {
+ "name": "inline-param-end-at-end",
+ "output": "\n\n\nA \n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"A \"}"
+ }
+ ]
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"A \"}"
+ }
+ ]
+ }
+ },
+ {
+ "name": "inline-param-end-then-opt",
+ "output": "\n\n\nU TC\n\n\n3\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_time",
+ "arguments": "{\"tz\":\"U TC\",\"days\":3}"
+ }
+ ]
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_time",
+ "arguments": "{\"tz\":\"U TC\",\"days\":3}"
+ }
+ ]
+ }
+ },
+ {
+ "name": "value-fn-end",
+ "output": "\n\n\nA B\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"A B\"}"
+ }
+ ]
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"A B\"}"
+ }
+ ]
+ }
+ },
+ {
+ "name": "value-lt",
+ "output": "\n\n\na < b\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"a < b\"}"
+ }
+ ]
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"a < b\"}"
+ }
+ ]
+ }
+ },
+ {
+ "name": "value-param-open",
+ "output": "\n\n\n\nx\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"\\nx\"}"
+ }
+ ]
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"\\nx\"}"
+ }
+ ]
+ }
+ },
+ {
+ "name": "value-spaces",
+ "output": "\n\n\n Paris \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": "value-blank-lines",
+ "output": "\n\n\n\nParis\n\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"\\nParis\\n\"}"
+ }
+ ]
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"\\nParis\\n\"}"
+ }
+ ]
+ }
+ },
+ {
+ "name": "second-call-crlf",
+ "output": "\n\n\nParis\n\n\n\n\r\n\r\n\r\nRome\r\n\r\n\r\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": "second-call-no-nl",
+ "output": "\n\n\nParis\n\n\n\nRome",
+ "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": "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-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": "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": "plain",
+ "output": "Hello there.",
+ "upstream": {
+ "content": "Hello there.",
+ "reasoning_content": "",
+ "tool_calls": []
+ },
+ "upstream_partial": {
+ "content": "Hello there.",
+ "reasoning_content": "",
+ "tool_calls": []
+ }
+ },
+ {
+ "name": "forced-plain-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": "forced-think-call",
+ "output": "Plan\n\n\n\n\n\nParis\n\n\n",
+ "upstream": {
+ "content": "Plan\n",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"Paris\"}"
+ }
+ ]
+ },
+ "upstream_partial": {
+ "content": "Plan\n",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"Paris\"}"
+ }
+ ]
+ }
+ },
+ {
+ "name": "forced-think-text",
+ "output": "Plan\n\n\nAnswer.",
+ "upstream": {
+ "content": "Plan\n\n\nAnswer.",
+ "reasoning_content": "",
+ "tool_calls": []
+ },
+ "upstream_partial": {
+ "content": "Plan\n\n\nAnswer.",
+ "reasoning_content": "",
+ "tool_calls": []
+ }
+ },
+ {
+ "name": "call-no-think-end",
+ "output": "Let me plan.\n\n\n\nParis\n\n\n",
+ "upstream": {
+ "content": "Let me plan.",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"Paris\"}"
+ }
+ ]
+ },
+ "upstream_partial": {
+ "content": "Let me plan.",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"Paris\"}"
+ }
+ ]
+ }
+ }
+ ]
+ },
+ {
+ "template": "test/fixtures/templates/Qwen3_5-0_8B.jinja",
+ "enable_thinking": true,
+ "parallel_tool_calls": true,
+ "cases": [
+ {
+ "name": "req-then-opt",
+ "output": "\n\n\nUTC\n\n\n3\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_time",
+ "arguments": "{\"tz\":\"UTC\",\"days\":3}"
+ }
+ ]
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_time",
+ "arguments": "{\"tz\":\"UTC\",\"days\":3}"
+ }
+ ]
+ }
+ },
+ {
+ "name": "opt-before-req",
+ "output": "\n\n\n3\n\n\nUTC\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ }
+ },
+ {
+ "name": "opt-before-req-then-call",
+ "output": "\n\n\n3\n\n\nUTC\n\n\n\n\n\n\nParis\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ }
+ },
+ {
+ "name": "call-then-opt-before-req",
+ "output": "\n\n\nParis\n\n\n\n\n\n\n3\n\n\nUTC\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": "opt-only",
+ "output": "\n\n\n3\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ }
+ },
+ {
+ "name": "opt-dup",
+ "output": "\n\n\nUTC\n\n\n3\n\n\n4\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_time",
+ "arguments": "{\"tz\":\"UTC\",\"days\":3,\"days\":4}"
+ }
+ ]
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_time",
+ "arguments": "{\"tz\":\"UTC\",\"days\":3,\"days\":4}"
+ }
+ ]
+ }
+ },
+ {
+ "name": "inline-param-end",
+ "output": "\n\n\nA B\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"A B\"}"
+ }
+ ]
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"A B\"}"
+ }
+ ]
+ }
+ },
+ {
+ "name": "inline-param-end-tail",
+ "output": "\n\n\nA B\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"A B\"}"
+ }
+ ]
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"A B\"}"
+ }
+ ]
+ }
+ },
+ {
+ "name": "inline-param-end-nl-before",
+ "output": "\n\n\nA\n B\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"A\\n B\"}"
+ }
+ ]
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"A\\n B\"}"
+ }
+ ]
+ }
+ },
+ {
+ "name": "inline-param-end-at-end",
+ "output": "\n\n\nA \n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"A \"}"
+ }
+ ]
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"A \"}"
+ }
+ ]
+ }
+ },
+ {
+ "name": "inline-param-end-then-opt",
+ "output": "\n\n\nU TC\n\n\n3\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_time",
+ "arguments": "{\"tz\":\"U TC\",\"days\":3}"
+ }
+ ]
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_time",
+ "arguments": "{\"tz\":\"U TC\",\"days\":3}"
+ }
+ ]
+ }
+ },
+ {
+ "name": "value-fn-end",
+ "output": "\n\n\nA B\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"A B\"}"
+ }
+ ]
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"A B\"}"
+ }
+ ]
+ }
+ },
+ {
+ "name": "value-lt",
+ "output": "\n\n\na < b\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"a < b\"}"
+ }
+ ]
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"a < b\"}"
+ }
+ ]
+ }
+ },
+ {
+ "name": "value-param-open",
+ "output": "\n\n\n\nx\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"\\nx\"}"
+ }
+ ]
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"\\nx\"}"
+ }
+ ]
+ }
+ },
+ {
+ "name": "value-spaces",
+ "output": "\n\n\n Paris \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": "value-blank-lines",
+ "output": "\n\n\n\nParis\n\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"\\nParis\\n\"}"
+ }
+ ]
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"\\nParis\\n\"}"
+ }
+ ]
+ }
+ },
+ {
+ "name": "int-spaces",
+ "output": "\n\n\nUTC\n\n\n 3 \n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ }
+ },
+ {
+ "name": "int-no-nl",
+ "output": "\n\n\nUTC\n\n3\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ }
+ },
+ {
+ "name": "int-inline-end",
+ "output": "\n\n\nUTC\n\n\n3 \n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ }
+ },
+ {
+ "name": "crlf",
+ "output": "\r\n\r\n\r\nParis\r\n\r\n\r\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ }
+ },
+ {
+ "name": "crlf-text",
+ "output": "Hi.\r\n\r\n\r\n\r\nParis\r\n\r\n\r\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "Hi.\r\n",
+ "tool_calls": []
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "Hi.\r\n",
+ "tool_calls": []
+ }
+ },
+ {
+ "name": "no-nl-all",
+ "output": "Paris",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ }
+ },
+ {
+ "name": "no-nl-after-scope",
+ "output": "\n\nParis\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ }
+ },
+ {
+ "name": "no-nl-after-fn",
+ "output": "\n\nParis\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ }
+ },
+ {
+ "name": "no-nl-after-param-open",
+ "output": "\n\nParis\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ }
+ },
+ {
+ "name": "no-nl-after-fn-end",
+ "output": "\n\n\nParis\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ }
+ },
+ {
+ "name": "no-nl-value-both",
+ "output": "\n\nParis\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ }
+ },
+ {
+ "name": "space-after-scope",
+ "output": " \n\n\nParis\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ }
+ },
+ {
+ "name": "blank-after-scope",
+ "output": "\n\n\n\nParis\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ }
+ },
+ {
+ "name": "blank-after-fn",
+ "output": "\n\n\n\nParis\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ }
+ },
+ {
+ "name": "blank-after-param-end",
+ "output": "\n\n\nParis\n\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ }
+ },
+ {
+ "name": "space-before-fn-end",
+ "output": "\n\n\nParis\n\n \n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ }
+ },
+ {
+ "name": "blank-before-scope-end",
+ "output": "\n\n\nParis\n\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ }
+ },
+ {
+ "name": "second-call-crlf",
+ "output": "\n\n\nParis\n\n\n\n\r\n\r\n\r\nRome\r\n\r\n\r\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": "second-call-no-nl",
+ "output": "\n\n\nParis\n\n\n\nRome",
+ "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": "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-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": "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": "plain",
+ "output": "Hello there.",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "Hello there.",
+ "tool_calls": []
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "Hello there.",
+ "tool_calls": []
+ }
+ },
+ {
+ "name": "forced-plain-call",
+ "output": "Plan\n\n\n\nParis\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "Plan\n",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"Paris\"}"
+ }
+ ]
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "Plan\n",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"Paris\"}"
+ }
+ ]
+ }
+ },
+ {
+ "name": "forced-think-call",
+ "output": "Plan\n\n\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": "forced-think-text",
+ "output": "Plan\n\n\nAnswer.",
+ "upstream": {
+ "content": "Answer.",
+ "reasoning_content": "Plan",
+ "tool_calls": []
+ },
+ "upstream_partial": {
+ "content": "Answer.",
+ "reasoning_content": "Plan",
+ "tool_calls": []
+ }
+ },
+ {
+ "name": "call-no-think-end",
+ "output": "Let me plan.\n\n\n\nParis\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "Let me plan.\n",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"Paris\"}"
+ }
+ ]
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "Let me plan.\n",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"Paris\"}"
+ }
+ ]
+ }
+ }
+ ]
+ },
+ {
+ "template": "test/fixtures/templates/Qwen3_5-0_8B.jinja",
+ "enable_thinking": false,
+ "parallel_tool_calls": false,
+ "cases": [
+ {
+ "name": "req-then-opt",
+ "output": "\n\n\nUTC\n\n\n3\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_time",
+ "arguments": "{\"tz\":\"UTC\",\"days\":3}"
+ }
+ ]
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_time",
+ "arguments": "{\"tz\":\"UTC\",\"days\":3}"
+ }
+ ]
+ }
+ },
+ {
+ "name": "opt-before-req",
+ "output": "\n\n\n3\n\n\nUTC\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ }
+ },
+ {
+ "name": "opt-before-req-then-call",
+ "output": "\n\n\n3\n\n\nUTC\n\n\n\n\n\n\nParis\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ }
+ },
+ {
+ "name": "call-then-opt-before-req",
+ "output": "\n\n\nParis\n\n\n\n\n\n\n3\n\n\nUTC\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": "opt-only",
+ "output": "\n\n\n3\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ }
+ },
+ {
+ "name": "opt-dup",
+ "output": "\n\n\nUTC\n\n\n3\n\n\n4\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_time",
+ "arguments": "{\"tz\":\"UTC\",\"days\":3,\"days\":4}"
+ }
+ ]
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_time",
+ "arguments": "{\"tz\":\"UTC\",\"days\":3,\"days\":4}"
+ }
+ ]
+ }
+ },
+ {
+ "name": "inline-param-end",
+ "output": "\n\n\nA B\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"A B\"}"
+ }
+ ]
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"A B\"}"
+ }
+ ]
+ }
+ },
+ {
+ "name": "inline-param-end-tail",
+ "output": "\n\n\nA B\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"A B\"}"
+ }
+ ]
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"A B\"}"
+ }
+ ]
+ }
+ },
+ {
+ "name": "inline-param-end-nl-before",
+ "output": "\n\n\nA\n B\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"A\\n B\"}"
+ }
+ ]
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"A\\n B\"}"
+ }
+ ]
+ }
+ },
+ {
+ "name": "inline-param-end-at-end",
+ "output": "\n\n\nA \n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"A \"}"
+ }
+ ]
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"A \"}"
+ }
+ ]
+ }
+ },
+ {
+ "name": "inline-param-end-then-opt",
+ "output": "\n\n\nU TC\n\n\n3\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_time",
+ "arguments": "{\"tz\":\"U TC\",\"days\":3}"
+ }
+ ]
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_time",
+ "arguments": "{\"tz\":\"U TC\",\"days\":3}"
+ }
+ ]
+ }
+ },
+ {
+ "name": "value-fn-end",
+ "output": "\n\n\nA B\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"A B\"}"
+ }
+ ]
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"A B\"}"
+ }
+ ]
+ }
+ },
+ {
+ "name": "value-lt",
+ "output": "\n\n\na < b\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"a < b\"}"
+ }
+ ]
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"a < b\"}"
+ }
+ ]
+ }
+ },
+ {
+ "name": "value-param-open",
+ "output": "\n\n\n\nx\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"\\nx\"}"
+ }
+ ]
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"\\nx\"}"
+ }
+ ]
+ }
+ },
+ {
+ "name": "value-spaces",
+ "output": "\n\n\n Paris \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": "value-blank-lines",
+ "output": "\n\n\n\nParis\n\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"\\nParis\\n\"}"
+ }
+ ]
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"\\nParis\\n\"}"
+ }
+ ]
+ }
+ },
+ {
+ "name": "int-spaces",
+ "output": "\n\n\nUTC\n\n\n 3 \n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ }
+ },
+ {
+ "name": "int-no-nl",
+ "output": "\n\n\nUTC\n\n3\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ }
+ },
+ {
+ "name": "int-inline-end",
+ "output": "\n\n\nUTC\n\n\n3 \n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ }
+ },
+ {
+ "name": "crlf",
+ "output": "\r\n\r\n\r\nParis\r\n\r\n\r\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ }
+ },
+ {
+ "name": "crlf-text",
+ "output": "Hi.\r\n\r\n\r\n\r\nParis\r\n\r\n\r\n",
+ "upstream": {
+ "content": "Hi.\r",
+ "reasoning_content": "",
+ "tool_calls": []
+ },
+ "upstream_partial": {
+ "content": "Hi.\r",
+ "reasoning_content": "",
+ "tool_calls": []
+ }
+ },
+ {
+ "name": "no-nl-all",
+ "output": "Paris",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ }
+ },
+ {
+ "name": "no-nl-after-scope",
+ "output": "\n\nParis\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ }
+ },
+ {
+ "name": "no-nl-after-fn",
+ "output": "\n\nParis\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ }
+ },
+ {
+ "name": "no-nl-after-param-open",
+ "output": "\n\nParis\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ }
+ },
+ {
+ "name": "no-nl-after-fn-end",
+ "output": "\n\n\nParis\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ }
+ },
+ {
+ "name": "no-nl-value-both",
+ "output": "\n\nParis\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ }
+ },
+ {
+ "name": "space-after-scope",
+ "output": " \n\n\nParis\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ }
+ },
+ {
+ "name": "blank-after-scope",
+ "output": "\n\n\n\nParis\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ }
+ },
+ {
+ "name": "blank-after-fn",
+ "output": "\n\n\n\nParis\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ }
+ },
+ {
+ "name": "blank-after-param-end",
+ "output": "\n\n\nParis\n\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ }
+ },
+ {
+ "name": "space-before-fn-end",
+ "output": "\n\n\nParis\n\n \n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ }
+ },
+ {
+ "name": "blank-before-scope-end",
+ "output": "\n\n\nParis\n\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ }
+ },
+ {
+ "name": "second-call-crlf",
+ "output": "\n\n\nParis\n\n\n\n\r\n\r\n\r\nRome\r\n\r\n\r\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": "second-call-no-nl",
+ "output": "\n\n\nParis\n\n\n\nRome",
+ "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": "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-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": "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": "plain",
+ "output": "Hello there.",
+ "upstream": {
+ "content": "Hello there.",
+ "reasoning_content": "",
+ "tool_calls": []
+ },
+ "upstream_partial": {
+ "content": "Hello there.",
+ "reasoning_content": "",
+ "tool_calls": []
+ }
+ },
+ {
+ "name": "forced-plain-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": "forced-think-call",
+ "output": "Plan\n\n\n\n\n\nParis\n\n\n",
+ "upstream": {
+ "content": "Plan\n",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"Paris\"}"
+ }
+ ]
+ },
+ "upstream_partial": {
+ "content": "Plan\n",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"Paris\"}"
+ }
+ ]
+ }
+ },
+ {
+ "name": "forced-think-text",
+ "output": "Plan\n\n\nAnswer.",
+ "upstream": {
+ "content": "Plan\n\n\nAnswer.",
+ "reasoning_content": "",
+ "tool_calls": []
+ },
+ "upstream_partial": {
+ "content": "Plan\n\n\nAnswer.",
+ "reasoning_content": "",
+ "tool_calls": []
+ }
+ },
+ {
+ "name": "call-no-think-end",
+ "output": "Let me plan.\n\n\n\nParis\n\n\n",
+ "upstream": {
+ "content": "Let me plan.",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"Paris\"}"
+ }
+ ]
+ },
+ "upstream_partial": {
+ "content": "Let me plan.",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"Paris\"}"
+ }
+ ]
+ }
+ }
+ ]
+ },
+ {
+ "template": "test/fixtures/templates/Qwen3_5-0_8B.jinja",
+ "enable_thinking": true,
+ "parallel_tool_calls": false,
+ "tool_choice": "required",
+ "cases": [
+ {
+ "name": "req-then-opt",
+ "output": "\n\n\nUTC\n\n\n3\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_time",
+ "arguments": "{\"tz\":\"UTC\",\"days\":3}"
+ }
+ ]
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_time",
+ "arguments": "{\"tz\":\"UTC\",\"days\":3}"
+ }
+ ]
+ }
+ },
+ {
+ "name": "call-then-opt-before-req",
+ "output": "\n\n\nParis\n\n\n\n\n\n\n3\n\n\nUTC\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": "opt-dup",
+ "output": "\n\n\nUTC\n\n\n3\n\n\n4\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_time",
+ "arguments": "{\"tz\":\"UTC\",\"days\":3,\"days\":4}"
+ }
+ ]
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_time",
+ "arguments": "{\"tz\":\"UTC\",\"days\":3,\"days\":4}"
+ }
+ ]
+ }
+ },
+ {
+ "name": "inline-param-end",
+ "output": "\n\n\nA B\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"A B\"}"
+ }
+ ]
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"A B\"}"
+ }
+ ]
+ }
+ },
+ {
+ "name": "inline-param-end-tail",
+ "output": "\n\n\nA B\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"A B\"}"
+ }
+ ]
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"A B\"}"
+ }
+ ]
+ }
+ },
+ {
+ "name": "inline-param-end-nl-before",
+ "output": "\n\n\nA\n B\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"A\\n B\"}"
+ }
+ ]
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"A\\n B\"}"
+ }
+ ]
+ }
+ },
+ {
+ "name": "inline-param-end-at-end",
+ "output": "\n\n\nA \n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"A \"}"
+ }
+ ]
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"A \"}"
+ }
+ ]
+ }
+ },
+ {
+ "name": "inline-param-end-then-opt",
+ "output": "\n\n\nU TC\n\n\n3\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_time",
+ "arguments": "{\"tz\":\"U TC\",\"days\":3}"
+ }
+ ]
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_time",
+ "arguments": "{\"tz\":\"U TC\",\"days\":3}"
+ }
+ ]
+ }
+ },
+ {
+ "name": "value-fn-end",
+ "output": "\n\n\nA B\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"A B\"}"
+ }
+ ]
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"A B\"}"
+ }
+ ]
+ }
+ },
+ {
+ "name": "value-lt",
+ "output": "\n\n\na < b\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"a < b\"}"
+ }
+ ]
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"a < b\"}"
+ }
+ ]
+ }
+ },
+ {
+ "name": "value-param-open",
+ "output": "\n\n\n\nx\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"\\nx\"}"
+ }
+ ]
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"\\nx\"}"
+ }
+ ]
+ }
+ },
+ {
+ "name": "value-spaces",
+ "output": "\n\n\n Paris \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": "value-blank-lines",
+ "output": "\n\n\n\nParis\n\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"\\nParis\\n\"}"
+ }
+ ]
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"\\nParis\\n\"}"
+ }
+ ]
+ }
+ },
+ {
+ "name": "second-call-crlf",
+ "output": "\n\n\nParis\n\n\n\n\r\n\r\n\r\nRome\r\n\r\n\r\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": "second-call-no-nl",
+ "output": "\n\n\nParis\n\n\n\nRome",
+ "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": "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-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": "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": "plain",
+ "output": "Hello there.",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "Hello there.",
+ "tool_calls": []
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "Hello there.",
+ "tool_calls": []
+ }
+ },
+ {
+ "name": "forced-plain-call",
+ "output": "Plan\n\n\n\nParis\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "Plan\n",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"Paris\"}"
+ }
+ ]
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "Plan\n",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"Paris\"}"
+ }
+ ]
+ }
+ },
+ {
+ "name": "forced-think-call",
+ "output": "Plan\n\n\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": "forced-think-text",
+ "output": "Plan\n\n\nAnswer.",
+ "upstream": {
+ "content": "Answer.",
+ "reasoning_content": "Plan",
+ "tool_calls": []
+ },
+ "upstream_partial": {
+ "content": "Answer.",
+ "reasoning_content": "Plan",
+ "tool_calls": []
+ }
+ },
+ {
+ "name": "call-no-think-end",
+ "output": "Let me plan.\n\n\n\nParis\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "Let me plan.\n",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"Paris\"}"
+ }
+ ]
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "Let me plan.\n",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"Paris\"}"
+ }
+ ]
+ }
+ }
+ ]
+ },
+ {
+ "template": "test/fixtures/llama_cpp_templates/StepFun3.5-Flash.jinja",
+ "enable_thinking": true,
+ "parallel_tool_calls": false,
+ "cases": [
+ {
+ "name": "req-then-opt",
+ "output": "\n\n\nUTC\n\n\n3\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_time",
+ "arguments": "{\"tz\":\"UTC\",\"days\":3}"
+ }
+ ]
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_time",
+ "arguments": "{\"tz\":\"UTC\",\"days\":3}"
+ }
+ ]
+ }
+ },
+ {
+ "name": "opt-before-req",
+ "output": "\n\n\n3\n\n\nUTC\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ }
+ },
+ {
+ "name": "opt-before-req-then-call",
+ "output": "\n\n\n3\n\n\nUTC\n\n\n\n\n\n\nParis\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ }
+ },
+ {
+ "name": "call-then-opt-before-req",
+ "output": "\n\n\nParis\n\n\n\n\n\n\n3\n\n\nUTC\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": "opt-only",
+ "output": "\n\n\n3\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ }
+ },
+ {
+ "name": "opt-dup",
+ "output": "\n\n\nUTC\n\n\n3\n\n\n4\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_time",
+ "arguments": "{\"tz\":\"UTC\",\"days\":3,\"days\":4}"
+ }
+ ]
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_time",
+ "arguments": "{\"tz\":\"UTC\",\"days\":3,\"days\":4}"
+ }
+ ]
+ }
+ },
+ {
+ "name": "inline-param-end",
+ "output": "\n\n\nA B\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"A B\"}"
+ }
+ ]
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"A B\"}"
+ }
+ ]
+ }
+ },
+ {
+ "name": "inline-param-end-tail",
+ "output": "\n\n\nA B\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"A B\"}"
+ }
+ ]
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"A B\"}"
+ }
+ ]
+ }
+ },
+ {
+ "name": "inline-param-end-nl-before",
+ "output": "\n\n\nA\n B\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"A\\n B\"}"
+ }
+ ]
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"A\\n B\"}"
+ }
+ ]
+ }
+ },
+ {
+ "name": "inline-param-end-at-end",
+ "output": "\n\n\nA \n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"A \"}"
+ }
+ ]
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"A \"}"
+ }
+ ]
+ }
+ },
+ {
+ "name": "inline-param-end-then-opt",
+ "output": "\n\n\nU TC\n\n\n3\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_time",
+ "arguments": "{\"tz\":\"U TC\",\"days\":3}"
+ }
+ ]
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_time",
+ "arguments": "{\"tz\":\"U TC\",\"days\":3}"
+ }
+ ]
+ }
+ },
+ {
+ "name": "value-fn-end",
+ "output": "\n\n\nA B\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"A B\"}"
+ }
+ ]
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"A B\"}"
+ }
+ ]
+ }
+ },
+ {
+ "name": "value-lt",
+ "output": "\n\n\na < b\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"a < b\"}"
+ }
+ ]
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"a < b\"}"
+ }
+ ]
+ }
+ },
+ {
+ "name": "value-param-open",
+ "output": "\n\n\n\nx\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"\\nx\"}"
+ }
+ ]
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"\\nx\"}"
+ }
+ ]
+ }
+ },
+ {
+ "name": "value-spaces",
+ "output": "\n\n\n Paris \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": "value-blank-lines",
+ "output": "\n\n\n\nParis\n\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"\\nParis\\n\"}"
+ }
+ ]
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"\\nParis\\n\"}"
+ }
+ ]
+ }
+ },
+ {
+ "name": "int-spaces",
+ "output": "\n\n\nUTC\n\n\n 3 \n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ }
+ },
+ {
+ "name": "int-no-nl",
+ "output": "\n\n\nUTC\n\n3\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ }
+ },
+ {
+ "name": "int-inline-end",
+ "output": "\n\n\nUTC\n\n\n3 \n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ }
+ },
+ {
+ "name": "crlf",
+ "output": "\r\n\r\n\r\nParis\r\n\r\n\r\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ }
+ },
+ {
+ "name": "crlf-text",
+ "output": "Hi.\r\n\r\n\r\n\r\nParis\r\n\r\n\r\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "Hi.\r\n",
+ "tool_calls": []
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "Hi.\r\n",
+ "tool_calls": []
+ }
+ },
+ {
+ "name": "no-nl-all",
+ "output": "Paris",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ }
+ },
+ {
+ "name": "no-nl-after-scope",
+ "output": "\n\nParis\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ }
+ },
+ {
+ "name": "no-nl-after-fn",
+ "output": "\n\nParis\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ }
+ },
+ {
+ "name": "no-nl-after-param-open",
+ "output": "\n\nParis\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ }
+ },
+ {
+ "name": "no-nl-after-fn-end",
+ "output": "\n\n\nParis\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ }
+ },
+ {
+ "name": "no-nl-value-both",
+ "output": "\n\nParis\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ }
+ },
+ {
+ "name": "space-after-scope",
+ "output": " \n\n\nParis\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ }
+ },
+ {
+ "name": "blank-after-scope",
+ "output": "\n\n\n\nParis\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ }
+ },
+ {
+ "name": "blank-after-fn",
+ "output": "\n\n\n\nParis\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ }
+ },
+ {
+ "name": "blank-after-param-end",
+ "output": "\n\n\nParis\n\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ }
+ },
+ {
+ "name": "space-before-fn-end",
+ "output": "\n\n\nParis\n\n \n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ }
+ },
+ {
+ "name": "blank-before-scope-end",
+ "output": "\n\n\nParis\n\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ }
+ },
+ {
+ "name": "second-call-crlf",
+ "output": "\n\n\nParis\n\n\n\n\r\n\r\n\r\nRome\r\n\r\n\r\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": "second-call-no-nl",
+ "output": "\n\n\nParis\n\n\n\nRome",
+ "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": "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-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": "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": "plain",
+ "output": "Hello there.",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "Hello there.",
+ "tool_calls": []
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "Hello there.",
+ "tool_calls": []
+ }
+ },
+ {
+ "name": "forced-plain-call",
+ "output": "Plan\n\n\n\nParis\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "Plan\n",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"Paris\"}"
+ }
+ ]
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "Plan\n",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"Paris\"}"
+ }
+ ]
+ }
+ },
+ {
+ "name": "forced-think-call",
+ "output": "Plan\n\n\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": "forced-think-text",
+ "output": "Plan\n\n\nAnswer.",
+ "upstream": {
+ "content": "Answer.",
+ "reasoning_content": "Plan",
+ "tool_calls": []
+ },
+ "upstream_partial": {
+ "content": "Answer.",
+ "reasoning_content": "Plan",
+ "tool_calls": []
+ }
+ },
+ {
+ "name": "call-no-think-end",
+ "output": "Let me plan.\n\n\n\nParis\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "Let me plan.\n",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"Paris\"}"
+ }
+ ]
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "Let me plan.\n",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"Paris\"}"
+ }
+ ]
+ }
+ }
+ ]
+ },
+ {
+ "template": "test/fixtures/llama_cpp_templates/NVIDIA-Nemotron-3-Nano-30B-A3B-BF16.jinja",
+ "enable_thinking": true,
+ "parallel_tool_calls": false,
+ "cases": [
+ {
+ "name": "req-then-opt",
+ "output": "\n\n\nUTC\n\n\n3\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_time",
+ "arguments": "{\"tz\":\"UTC\",\"days\":3}"
+ }
+ ]
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_time",
+ "arguments": "{\"tz\":\"UTC\",\"days\":3}"
+ }
+ ]
+ }
+ },
+ {
+ "name": "opt-before-req",
+ "output": "\n\n\n3\n\n\nUTC\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ }
+ },
+ {
+ "name": "opt-before-req-then-call",
+ "output": "\n\n\n3\n\n\nUTC\n\n\n\n\n\n\nParis\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ }
+ },
+ {
+ "name": "call-then-opt-before-req",
+ "output": "\n\n\nParis\n\n\n\n\n\n\n3\n\n\nUTC\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": "opt-only",
+ "output": "\n\n\n3\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ }
+ },
+ {
+ "name": "opt-dup",
+ "output": "\n\n\nUTC\n\n\n3\n\n\n4\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_time",
+ "arguments": "{\"tz\":\"UTC\",\"days\":3,\"days\":4}"
+ }
+ ]
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_time",
+ "arguments": "{\"tz\":\"UTC\",\"days\":3,\"days\":4}"
+ }
+ ]
+ }
+ },
+ {
+ "name": "inline-param-end",
+ "output": "\n\n\nA B\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"A B\"}"
+ }
+ ]
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"A B\"}"
+ }
+ ]
+ }
+ },
+ {
+ "name": "inline-param-end-tail",
+ "output": "\n\n\nA B\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"A B\"}"
+ }
+ ]
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"A B\"}"
+ }
+ ]
+ }
+ },
+ {
+ "name": "inline-param-end-nl-before",
+ "output": "\n\n\nA\n B\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"A\\n B\"}"
+ }
+ ]
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"A\\n B\"}"
+ }
+ ]
+ }
+ },
+ {
+ "name": "inline-param-end-at-end",
+ "output": "\n\n\nA \n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"A \"}"
+ }
+ ]
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"A \"}"
+ }
+ ]
+ }
+ },
+ {
+ "name": "inline-param-end-then-opt",
+ "output": "\n\n\nU TC\n\n\n3\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_time",
+ "arguments": "{\"tz\":\"U TC\",\"days\":3}"
+ }
+ ]
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_time",
+ "arguments": "{\"tz\":\"U TC\",\"days\":3}"
+ }
+ ]
+ }
+ },
+ {
+ "name": "value-fn-end",
+ "output": "\n\n\nA B\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"A B\"}"
+ }
+ ]
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"A B\"}"
+ }
+ ]
+ }
+ },
+ {
+ "name": "value-lt",
+ "output": "\n\n\na < b\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"a < b\"}"
+ }
+ ]
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"a < b\"}"
+ }
+ ]
+ }
+ },
+ {
+ "name": "value-param-open",
+ "output": "\n\n\n\nx\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"\\nx\"}"
+ }
+ ]
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"\\nx\"}"
+ }
+ ]
+ }
+ },
+ {
+ "name": "value-spaces",
+ "output": "\n\n\n Paris \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": "value-blank-lines",
+ "output": "\n\n\n\nParis\n\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"\\nParis\\n\"}"
+ }
+ ]
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"\\nParis\\n\"}"
+ }
+ ]
+ }
+ },
+ {
+ "name": "int-spaces",
+ "output": "\n\n\nUTC\n\n\n 3 \n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ }
+ },
+ {
+ "name": "int-no-nl",
+ "output": "\n\n\nUTC\n\n3\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ }
+ },
+ {
+ "name": "int-inline-end",
+ "output": "\n\n\nUTC\n\n\n3 \n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ }
+ },
+ {
+ "name": "crlf",
+ "output": "\r\n\r\n\r\nParis\r\n\r\n\r\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ }
+ },
+ {
+ "name": "crlf-text",
+ "output": "Hi.\r\n\r\n\r\n\r\nParis\r\n\r\n\r\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "Hi.\r\n",
+ "tool_calls": []
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "Hi.\r\n",
+ "tool_calls": []
+ }
+ },
+ {
+ "name": "no-nl-all",
+ "output": "Paris",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ }
+ },
+ {
+ "name": "no-nl-after-scope",
+ "output": "\n\nParis\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ }
+ },
+ {
+ "name": "no-nl-after-fn",
+ "output": "\n\nParis\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ }
+ },
+ {
+ "name": "no-nl-after-param-open",
+ "output": "\n\nParis\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ }
+ },
+ {
+ "name": "no-nl-after-fn-end",
+ "output": "\n\n\nParis\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ }
+ },
+ {
+ "name": "no-nl-value-both",
+ "output": "\n\nParis\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ }
+ },
+ {
+ "name": "space-after-scope",
+ "output": " \n\n\nParis\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ }
+ },
+ {
+ "name": "blank-after-scope",
+ "output": "\n\n\n\nParis\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ }
+ },
+ {
+ "name": "blank-after-fn",
+ "output": "\n\n\n\nParis\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ }
+ },
+ {
+ "name": "blank-after-param-end",
+ "output": "\n\n\nParis\n\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ }
+ },
+ {
+ "name": "space-before-fn-end",
+ "output": "\n\n\nParis\n\n \n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ }
+ },
+ {
+ "name": "blank-before-scope-end",
+ "output": "\n\n\nParis\n\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ }
+ },
+ {
+ "name": "second-call-crlf",
+ "output": "\n\n\nParis\n\n\n\n\r\n\r\n\r\nRome\r\n\r\n\r\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": "second-call-no-nl",
+ "output": "\n\n\nParis\n\n\n\nRome",
+ "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": "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-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": "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": "plain",
+ "output": "Hello there.",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "Hello there.",
+ "tool_calls": []
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "Hello there.",
+ "tool_calls": []
+ }
+ },
+ {
+ "name": "forced-plain-call",
+ "output": "Plan\n\n\n\nParis\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "Plan\n",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"Paris\"}"
+ }
+ ]
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "Plan\n",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"Paris\"}"
+ }
+ ]
+ }
+ },
+ {
+ "name": "forced-think-call",
+ "output": "Plan\n\n\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": "forced-think-text",
+ "output": "Plan\n\n\nAnswer.",
+ "upstream": {
+ "content": "Answer.",
+ "reasoning_content": "Plan",
+ "tool_calls": []
+ },
+ "upstream_partial": {
+ "content": "Answer.",
+ "reasoning_content": "Plan",
+ "tool_calls": []
+ }
+ },
+ {
+ "name": "call-no-think-end",
+ "output": "Let me plan.\n\n\n\nParis\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "Let me plan.\n",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"Paris\"}"
+ }
+ ]
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "Let me plan.\n",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"Paris\"}"
+ }
+ ]
+ }
+ }
+ ]
+ },
+ {
+ "template": "test/fixtures/llama_cpp_templates/NVIDIA-Nemotron-3-Nano-30B-A3B-BF16.jinja",
+ "enable_thinking": true,
+ "parallel_tool_calls": true,
+ "tool_choice": "required",
+ "cases": [
+ {
+ "name": "req-then-opt",
+ "output": "\n\n\nUTC\n\n\n3\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_time",
+ "arguments": "{\"tz\":\"UTC\",\"days\":3}"
+ }
+ ]
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_time",
+ "arguments": "{\"tz\":\"UTC\",\"days\":3}"
+ }
+ ]
+ }
+ },
+ {
+ "name": "call-then-opt-before-req",
+ "output": "\n\n\nParis\n\n\n\n\n\n\n3\n\n\nUTC\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": "opt-dup",
+ "output": "\n\n\nUTC\n\n\n3\n\n\n4\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_time",
+ "arguments": "{\"tz\":\"UTC\",\"days\":3,\"days\":4}"
+ }
+ ]
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_time",
+ "arguments": "{\"tz\":\"UTC\",\"days\":3,\"days\":4}"
+ }
+ ]
+ }
+ },
+ {
+ "name": "inline-param-end",
+ "output": "\n\n\nA B\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"A B\"}"
+ }
+ ]
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"A B\"}"
+ }
+ ]
+ }
+ },
+ {
+ "name": "inline-param-end-tail",
+ "output": "\n\n\nA B\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"A B\"}"
+ }
+ ]
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"A B\"}"
+ }
+ ]
+ }
+ },
+ {
+ "name": "inline-param-end-nl-before",
+ "output": "\n\n\nA\n B\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"A\\n B\"}"
+ }
+ ]
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"A\\n B\"}"
+ }
+ ]
+ }
+ },
+ {
+ "name": "inline-param-end-at-end",
+ "output": "\n\n\nA \n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"A \"}"
+ }
+ ]
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"A \"}"
+ }
+ ]
+ }
+ },
+ {
+ "name": "inline-param-end-then-opt",
+ "output": "\n\n\nU TC\n\n\n3\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_time",
+ "arguments": "{\"tz\":\"U TC\",\"days\":3}"
+ }
+ ]
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_time",
+ "arguments": "{\"tz\":\"U TC\",\"days\":3}"
+ }
+ ]
+ }
+ },
+ {
+ "name": "value-fn-end",
+ "output": "\n\n\nA B\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"A B\"}"
+ }
+ ]
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"A B\"}"
+ }
+ ]
+ }
+ },
+ {
+ "name": "value-lt",
+ "output": "\n\n\na < b\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"a < b\"}"
+ }
+ ]
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"a < b\"}"
+ }
+ ]
+ }
+ },
+ {
+ "name": "value-param-open",
+ "output": "\n\n\n\nx\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"\\nx\"}"
+ }
+ ]
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"\\nx\"}"
+ }
+ ]
+ }
+ },
+ {
+ "name": "value-spaces",
+ "output": "\n\n\n Paris \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": "value-blank-lines",
+ "output": "\n\n\n\nParis\n\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"\\nParis\\n\"}"
+ }
+ ]
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"\\nParis\\n\"}"
+ }
+ ]
+ }
+ },
+ {
+ "name": "second-call-crlf",
+ "output": "\n\n\nParis\n\n\n\n\r\n\r\n\r\nRome\r\n\r\n\r\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": "second-call-no-nl",
+ "output": "\n\n\nParis\n\n\n\nRome",
+ "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": "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-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": "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": "plain",
+ "output": "Hello there.",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "Hello there.",
+ "tool_calls": []
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "Hello there.",
+ "tool_calls": []
+ }
+ },
+ {
+ "name": "forced-plain-call",
+ "output": "Plan\n\n\n\nParis\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "Plan\n",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"Paris\"}"
+ }
+ ]
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "Plan\n",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"Paris\"}"
+ }
+ ]
+ }
+ },
+ {
+ "name": "forced-think-call",
+ "output": "Plan\n\n\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": "forced-think-text",
+ "output": "Plan\n\n\nAnswer.",
+ "upstream": {
+ "content": "Answer.",
+ "reasoning_content": "Plan",
+ "tool_calls": []
+ },
+ "upstream_partial": {
+ "content": "Answer.",
+ "reasoning_content": "Plan",
+ "tool_calls": []
+ }
+ },
+ {
+ "name": "call-no-think-end",
+ "output": "Let me plan.\n\n\n\nParis\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "Let me plan.\n",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"Paris\"}"
+ }
+ ]
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "Let me plan.\n",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"Paris\"}"
+ }
+ ]
+ }
+ }
+ ]
+ },
+ {
+ "template": "test/fixtures/llama_cpp_templates/NVIDIA-Nemotron-3-Nano-30B-A3B-BF16.jinja",
+ "enable_thinking": false,
+ "parallel_tool_calls": false,
+ "cases": [
+ {
+ "name": "req-then-opt",
+ "output": "\n\n\nUTC\n\n\n3\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_time",
+ "arguments": "{\"tz\":\"UTC\",\"days\":3}"
+ }
+ ]
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_time",
+ "arguments": "{\"tz\":\"UTC\",\"days\":3}"
+ }
+ ]
+ }
+ },
+ {
+ "name": "opt-before-req",
+ "output": "\n\n\n3\n\n\nUTC\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ }
+ },
+ {
+ "name": "opt-before-req-then-call",
+ "output": "\n\n\n3\n\n\nUTC\n\n\n\n\n\n\nParis\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ }
+ },
+ {
+ "name": "call-then-opt-before-req",
+ "output": "\n\n\nParis\n\n\n\n\n\n\n3\n\n\nUTC\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": "opt-only",
+ "output": "\n\n\n3\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ }
+ },
+ {
+ "name": "opt-dup",
+ "output": "\n\n\nUTC\n\n\n3\n\n\n4\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_time",
+ "arguments": "{\"tz\":\"UTC\",\"days\":3,\"days\":4}"
+ }
+ ]
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_time",
+ "arguments": "{\"tz\":\"UTC\",\"days\":3,\"days\":4}"
+ }
+ ]
+ }
+ },
+ {
+ "name": "inline-param-end",
+ "output": "\n\n\nA B\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"A B\"}"
+ }
+ ]
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"A B\"}"
+ }
+ ]
+ }
+ },
+ {
+ "name": "inline-param-end-tail",
+ "output": "\n\n\nA B\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"A B\"}"
+ }
+ ]
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"A B\"}"
+ }
+ ]
+ }
+ },
+ {
+ "name": "inline-param-end-nl-before",
+ "output": "\n\n\nA\n B\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"A\\n B\"}"
+ }
+ ]
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"A\\n B\"}"
+ }
+ ]
+ }
+ },
+ {
+ "name": "inline-param-end-at-end",
+ "output": "\n\n\nA \n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"A \"}"
+ }
+ ]
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"A \"}"
+ }
+ ]
+ }
+ },
+ {
+ "name": "inline-param-end-then-opt",
+ "output": "\n\n\nU TC\n\n\n3\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_time",
+ "arguments": "{\"tz\":\"U TC\",\"days\":3}"
+ }
+ ]
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_time",
+ "arguments": "{\"tz\":\"U TC\",\"days\":3}"
+ }
+ ]
+ }
+ },
+ {
+ "name": "value-fn-end",
+ "output": "\n\n\nA B\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"A B\"}"
+ }
+ ]
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"A B\"}"
+ }
+ ]
+ }
+ },
+ {
+ "name": "value-lt",
+ "output": "\n\n\na < b\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"a < b\"}"
+ }
+ ]
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"a < b\"}"
+ }
+ ]
+ }
+ },
+ {
+ "name": "value-param-open",
+ "output": "\n\n\n\nx\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"\\nx\"}"
+ }
+ ]
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"\\nx\"}"
+ }
+ ]
+ }
+ },
+ {
+ "name": "value-spaces",
+ "output": "\n\n\n Paris \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": "value-blank-lines",
+ "output": "\n\n\n\nParis\n\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"\\nParis\\n\"}"
+ }
+ ]
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"\\nParis\\n\"}"
+ }
+ ]
+ }
+ },
+ {
+ "name": "int-spaces",
+ "output": "\n\n\nUTC\n\n\n 3 \n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ }
+ },
+ {
+ "name": "int-no-nl",
+ "output": "\n\n\nUTC\n\n3\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ }
+ },
+ {
+ "name": "int-inline-end",
+ "output": "\n\n\nUTC\n\n\n3 \n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ }
+ },
+ {
+ "name": "crlf",
+ "output": "\r\n\r\n\r\nParis\r\n\r\n\r\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ }
+ },
+ {
+ "name": "crlf-text",
+ "output": "Hi.\r\n\r\n\r\n\r\nParis\r\n\r\n\r\n",
+ "upstream": {
+ "content": "Hi.\r",
+ "reasoning_content": "",
+ "tool_calls": []
+ },
+ "upstream_partial": {
+ "content": "Hi.\r",
+ "reasoning_content": "",
+ "tool_calls": []
+ }
+ },
+ {
+ "name": "no-nl-all",
+ "output": "Paris",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ }
+ },
+ {
+ "name": "no-nl-after-scope",
+ "output": "\n\nParis\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ }
+ },
+ {
+ "name": "no-nl-after-fn",
+ "output": "\n\nParis\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ }
+ },
+ {
+ "name": "no-nl-after-param-open",
+ "output": "\n\nParis\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ }
+ },
+ {
+ "name": "no-nl-after-fn-end",
+ "output": "\n\n\nParis\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ }
+ },
+ {
+ "name": "no-nl-value-both",
+ "output": "\n\nParis\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ }
+ },
+ {
+ "name": "space-after-scope",
+ "output": " \n\n\nParis\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ }
+ },
+ {
+ "name": "blank-after-scope",
+ "output": "\n\n\n\nParis\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ }
+ },
+ {
+ "name": "blank-after-fn",
+ "output": "\n\n\n\nParis\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ }
+ },
+ {
+ "name": "blank-after-param-end",
+ "output": "\n\n\nParis\n\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ }
+ },
+ {
+ "name": "space-before-fn-end",
+ "output": "\n\n\nParis\n\n \n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ }
+ },
+ {
+ "name": "blank-before-scope-end",
+ "output": "\n\n\nParis\n\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": []
+ }
+ },
+ {
+ "name": "second-call-crlf",
+ "output": "\n\n\nParis\n\n\n\n\r\n\r\n\r\nRome\r\n\r\n\r\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": "second-call-no-nl",
+ "output": "\n\n\nParis\n\n\n\nRome",
+ "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": "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-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": "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": "plain",
+ "output": "Hello there.",
+ "upstream": {
+ "content": "Hello there.",
+ "reasoning_content": "",
+ "tool_calls": []
+ },
+ "upstream_partial": {
+ "content": "Hello there.",
+ "reasoning_content": "",
+ "tool_calls": []
+ }
+ },
+ {
+ "name": "forced-plain-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": "forced-think-call",
+ "output": "Plan\n\n\n\n\n\nParis\n\n\n",
+ "upstream": {
+ "content": "Plan\n",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"Paris\"}"
+ }
+ ]
+ },
+ "upstream_partial": {
+ "content": "Plan\n",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"Paris\"}"
+ }
+ ]
+ }
+ },
+ {
+ "name": "forced-think-text",
+ "output": "Plan\n\n\nAnswer.",
+ "upstream": {
+ "content": "Plan\n\n\nAnswer.",
+ "reasoning_content": "",
+ "tool_calls": []
+ },
+ "upstream_partial": {
+ "content": "Plan\n\n\nAnswer.",
+ "reasoning_content": "",
+ "tool_calls": []
+ }
+ },
+ {
+ "name": "call-no-think-end",
+ "output": "Let me plan.\n\n\n\nParis\n\n\n",
+ "upstream": {
+ "content": "Let me plan.",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"Paris\"}"
+ }
+ ]
+ },
+ "upstream_partial": {
+ "content": "Let me plan.",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"Paris\"}"
+ }
+ ]
+ }
+ }
+ ]
+ },
+ {
+ "template": "test/fixtures/llama_cpp_templates/NVIDIA-Nemotron-3-Nano-30B-A3B-BF16.jinja",
+ "enable_thinking": false,
+ "parallel_tool_calls": false,
+ "tool_choice": "required",
+ "cases": [
+ {
+ "name": "req-then-opt",
+ "output": "\n\n\nUTC\n\n\n3\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_time",
+ "arguments": "{\"tz\":\"UTC\",\"days\":3}"
+ }
+ ]
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_time",
+ "arguments": "{\"tz\":\"UTC\",\"days\":3}"
+ }
+ ]
+ }
+ },
+ {
+ "name": "call-then-opt-before-req",
+ "output": "\n\n\nParis\n\n\n\n\n\n\n3\n\n\nUTC\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": "opt-dup",
+ "output": "\n\n\nUTC\n\n\n3\n\n\n4\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_time",
+ "arguments": "{\"tz\":\"UTC\",\"days\":3,\"days\":4}"
+ }
+ ]
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_time",
+ "arguments": "{\"tz\":\"UTC\",\"days\":3,\"days\":4}"
+ }
+ ]
+ }
+ },
+ {
+ "name": "inline-param-end",
+ "output": "\n\n\nA B\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"A B\"}"
+ }
+ ]
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"A B\"}"
+ }
+ ]
+ }
+ },
+ {
+ "name": "inline-param-end-tail",
+ "output": "\n\n\nA B\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"A B\"}"
+ }
+ ]
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"A B\"}"
+ }
+ ]
+ }
+ },
+ {
+ "name": "inline-param-end-nl-before",
+ "output": "\n\n\nA\n B\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"A\\n B\"}"
+ }
+ ]
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"A\\n B\"}"
+ }
+ ]
+ }
+ },
+ {
+ "name": "inline-param-end-at-end",
+ "output": "\n\n\nA \n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"A \"}"
+ }
+ ]
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"A \"}"
+ }
+ ]
+ }
+ },
+ {
+ "name": "inline-param-end-then-opt",
+ "output": "\n\n\nU TC\n\n\n3\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_time",
+ "arguments": "{\"tz\":\"U TC\",\"days\":3}"
+ }
+ ]
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_time",
+ "arguments": "{\"tz\":\"U TC\",\"days\":3}"
+ }
+ ]
+ }
+ },
+ {
+ "name": "value-fn-end",
+ "output": "\n\n\nA B\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"A B\"}"
+ }
+ ]
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"A B\"}"
+ }
+ ]
+ }
+ },
+ {
+ "name": "value-lt",
+ "output": "\n\n\na < b\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"a < b\"}"
+ }
+ ]
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"a < b\"}"
+ }
+ ]
+ }
+ },
+ {
+ "name": "value-param-open",
+ "output": "\n\n\n\nx\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"\\nx\"}"
+ }
+ ]
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"\\nx\"}"
+ }
+ ]
+ }
+ },
+ {
+ "name": "value-spaces",
+ "output": "\n\n\n Paris \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": "value-blank-lines",
+ "output": "\n\n\n\nParis\n\n\n\n",
+ "upstream": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"\\nParis\\n\"}"
+ }
+ ]
+ },
+ "upstream_partial": {
+ "content": "",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"\\nParis\\n\"}"
+ }
+ ]
+ }
+ },
+ {
+ "name": "second-call-crlf",
+ "output": "\n\n\nParis\n\n\n\n\r\n\r\n\r\nRome\r\n\r\n\r\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": "second-call-no-nl",
+ "output": "\n\n\nParis\n\n\n\nRome",
+ "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": "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-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": "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": "plain",
+ "output": "Hello there.",
+ "upstream": {
+ "content": "Hello there.",
+ "reasoning_content": "",
+ "tool_calls": []
+ },
+ "upstream_partial": {
+ "content": "Hello there.",
+ "reasoning_content": "",
+ "tool_calls": []
+ }
+ },
+ {
+ "name": "forced-plain-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": "forced-think-call",
+ "output": "Plan\n\n\n\n\n\nParis\n\n\n",
+ "upstream": {
+ "content": "Plan\n",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"Paris\"}"
+ }
+ ]
+ },
+ "upstream_partial": {
+ "content": "Plan\n",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"Paris\"}"
+ }
+ ]
+ }
+ },
+ {
+ "name": "forced-think-text",
+ "output": "Plan\n\n\nAnswer.",
+ "upstream": {
+ "content": "Plan\n\n\nAnswer.",
+ "reasoning_content": "",
+ "tool_calls": []
+ },
+ "upstream_partial": {
+ "content": "Plan\n\n\nAnswer.",
+ "reasoning_content": "",
+ "tool_calls": []
+ }
+ },
+ {
+ "name": "call-no-think-end",
+ "output": "Let me plan.\n\n\n\nParis\n\n\n",
+ "upstream": {
+ "content": "Let me plan.",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"Paris\"}"
+ }
+ ]
+ },
+ "upstream_partial": {
+ "content": "Let me plan.",
+ "reasoning_content": "",
+ "tool_calls": [
+ {
+ "name": "get_weather",
+ "arguments": "{\"location\":\"Paris\"}"
+ }
+ ]
+ }
+ }
+ ]
+ }
+ ]
+}
diff --git a/test/fixtures/qwen3_coder_call_body_upstream.md b/test/fixtures/qwen3_coder_call_body_upstream.md
new file mode 100644
index 000000000..3d0512277
--- /dev/null
+++ b/test/fixtures/qwen3_coder_call_body_upstream.md
@@ -0,0 +1,24 @@
+# Qwen3-Coder XML call-body upstream parses
+
+`qwen3_coder_call_body_upstream.json` records how llama.cpp parses the body of
+a Qwen3-Coder XML call, for issue #1898: the line breaks between its tags, the
+order of required and optional arguments, and string values that hold tags or
+whitespace. The templates are the vendored Qwen3-Coder, Qwen3.5 0.8B,
+StepFun3.5-Flash and Nemotron-3-Nano templates; llama.cpp parses all four with
+its Qwen3-Coder parser.
+
+The probe is the one `qwen3_coder_xml_upstream.md` describes, at the same
+llama.cpp commit, with the two tools in `tools`: `get_weather` with a required
+string `location`, and `get_time` with a required string `tz` and an optional
+integer `days`. Each entry sets its `enable_thinking`, `parallel_tool_calls`
+and, when not auto, `tool_choice`. Feeding the whole output first gave the
+same result. `upstream_partial` is `common_chat_peg_parse` with `is_partial`.
+
+Left out:
+
+- With `tool_choice` required, a reply whose only call is invalid: llama.cpp
+ fails the whole reply with an error, and llamadart returns the content and
+ no call.
+- A value that ends without the line breaks around ``, as in
+ `Paris`: llama.cpp returns a call whose JSON arguments never
+ end, and llamadart drops the call.
diff --git a/test/fixtures/qwen3_coder_xml_upstream.md b/test/fixtures/qwen3_coder_xml_upstream.md
index 961335f60..717795bc1 100644
--- a/test/fixtures/qwen3_coder_xml_upstream.md
+++ b/test/fixtures/qwen3_coder_xml_upstream.md
@@ -29,16 +29,14 @@ Left out:
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.
- The `bare-call`, `text-then-bare-call` and `bare-call-then-call` cases with
Qwen3-Coder and tool choice auto: llamadart takes such a call only for a
required call, so the tag and what follows it stay content.
- The `bare-call` and `text-then-bare-call` cases with StepFun3.5-Flash and
thinking off: llama.cpp keeps the thought its prompt opened, so a reply with
no thinking tag or `` is reasoning, while llamadart closed the
- thought and returns content.
+ thought and returns content. This is deliberate (maintainer decision on
+ #1898).
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
diff --git a/test/integration/core/engine/qwen3_coder_call_body_upstream_test.dart b/test/integration/core/engine/qwen3_coder_call_body_upstream_test.dart
new file mode 100644
index 000000000..fe505b10b
--- /dev/null
+++ b/test/integration/core/engine/qwen3_coder_call_body_upstream_test.dart
@@ -0,0 +1,185 @@
+@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/inference/tool_choice.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_call_body_upstream.json',
+ ).readAsStringSync(),
+ )
+ as Map;
+
+final List _tools = [
+ ToolDefinition(
+ name: 'get_weather',
+ description: 'w',
+ parameters: [ToolParam.string('location', required: true)],
+ ),
+ ToolDefinition(
+ name: 'get_time',
+ description: 't',
+ parameters: [
+ ToolParam.string('tz', required: true),
+ ToolParam.integer('days'),
+ ],
+ ),
+];
+
+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 B'), true, true),
+ (_time([('tz', 'UTC')]), true, true),
+ (_time([('tz', 'UTC'), ('days', '3')]), true, true),
+ (_time([('days', '3'), ('tz', 'UTC')]), false, false),
+ (_time([('tz', 'UTC'), ('days', '3'), ('days', '4')]), true, true),
+ (_time([('tz', 'UTC'), ('tz', 'X')]), false, false),
+ (_time([('days', '3')]), false, false),
+ (_time([('tz', 'UTC'), ('days', ' 3')]), false, false),
+ (_time([('tz', 'UTC'), ('days', '3 ')]), false, false),
+ (_time([('tz', 'UTC'), ('days', '-1')]), true, true),
+ (_time([('tz', 'UTC'), ('days', '03')]), false, false),
+ (_time([('tz', 'UTC'), ('days', '3.5')]), false, false),
+ (_time([('tz', 'UTC'), ('days', 'abc')]), false, false),
+ (_time([('tz', 'UTC'), ('days', '"3"')]), false, false),
+ (_weather('Paris').replaceAll('\n', '\r\n'), false, false),
+ (_weather('Paris').replaceAll('\n', ''), false, false),
+ (_weather('Paris').replaceFirst('>\n', '>'), false, false),
+ (_weather('Paris').replaceFirst('>\n', '> \n'), false, false),
+ (_weather('Paris').replaceFirst('>\n', '>\n\n'), false, false),
+ (
+ _weather('Paris').replaceFirst('\n', '\n\n'),
+ false,
+ false,
+ ),
+ (
+ _weather('Paris').replaceFirst('\n', ''),
+ false,
+ false,
+ ),
+ (
+ _weather('Paris').replaceFirst('\n', '\n\n'),
+ false,
+ false,
+ ),
+ (_weather('Paris').replaceFirst('>\nParis', '>Paris'), false, false),
+ (_weather('Paris').replaceFirst('Paris\n<', 'Paris<'), false, false),
+ (_call('nope', [('location', 'Paris')]), false, false),
+ (_call('get_weather', [('loc', 'Paris')]), false, false),
+ (_call('get_weather', []), false, false),
+ ('${_weather('Paris')}\n${_weather('Rome')}', false, true),
+ ('${_weather('Paris')}${_weather('Rome')}', false, true),
+ ('${_weather('Paris')}\n\n${_weather('Rome')}\n', false, true),
+ ('${_weather('Paris')} ${_weather('Rome')}', false, true),
+ ('${_weather('Paris')}\nDone.', false, false),
+ (
+ '${_weather('Paris')}\n${_weather('Rome').replaceAll('\n', '\r\n')}',
+ false,
+ false,
+ ),
+ (
+ '${_weather('Paris')}\n${_time([('days', '3'), ('tz', 'UTC')])}',
+ false,
+ false,
+ ),
+ (
+ '${_function('get_weather', [('location', 'Paris')])}',
+ false,
+ false,
+ ),
+ (_weather('Paris').substring(0, _weather('Paris').length - 3), false, false),
+];
+
+/// Replies of the `set_tags` tool, with whether llama.cpp's (`cd959bae9`)
+/// parallel-call grammar takes them, as `test-gbnf-validator` reported.
+final List<(String, bool)> _schemaReplies = [
+ (_tags([('tags', '["a","b"]')]), true),
+ (_tags([('tags', '[\n "a",\n "b"\n]')]), true),
+ (_tags([('tags', '["a" ]')]), true),
+ (_tags([('tags', '[ "a"]')]), true),
+ (_tags([('tags', '[]')]), true),
+ (_tags([('tags', '[\n]')]), true),
+ (_tags([('tags', ' ["a"]')]), false),
+ (_tags([('tags', '["a"] ')]), false),
+ (_tags([('tags', '["a"]\n')]), false),
+ (_tags([('tags', '"a"')]), false),
+ (_tags([('tags', '[1]')]), false),
+ (_tags([('tags', '[]'), ('opts', '{"k": "v"}')]), true),
+ (_tags([('tags', '[]'), ('opts', '{\n "k": "v"\n}')]), true),
+ (_tags([('tags', '[]'), ('opts', '{ }')]), true),
+ (_tags([('tags', '[]'), ('opts', '{"k": "v"} ')]), false),
+ (_tags([('tags', '[]'), ('opts', '{"k": 1}')]), false),
+ (_tags([('tags', '[]'), ('level', '1')]), true),
+ (_tags([('tags', '[]'), ('level', '2')]), true),
+ (_tags([('tags', '[]'), ('level', '3')]), false),
+ (_tags([('tags', '[]'), ('level', '"1"')]), false),
+ (_tags([('tags', '[]'), ('level', ' 1')]), false),
+ (_tags([('tags', '[]'), ('mode', 'a')]), true),
+ (_tags([('tags', '[]'), ('mode', '1')]), true),
+ (_tags([('tags', '[]'), ('mode', 'xyz')]), true),
+ (_tags([('tags', '[]'), ('mode', ' a ')]), true),
+ (_tags([('tags', '[]'), ('count', '3')]), true),
+ (_tags([('tags', '[]'), ('count', '3 ')]), false),
+ (_tags([('tags', '[]'), ('count', '[1, 2]')]), true),
+ (_tags([('tags', '[]'), ('count', '[1] ')]), false),
+ (_tags([('tags', '[]'), ('count', '[\n 1\n]')]), true),
+];
+
+void main() {
+ test('the call grammar takes the JSON values llama.cpp takes', () {
+ final grammar = GbnfRecognizer(
+ Qwen3CoderXmlHandler().buildGrammar([..._tools, _setTags])!,
+ );
+ for (final (output, accepted) in _schemaReplies) {
+ expect(grammar.accepts(output), accepted, reason: output);
+ }
+ });
+
+ for (final (:template, :enableThinking, bareFirstCall: _)
+ in qwen3CoderRequiredTemplates) {
+ for (final parallel in [false, true]) {
+ test('${template.split('/').last}, thinking $enableThinking, parallel '
+ '$parallel: the call grammar takes what llama.cpp takes', () {
+ final rendered = ChatTemplateEngine.render(
+ templateSource: File(template).readAsStringSync(),
+ messages: const [
+ LlamaChatMessage.fromText(
+ role: LlamaChatRole.user,
+ text: 'Weather in Paris?',
+ ),
+ ],
+ metadata: const {},
+ tools: _tools,
+ parallelToolCalls: parallel,
+ enableThinking: enableThinking,
+ );
+ expect(rendered.grammarLazy, isTrue);
+ expect(rendered.grammarTriggers.map((trigger) => trigger.value), [
+ '',
+ ]);
+ final grammar = GbnfRecognizer(rendered.grammar!);
+ for (final (output, single, parallelCalls) in _replies) {
+ expect(
+ grammar.accepts(output),
+ parallel ? parallelCalls : single,
+ reason: output,
+ );
+ }
+ });
+ }
+ }
+}
diff --git a/test/integration/core/template/qwen3_coder_required_grammar_test.dart b/test/integration/core/template/qwen3_coder_required_grammar_test.dart
index beb4bbf6f..8105bb3fd 100644
--- a/test/integration/core/template/qwen3_coder_required_grammar_test.dart
+++ b/test/integration/core/template/qwen3_coder_required_grammar_test.dart
@@ -31,7 +31,7 @@ void main() {
);
expect(rendered.grammarLazy, isTrue);
expect(rendered.grammarTriggers.map((trigger) => trigger.value), [
- '\n',
], reason: template);
final grammar = GbnfRecognizer(rendered.grammar!);
const bareCall =
@@ -75,27 +75,6 @@ void main() {
}
});
- test('Nemotron-3-Nano keeps its own required grammar', () {
- for (final enableThinking in [true, false]) {
- final rendered = renderQwen3CoderRequiredCall(
- 'test/fixtures/llama_cpp_templates/'
- 'NVIDIA-Nemotron-3-Nano-30B-A3B-BF16.jinja',
- enableThinking: enableThinking,
- parallelToolCalls: false,
- );
- expect(rendered.format, ChatFormat.pegConstructed.index);
- expect(rendered.grammarLazy, isFalse);
- expect(
- rendered.grammar,
- allOf(
- isNot(contains('text-before-calls')),
- isNot(contains('first-tool-call-scope')),
- ),
- reason: 'thinking $enableThinking',
- );
- }
- });
-
group('required tool-call grammar takes what llama.cpp takes', () {
for (final (:template, :enableThinking, :bareFirstCall)
in qwen3CoderRequiredTemplates) {
diff --git a/test/support/forced_open_required_calls.dart b/test/support/forced_open_required_calls.dart
index 160f70597..9ac814d2a 100644
--- a/test/support/forced_open_required_calls.dart
+++ b/test/support/forced_open_required_calls.dart
@@ -27,14 +27,6 @@ const forcedOpenRequiredCalls =
'plan<|END_THINKING|><|START_ACTION|>[{"tool_name": "get_weather", '
'"parameters": {"location": "Paris"}}]<|END_ACTION|>',
),
- (
- template: 'NVIDIA-Nemotron-3-Nano-30B-A3B-BF16.jinja',
- format: ChatFormat.pegConstructed,
- output:
- 'plan\n\n'
- '\nParis\n\n\n'
- '',
- ),
(
template: 'openbmb-MiniCPM5-1B.jinja',
format: ChatFormat.minicpm5,
diff --git a/test/support/peg_constructed_qwen_xml_parser.dart b/test/support/peg_constructed_qwen_xml_parser.dart
new file mode 100644
index 000000000..bc40081e8
--- /dev/null
+++ b/test/support/peg_constructed_qwen_xml_parser.dart
@@ -0,0 +1,77 @@
+import 'package:llamadart/src/core/models/tools/tool_definition.dart';
+import 'package:llamadart/src/core/template/peg_parser_builder.dart';
+import 'package:llamadart/src/core/template/tool_schema_utils.dart';
+
+/// A `pegConstructed` parser for one Qwen3-Coder XML call to [tools], after a
+/// thought the prompt opened when [thinkingForcedOpen], as llamadart built
+/// one for Nemotron-3-Nano before it took llama.cpp's Qwen3-Coder parser.
+///
+/// No handler emits such a parser now, but a template result may carry one.
+String pegConstructedQwenXmlParser(
+ List tools, {
+ required bool thinkingForcedOpen,
+}) {
+ final p = ChatPegConstructedBuilder();
+ final reasoning = thinkingForcedOpen
+ ? p.reasoning(p.until('')) + (p.literal('') | p.end())
+ : p.eps();
+
+ PegParser toolChoice = p.choice([]);
+ for (final tool in tools) {
+ final schema = tool.toJsonSchema();
+ final requiredNames = schemaRequired(schema);
+ PegParser args = p.eps();
+ for (final MapEntry(key: name, value: property) in schemaProperties(
+ schema,
+ ).entries) {
+ final ruleName = 'tool-${tool.name}-arg-$name';
+ final value = schemaResolvesToString(property)
+ ? p.toolArgStringValue(
+ p.untilOneOf([
+ '\n',
+ '\n',
+ ]),
+ ) +
+ p.literal('\n')
+ : p.toolArgJsonValue(
+ p.schema(p.json(), '$ruleName-schema', property),
+ );
+ final argument = p.rule(
+ ruleName,
+ p.toolArgOpen(
+ p.literal('\n'),
+ ) +
+ value +
+ p.optional(p.toolArgClose(p.literal('\n'))),
+ );
+ args += p.repeat(argument, requiredNames.contains(name) ? 1 : 0, 1);
+ }
+ toolChoice |= p.rule(
+ 'tool-${tool.name}',
+ p.toolOpen(
+ p.literal('\n'),
+ ) +
+ args +
+ p.toolClose(p.literal('\n')),
+ );
+ }
+
+ final toolCall = p.rule(
+ 'tool-call',
+ p.literal('\n') +
+ toolChoice +
+ p.literal('') +
+ p.space(),
+ );
+ p.setRoot(
+ reasoning +
+ p.content(p.until('')) +
+ p.triggerRule('tool-call-root', p.repeat(toolCall, 0, 1)),
+ );
+ return p.save();
+}
diff --git a/test/support/qwen3_coder_required_calls.dart b/test/support/qwen3_coder_required_calls.dart
index fcfb6fd05..27a8e5984 100644
--- a/test/support/qwen3_coder_required_calls.dart
+++ b/test/support/qwen3_coder_required_calls.dart
@@ -45,6 +45,20 @@ const qwen3CoderRequiredTemplates =
enableThinking: false,
bareFirstCall: false,
),
+ (
+ template:
+ 'test/fixtures/llama_cpp_templates/'
+ 'NVIDIA-Nemotron-3-Nano-30B-A3B-BF16.jinja',
+ enableThinking: true,
+ bareFirstCall: false,
+ ),
+ (
+ template:
+ 'test/fixtures/llama_cpp_templates/'
+ 'NVIDIA-Nemotron-3-Nano-30B-A3B-BF16.jinja',
+ enableThinking: false,
+ bareFirstCall: false,
+ ),
];
/// Renders [template] for a required [qwen3CoderRequiredTool] call.
diff --git a/test/unit/core/engine/chat_completion_stream_parser_test.dart b/test/unit/core/engine/chat_completion_stream_parser_test.dart
index 125fa91a8..4452dc3b2 100644
--- a/test/unit/core/engine/chat_completion_stream_parser_test.dart
+++ b/test/unit/core/engine/chat_completion_stream_parser_test.dart
@@ -18,12 +18,13 @@ import 'package:llamadart/src/core/template/chat_format.dart';
import 'package:llamadart/src/core/template/chat_template_engine.dart';
import 'package:llamadart/src/core/template/chat_template_handler.dart';
import 'package:llamadart/src/core/template/handlers/ministral_handler.dart';
-import 'package:llamadart/src/core/template/handlers/qwen3_coder_xml_handler.dart';
import 'package:llamadart/src/core/template/handlers/solar_open_handler.dart';
import 'package:llamadart/src/core/template/template_internal_metadata.dart';
import 'package:llamadart/src/core/template/thinking_utils.dart';
import 'package:test/test.dart';
+import '../../../support/peg_constructed_qwen_xml_parser.dart';
+
void main() {
group('ChatCompletionStreamParser', () {
for (final valid in [true, false]) {
@@ -2388,21 +2389,14 @@ void main() {
.parser!;
}
- const nemotronV3Template =
- '{% set truncate_history_thinking = true %}'
- ''
- '';
-
- test('Qwen3-Coder XML with a Nemotron V3 parser', () async {
+ test('Qwen3-Coder XML with a PEG-constructed parser', () async {
for (final format in const [
ChatFormat.qwen3CoderXml,
ChatFormat.pegConstructed,
]) {
- final withoutThinking = parser(
- Qwen3CoderXmlHandler(),
- templateSource: nemotronV3Template,
- enableThinking: false,
- );
+ final withoutThinking = pegConstructedQwenXmlParser([
+ _weatherTool,
+ ], thinkingForcedOpen: false);
for (final output in outputs(format, qwenXmlCall).take(6)) {
await _expectStreamMatchesParse(
format,
@@ -2415,10 +2409,9 @@ void main() {
format,
'Plan.\n\nLet me check.\n$qwenXmlCall',
forcedOpen: true,
- parser: parser(
- Qwen3CoderXmlHandler(),
- templateSource: '$nemotronV3Template\n',
- ),
+ parser: pegConstructedQwenXmlParser([
+ _weatherTool,
+ ], thinkingForcedOpen: true),
openings: const ['', ''],
);
}
@@ -2426,11 +2419,9 @@ void main() {
test('a PEG parse with tools and a closed thought streams its call, '
'not the envelope', () async {
- final withoutThinking = parser(
- Qwen3CoderXmlHandler(),
- templateSource: nemotronV3Template,
- enableThinking: false,
- );
+ final withoutThinking = pegConstructedQwenXmlParser([
+ _weatherTool,
+ ], thinkingForcedOpen: false);
for (final output in [
'Let me check.\n$qwenXmlCall',
' \n Let me check.\n$qwenXmlCall',
@@ -3073,11 +3064,6 @@ void main() {
.parser!;
}
- const nemotronV3Template =
- '{% set truncate_history_thinking = true %}'
- ''
- '';
-
test('the DeepSeek R1 chunk from #754', () async {
final chunks = await ChatCompletionStreamParser.parse(
tokenStream: Stream.value('\nPlan.\n\n\nSure.'),
@@ -3351,15 +3337,12 @@ void main() {
'keeps leading whitespace a PEG parse keeps without tools',
() async {
final ministral = pegParser(MinistralHandler());
- final qwen = pegParser(
- Qwen3CoderXmlHandler(),
- templateSource: nemotronV3Template,
- enableThinking: false,
- );
- final qwenThinking = pegParser(
- Qwen3CoderXmlHandler(),
- templateSource: '$nemotronV3Template\n',
- );
+ final qwen = pegConstructedQwenXmlParser([
+ _weatherTool,
+ ], thinkingForcedOpen: false);
+ final qwenThinking = pegConstructedQwenXmlParser([
+ _weatherTool,
+ ], thinkingForcedOpen: true);
for (final (format, parser, forced) in [
(ChatFormat.ministral, ministral, false),
(ChatFormat.pegNative, ministral, false),
diff --git a/test/unit/core/template/chat_template_engine_test.dart b/test/unit/core/template/chat_template_engine_test.dart
index 882324bb0..36d226019 100644
--- a/test/unit/core/template/chat_template_engine_test.dart
+++ b/test/unit/core/template/chat_template_engine_test.dart
@@ -1724,157 +1724,48 @@ void main() {
expect(maxCallsFromParser(requiredSingle.parser!), equals(1));
});
- test('routes Nemotron v3 templates to PEG-constructed parser path', () {
+ // llama.cpp (`cd959bae9`) parses Nemotron-3-Nano with its Qwen3-Coder
+ // parser, where `` also ends a forced-open thought.
+ test('routes Nemotron v3 templates to the Qwen3-Coder XML parser', () {
const template =
- '{% set truncate_history_thinking = true %}'
- ''
- '';
-
- final result = ChatTemplateEngine.render(
- templateSource: template,
- messages: grammarMessages,
- metadata: const {},
- tools: tools,
- toolChoice: ToolChoice.auto,
- );
-
- expect(result.format, equals(ChatFormat.pegConstructed.index));
- expect(result.parser, isNotNull);
- expect(result.parser, isNotEmpty);
- expect(result.grammarTriggers, hasLength(1));
- expect(result.grammarTriggers.first.value, equals(''));
-
- final parsed = ChatTemplateEngine.parse(
- result.format,
- 'I am thinking\n'
- '\n'
- '\n'
- '\n'
- '\n'
- 'Seoul\n'
- '\n'
- '\n'
- '',
- parser: result.parser,
- thinkingForcedOpen: result.thinkingForcedOpen,
- );
-
- expect(parsed.reasoningContent, equals('I am thinking'));
- expect(parsed.toolCalls, hasLength(1));
- expect(parsed.toolCalls.first.function?.name, equals('get_weather'));
- expect(
- parsed.toolCalls.first.function?.arguments,
- equals('{"city":"Seoul"}'),
- );
- });
-
- test('Nemotron v3 tool_choice none uses content-only parser behavior', () {
- const template =
- '{% set truncate_history_thinking = true %}'
- ''
- '';
-
- final result = ChatTemplateEngine.render(
- templateSource: template,
- messages: grammarMessages,
- metadata: const {},
- tools: tools,
- toolChoice: ToolChoice.none,
- );
-
- expect(result.format, equals(ChatFormat.pegConstructed.index));
- expect(result.parser, isNotNull);
- expect(result.parser, isNotEmpty);
- expect(result.grammar, isNull);
- expect(result.grammarLazy, isFalse);
- expect(result.grammarTriggers, isEmpty);
-
- final parsed = ChatTemplateEngine.parse(
- result.format,
- 'I am thinking\n'
- '\n'
- '\n'
- '\n'
- '\n'
- 'Seoul\n'
- '\n'
- '\n'
- '',
- parser: result.parser,
- thinkingForcedOpen: result.thinkingForcedOpen,
- );
-
- expect(parsed.reasoningContent, equals('I am thinking'));
- expect(parsed.toolCalls, isEmpty);
- expect(parsed.content, contains(''));
- expect(parsed.content, contains(''));
- });
-
- test('Nemotron v3 parser respects required/parallel tool call bounds', () {
- const template =
- '{% set truncate_history_thinking = true %}'
- ''
- '';
- const templateParallel =
'{% set truncate_history_thinking = true %}'
''
''
- '{% if tools %}{% for tool in tools %}'
- '{{ tool["function"]["name"] }}'
- '{% endfor %}{% endif %}';
+ '{% if add_generation_prompt %}\n{% endif %}';
- int maxCallsFromParser(String parser) {
- final decoded = jsonDecode(parser) as Map;
- final parsers = (decoded['parsers'] as List)
- .cast>();
- final toolCallRoot = parsers.firstWhere(
- (node) => node['type'] == 'rule' && node['name'] == 'tool-call-root',
+ for (final toolChoice in [ToolChoice.auto, ToolChoice.required]) {
+ final result = ChatTemplateEngine.render(
+ templateSource: template,
+ messages: grammarMessages,
+ metadata: const {},
+ tools: tools,
+ toolChoice: toolChoice,
);
- final repetition = parsers[(toolCallRoot['child'] as num).toInt()];
- return (repetition['max_count'] as num).toInt();
- }
- int minCallsFromParser(String parser) {
- final decoded = jsonDecode(parser) as Map;
- final parsers = (decoded['parsers'] as List)
- .cast>();
- final toolCallRoot = parsers.firstWhere(
- (node) => node['type'] == 'rule' && node['name'] == 'tool-call-root',
+ expect(result.format, equals(ChatFormat.qwen3CoderXml.index));
+ expect(result.parser, isNull);
+ expect(result.thinkingForcedOpen, isTrue);
+ final parsed = ChatTemplateEngine.parseRendered(
+ result,
+ 'I am thinking\n'
+ '\n'
+ '\n'
+ '\n'
+ 'Seoul\n'
+ '\n'
+ '\n'
+ '',
+ tools: tools,
);
- final repetition = parsers[(toolCallRoot['child'] as num).toInt()];
- return (repetition['min_count'] as num).toInt();
- }
-
- final autoSingle = ChatTemplateEngine.render(
- templateSource: template,
- messages: grammarMessages,
- metadata: const {},
- tools: tools,
- toolChoice: ToolChoice.auto,
- );
- expect(minCallsFromParser(autoSingle.parser!), equals(0));
- expect(maxCallsFromParser(autoSingle.parser!), equals(1));
-
- final autoParallel = ChatTemplateEngine.render(
- templateSource: templateParallel,
- messages: grammarMessages,
- metadata: const {},
- tools: tools,
- toolChoice: ToolChoice.auto,
- parallelToolCalls: true,
- );
- expect(minCallsFromParser(autoParallel.parser!), equals(0));
- expect(maxCallsFromParser(autoParallel.parser!), equals(-1));
- final requiredSingle = ChatTemplateEngine.render(
- templateSource: template,
- messages: grammarMessages,
- metadata: const {},
- tools: tools,
- toolChoice: ToolChoice.required,
- );
- expect(minCallsFromParser(requiredSingle.parser!), equals(1));
- expect(maxCallsFromParser(requiredSingle.parser!), equals(1));
+ expect(parsed.reasoningContent, equals('I am thinking'));
+ expect(parsed.toolCalls, hasLength(1));
+ expect(parsed.toolCalls.first.function?.name, equals('get_weather'));
+ expect(
+ parsed.toolCalls.first.function?.arguments,
+ equals('{"city":"Seoul"}'),
+ );
+ }
});
test('keeps Ministral handler but strips grammar for tool_choice none', () {
diff --git a/test/unit/core/template/handlers/qwen3_coder_xml_handler_test.dart b/test/unit/core/template/handlers/qwen3_coder_xml_handler_test.dart
index 26ca45507..02bd82d60 100644
--- a/test/unit/core/template/handlers/qwen3_coder_xml_handler_test.dart
+++ b/test/unit/core/template/handlers/qwen3_coder_xml_handler_test.dart
@@ -5,12 +5,18 @@ import 'package:llamadart/src/core/models/chat/chat_role.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:llamadart/src/core/template/handlers/qwen3_coder_xml_handler.dart';
import 'package:llamadart/src/core/template/template_internal_metadata.dart';
import 'package:test/test.dart';
+import '../../../../support/gbnf_recognizer.dart';
+
void main() {
+ _requiredArgumentOrderTests();
+ _stringOrIntegerValueTests();
+
test('Qwen3CoderXmlHandler parses qwen XML tool calls', () {
final handler = Qwen3CoderXmlHandler();
final tools = [
@@ -51,6 +57,34 @@ void main() {
expect(noTool.content, equals('plain'));
});
+ // llama.cpp (`cd959bae9`) holds back the start of a `` a
+ // partial reply may still complete, and keeps it once the reply ends.
+ test('a partial reply holds back the start of a tool-call scope', () {
+ final handler = Qwen3CoderXmlHandler();
+ final tools = [
+ ToolDefinition(
+ name: 'get_weather',
+ description: 'Get weather',
+ parameters: [ToolParam.string('city', required: true)],
+ handler: _noop,
+ ),
+ ];
+ for (final (output, partial) in [
+ ('See '));
+ expect(rendered.parser, isNull);
+ expect(rendered.grammarTriggers.map((trigger) => trigger.value), [
+ '',
+ ]);
expect(rendered.preservedTokens, contains(''));
expect(rendered.preservedTokens, contains(''));
- final parsed = ChatTemplateEngine.parse(
- rendered.format,
+ ChatParseResult parse(String output) =>
+ ChatTemplateEngine.parseRendered(rendered, output, tools: tools);
+ const code =
+ 'def hello():\n'
+ ' print("Hello, world!")\n'
+ '\n'
+ 'hello()';
+ final parsed = parse(
'I am thinking\n'
'\n'
'\n'
'\n'
'\n'
- 'def hello():\n'
- ' print("Hello, world!")\n'
- '\n'
- 'hello()\n'
+ '$code\n'
+ '\n'
'\n'
'',
- parser: rendered.parser,
- thinkingForcedOpen: rendered.thinkingForcedOpen,
);
-
expect(parsed.reasoningContent, equals('I am thinking'));
expect(parsed.toolCalls, hasLength(1));
expect(parsed.toolCalls.first.function?.name, equals('python'));
expect(
- parsed.toolCalls.first.function?.arguments,
- equals(
- '{"code":"def hello():\\n print(\\"Hello, world!\\")\\n\\nhello()"}',
- ),
+ jsonDecode(parsed.toolCalls.first.function!.arguments!),
+ equals({'code': code}),
);
- });
-
- test(
- 'Nemotron v3 parser supports missing parameter close and parallel calls',
- () {
- final handler = Qwen3CoderXmlHandler();
- final tools = [
- ToolDefinition(
- name: 'python',
- description: 'Run Python',
- parameters: [ToolParam.string('code', required: true)],
- handler: _noop,
- ),
- ToolDefinition(
- name: 'get_weather',
- description: 'Get weather',
- parameters: [ToolParam.string('city', required: true)],
- handler: _noop,
- ),
- ];
-
- final rendered = handler.render(
- templateSource:
- '{% set truncate_history_thinking = true %}'
- ''
- '',
- messages: const [
- LlamaChatMessage.fromText(role: LlamaChatRole.user, text: 'hello'),
- ],
- metadata: const {internalParallelToolCallsMetadataKey: 'true'},
- tools: tools,
- enableThinking: true,
- );
-
- final parsed = ChatTemplateEngine.parse(
- rendered.format,
- 'plan\n'
- '\n'
- '\n'
- '\n'
- '\n'
- 'print("hi")\n'
- '\n'
- '\n'
- '\n'
- '\n'
- '\n'
- 'Seoul\n'
- '\n'
- '\n'
- '',
- parser: rendered.parser,
- thinkingForcedOpen: rendered.thinkingForcedOpen,
- );
- expect(parsed.reasoningContent, equals('plan'));
- expect(parsed.toolCalls, hasLength(2));
- expect(parsed.toolCalls[0].function?.name, equals('python'));
- expect(
- parsed.toolCalls[0].function?.arguments,
- equals('{"code":"print(\\"hi\\")"}'),
- );
- expect(parsed.toolCalls[1].function?.name, equals('get_weather'));
- expect(
- parsed.toolCalls[1].function?.arguments,
- equals('{"city":"Seoul"}'),
- );
- },
- );
+ // llama.cpp returns a call without `` with unterminated JSON
+ // arguments.
+ expect(
+ parse(
+ 'plan\n\n\n\n\n'
+ 'print("hi")\n\n',
+ ).toolCalls,
+ isEmpty,
+ );
+ });
test('Qwen3/Nemotron preserved tokens are retained without tools', () {
final handler = Qwen3CoderXmlHandler();
@@ -218,9 +195,8 @@ void main() {
);
expect(nemotron.preservedTokens, contains(''));
expect(nemotron.preservedTokens, contains(''));
- expect(nemotron.format, equals(ChatFormat.pegConstructed.index));
- expect(nemotron.parser, isNotNull);
- expect(nemotron.parser, isNotEmpty);
+ expect(nemotron.format, equals(ChatFormat.qwen3CoderXml.index));
+ expect(nemotron.parser, isNull);
});
test('Qwen3.6 renders its thinking control without Nemotron parsing', () {
@@ -304,8 +280,8 @@ void main() {
return rootOf(rendered.grammar!);
}
- const single = 'root ::= tool-call-scope';
- const repeated = 'root ::= tool-call-scope+';
+ const single = 'root ::= tool-call';
+ const repeated = 'root ::= tool-call tool-call*';
const parallelOff = {internalParallelToolCallsMetadataKey: 'false'};
const parallelOn = {internalParallelToolCallsMetadataKey: 'true'};
expect(rootFor(nemotronTemplate, const {}), equals(single));
@@ -318,6 +294,95 @@ void main() {
});
}
+// llama.cpp (`cd959bae9`) reads a value that may be a string as JSON only
+// when it is a JSON value of another type the schema allows.
+void _stringOrIntegerValueTests() {
+ test('a string-or-integer value is JSON only as an integer', () {
+ final tools = [
+ ToolDefinition.fromJsonSchema(
+ name: 'f',
+ description: 'f',
+ schema: {
+ 'type': 'object',
+ 'properties': {
+ 'v': {
+ 'type': ['string', 'integer'],
+ },
+ },
+ 'required': ['v'],
+ },
+ ),
+ ];
+ for (final (raw, value) in [
+ ('"Paris"', '"Paris"'),
+ ('3', 3),
+ ('Paris', 'Paris'),
+ ('[1]', '[1]'),
+ ('true', 'true'),
+ ('null', 'null'),
+ (' 3', ' 3'),
+ ]) {
+ final parsed = Qwen3CoderXmlHandler().parseWithTools(
+ '\n\n\n$raw\n\n'
+ '\n',
+ tools: tools,
+ );
+ expect(jsonDecode(parsed.toolCalls.single.function!.arguments!), {
+ 'v': value,
+ }, reason: raw);
+ }
+ });
+}
+
+// llama.cpp (`cd959bae9`) takes up to six required arguments in any order,
+// and more only in declaration order, in its parser and its grammar. A
+// repeated required argument drops the call.
+void _requiredArgumentOrderTests() {
+ ToolDefinition requiredStrings(String name, int count) => ToolDefinition(
+ name: name,
+ description: name,
+ parameters: [
+ for (var i = 0; i < count; i++) ToolParam.string('p$i', required: true),
+ ],
+ handler: _noop,
+ );
+ String call(String name, List order) =>
+ '\n\n'
+ '${order.map((i) => '\nv$i\n\n').join()}'
+ '\n';
+ final tools = [requiredStrings('two', 2), requiredStrings('seven', 7)];
+
+ test('required arguments come in any order up to six of them', () {
+ final rendered = Qwen3CoderXmlHandler().render(
+ templateSource: '{{ messages[0]["content"] }}',
+ messages: const [
+ LlamaChatMessage.fromText(role: LlamaChatRole.user, text: 'hello'),
+ ],
+ metadata: const {},
+ tools: tools,
+ );
+ final grammar = GbnfRecognizer(rendered.grammar!);
+ for (final (output, valid) in [
+ (call('two', [1, 0]), true),
+ (call('two', [0, 1]), true),
+ (call('two', [0, 0, 1]), false),
+ (call('two', [0, 1, 0]), false),
+ (call('two', [1, 0, 0]), false),
+ (call('seven', [0, 1, 2, 3, 4, 5, 6]), true),
+ (call('seven', [1, 0, 2, 3, 4, 5, 6]), false),
+ (call('seven', [6, 5, 4, 3, 2, 1, 0]), false),
+ ]) {
+ final parsed = ChatTemplateEngine.parseRendered(
+ rendered,
+ output,
+ tools: tools,
+ );
+ expect(parsed.toolCalls, hasLength(valid ? 1 : 0), reason: output);
+ expect(grammar.accepts(output), valid, reason: output);
+ }
+ });
+}
+
Future\n`, untrimmed, and
+any other is JSON with no whitespace around it. Nemotron-3-Nano parses the
+same way. For a required call with a template
without a thought, as Qwen3-Coder's, a declared tool's ``
before any `` also ends the content and starts the first call, as
llama.cpp (`cd959bae9`) allows. Otherwise that tag is text, in the parse, the
@@ -307,8 +315,8 @@ parses return a forced-open thought that never closes as reasoning, including
any tool-call envelope inside it, as llama.cpp (`620d2225c`) does with the
QwQ, MiniMax-M2 and DeepSeek V3.1 templates.
-Output parsed with a PEG parser (Ministral, Solar Open, Nemotron V3, or
-Qwen3-Coder XML given a parser) streams the content and reasoning of partial
+Output parsed with a PEG parser (Ministral, Solar Open, or Qwen3-Coder XML
+given a parser) streams the content and reasoning of partial
PEG parses when tool calls are parsed. Those parses hold back a possible
opening themselves. A Ministral thought cut off by the token limit therefore
streams as reasoning, although the final parse returns it, with its `[THINK]`
diff --git a/website/docs/guides/tool-calling.md b/website/docs/guides/tool-calling.md
index c7f25b5c5..b6412efdd 100644
--- a/website/docs/guides/tool-calling.md
+++ b/website/docs/guides/tool-calling.md
@@ -489,7 +489,11 @@ When a Hermes template forces reasoning open (such as QwQ), the
`ToolChoice.required` grammar accepts reasoning closed by `` before the
calls, for schema and `ToolParam` tools.
-With Qwen3-Coder XML templates (Qwen3-Coder, Qwen3.5, StepFun3.5-Flash), the
+With Qwen3-Coder XML templates (Qwen3-Coder, Qwen3.5, StepFun3.5-Flash,
+Nemotron 3 Nano), a call counts, as in llama-server, only with a line break
+after each tag and around each value, and with its required arguments before
+its optional ones; a string value is kept as generated, up to the first
+`\n\n`. The tool-call grammar enforces the same shape. The
`ToolChoice.required` grammar accepts a thought and any text without
`` before the calls, as in llama-server, so leave room in
`maxTokens`: a reply that spends it first ends with `length` and no call. The