{ "add_prefix_space": false, "audio_bos_token": "<|audio_start|>", "audio_eos_token": "<|audio_end|>", "audio_token": "<|audio_pad|>", "backend": "tokenizers", "bos_token": null, "clean_up_tokenization_spaces": false, "eos_token": "<|im_end|>", "errors": "replace", "image_token": "<|image_pad|>", "is_local": true, "local_files_only": false, "model_max_length": 262144, "model_specific_special_tokens": { "audio_bos_token": "<|audio_start|>", "audio_eos_token": "<|audio_end|>", "audio_token": "<|audio_pad|>", "image_token": "<|image_pad|>", "video_token": "<|video_pad|>", "vision_bos_token": "<|vision_start|>", "vision_eos_token": "<|vision_end|>" }, "pad_token": "<|endoftext|>", "padding_side": "left", "pretokenize_regex": "(?i:'s|'t|'re|'ve|'m|'ll|'d)|[^\\r\\n\\p{L}\\p{N}]?[\\p{L}\\p{M}]+|\\p{N}| ?[^\\s\\p{L}\\p{M}\\p{N}]+[\\r\\n]*|\\s*[\\r\\n]+|\\s+(?!\\S)|\\s+", "processor_class": "Qwen3VLProcessor", "split_special_tokens": false, "tokenizer_class": "TokenizersBackend", "unk_token": null, "video_token": "<|video_pad|>", "vision_bos_token": "<|vision_start|>", "vision_eos_token": "<|vision_end|>", "added_tokens_decoder": { "248044": { "content": "<|endoftext|>", "single_word": false, "lstrip": false, "rstrip": false, "normalized": false, "special": true }, "248045": { "content": "<|im_start|>", "single_word": false, "lstrip": false, "rstrip": false, "normalized": false, "special": true }, "248046": { "content": "<|im_end|>", "single_word": false, "lstrip": false, "rstrip": false, "normalized": false, "special": true }, "248047": { "content": "<|object_ref_start|>", "single_word": false, "lstrip": false, "rstrip": false, "normalized": false, "special": true }, "248048": { "content": "<|object_ref_end|>", "single_word": false, "lstrip": false, "rstrip": false, "normalized": false, "special": true }, "248049": { "content": "<|box_start|>", "single_word": false, "lstrip": false, "rstrip": false, "normalized": false, "special": true }, "248050": { "content": "<|box_end|>", "single_word": false, "lstrip": false, "rstrip": false, "normalized": false, "special": true }, "248051": { "content": "<|quad_start|>", "single_word": false, "lstrip": false, "rstrip": false, "normalized": false, "special": true }, "248052": { "content": "<|quad_end|>", "single_word": false, "lstrip": false, "rstrip": false, "normalized": false, "special": true }, "248053": { "content": "<|vision_start|>", "single_word": false, "lstrip": false, "rstrip": false, "normalized": false, "special": true }, "248054": { "content": "<|vision_end|>", "single_word": false, "lstrip": false, "rstrip": false, "normalized": false, "special": true }, "248055": { "content": "<|vision_pad|>", "single_word": false, "lstrip": false, "rstrip": false, "normalized": false, "special": true }, "248056": { "content": "<|image_pad|>", "single_word": false, "lstrip": false, "rstrip": false, "normalized": false, "special": true }, "248057": { "content": "<|video_pad|>", "single_word": false, "lstrip": false, "rstrip": false, "normalized": false, "special": true }, "248058": { "content": "", "single_word": false, "lstrip": false, "rstrip": false, "normalized": false, "special": false }, "248059": { "content": "", "single_word": false, "lstrip": false, "rstrip": false, "normalized": false, "special": false }, "248060": { "content": "<|fim_prefix|>", "single_word": false, "lstrip": false, "rstrip": false, "normalized": false, "special": false }, "248061": { "content": "<|fim_middle|>", "single_word": false, "lstrip": false, "rstrip": false, "normalized": false, "special": false }, "248062": { "content": "<|fim_suffix|>", "single_word": false, "lstrip": false, "rstrip": false, "normalized": false, "special": false }, "248063": { "content": "<|fim_pad|>", "single_word": false, "lstrip": false, "rstrip": false, "normalized": false, "special": false }, "248064": { "content": "<|repo_name|>", "single_word": false, "lstrip": false, "rstrip": false, "normalized": false, "special": false }, "248065": { "content": "<|file_sep|>", "single_word": false, "lstrip": false, "rstrip": false, "normalized": false, "special": false }, "248066": { "content": "", "single_word": false, "lstrip": false, "rstrip": false, "normalized": false, "special": false }, "248067": { "content": "", "single_word": false, "lstrip": false, "rstrip": false, "normalized": false, "special": false }, "248068": { "content": "", "single_word": false, "lstrip": false, "rstrip": false, "normalized": false, "special": false }, "248069": { "content": "", "single_word": false, "lstrip": false, "rstrip": false, "normalized": false, "special": false }, "248070": { "content": "<|audio_start|>", "single_word": false, "lstrip": false, "rstrip": false, "normalized": false, "special": true }, "248071": { "content": "<|audio_end|>", "single_word": false, "lstrip": false, "rstrip": false, "normalized": false, "special": true }, "248072": { "content": "", "single_word": false, "lstrip": false, "rstrip": false, "normalized": false, "special": true }, "248073": { "content": "", "single_word": false, "lstrip": false, "rstrip": false, "normalized": false, "special": true }, "248074": { "content": "", "single_word": false, "lstrip": false, "rstrip": false, "normalized": false, "special": true }, "248075": { "content": "", "single_word": false, "lstrip": false, "rstrip": false, "normalized": false, "special": true }, "248076": { "content": "<|audio_pad|>", "single_word": false, "lstrip": false, "rstrip": false, "normalized": false, "special": true } }, "chat_template": "{%- set template_version = template_version if template_version is defined else \"protium-v1.0.0-objective-gated\" %}\n\n{#- ========================================================================== -#}\n{#- PROTIUM-1.0 — OBJECTIVE-GATED COGNITIVE ARCHITECTURE -#}\n{#- Solstice-AI Zero-Waste Protocol for High-Efficiency Reasoning Models -#}\n{#- Named after Protium (1H): Zero Neutrons. Zero Dead Weight. Pure Thrust. -#}\n{#- Lineage: qwen3.8-froggeric-v22.5.0 (DavidAU, MIT) -> Solstice-AI -#}\n{#- -#}\n{#- CORE TENETS: -#}\n{#- 1. TOKEN 1 TARGET ANCHOR: Lock the termination condition at step 1. -#}\n{#- 2. FORWARD-ONLY SOLVE: Advance directly toward the target. Eliminate -#}\n{#- conversational filler (\"let's see\", \"hmm\", \"wait\"). No rhetorical -#}\n{#- hesitation; execute pure continuous deduction. -#}\n{#- 3. EARLY EXIT GATE: Terminate thinking the instant the target condition -#}\n{#- is satisfied and verified. Never dwell, stall, or manufacture doubt. -#}\n{#- 4. DELTA-ONLY CORRECTION: Fix only the broken variable upon contradiction;-#}\n{#- never regress into full restarts or circular overthinking loops. -#}\n{#- 5. ABSOLUTE RESOLVE: Decisive, unhedged final delivery. Zero preamble. -#}\n{#- -#}\n{#- THE SPECTRUM (governed purely by problem constraints & verification): -#}\n{#- [L0] Mortal - thinking off; execute directly. -#}\n{#- [L1] Hermes - rapid instinct; immediate verification pass. -#}\n{#- [L2] Apollo - disciplined deduction; linear constraint trace. -#}\n{#- [L3] Artemis - edge-case & boundary vulnerability audit. -#}\n{#- [L4] Athena - strategic synthesis; architectural trade-offs. -#}\n{#- [L5] Prometheus - defensive engineering; second-order failure modeling. -#}\n{#- [L6] Solstice - axiomatic derivation; multi-hypothesis stress testing. -#}\n{#- [L7] Hyperion - ground-up first-principles decomposition. -#}\n{#- [L8] Einstein - theoretical mastery; unified invariant reduction. -#}\n{#- [L9] Oracle - proof-grade formal authority; zero placeholders. -#}\n{#- [L10] Proteus - dynamic cognitive adaptation (Default); auto-calibrated -#}\n{#- impedance matching across all levels with early exit. -#}\n{#- swarm - 20-perspective divergent swarm, verdict line. -#}\n{#- council - adversarial research council, verdict line. -#}\n{#- -#}\n{#- CONTINUOUS DEPTH MAP (10-100): 1-14 L1 | 15-29 L2 | 30-44 L3 | 45-59 L4 | -#}\n{#- 60-69 L5 | 70-79 L6 | 80-89 L7 | 90-96 L8 | 97-100 L9 | 0 = off. -#}\n{#- -#}\n{#- INLINE SYNTAX (case-insensitive, stripped before model sees them): -#}\n{#- [L0]..[L9] | {REASON:level|name|number} | [MODE:level|name|number] -#}\n{#- [regular] | [vanilla] | [standard] | [default] -#}\n{#- Prefix 'i' = silent variant: {REASON:i8} runs L8 rigor, thinking hidden. -#}\n{#- PRECEDENCE: default L7 < runtime kwarg < inline signals (last wins). -#}\n{#- ========================================================================== -#}\n\n{#- ------------------------------------------------------------------ -#}\n{#- RUNTIME KWARGS -#}\n{#- ------------------------------------------------------------------ -#}\n{%- set _tool_format = tool_call_format if tool_call_format is defined else 'xml' %}\n{%- set image_count = namespace(value=0) %}\n{%- set video_count = namespace(value=0) %}\n{%- set add_vision_id = add_vision_id if add_vision_id is defined else false %}\n{%- set enable_thinking = enable_thinking if enable_thinking is defined else true %}\n{%- set auto_disable_thinking_with_tools = auto_disable_thinking_with_tools if auto_disable_thinking_with_tools is defined else false %}\n{%- if preserve_reasoning is defined and preserve_reasoning is not none %}\n {%- set _preserve_thinking = preserve_reasoning %}\n{%- elif preserve_thinking is defined and preserve_thinking is not none %}\n {%- set _preserve_thinking = preserve_thinking %}\n{%- else %}\n {%- set _preserve_thinking = true %}\n{%- endif %}\n{%- set max_tool_arg_chars = max_tool_arg_chars if max_tool_arg_chars is defined else 0 %}\n{%- set max_tool_response_chars = max_tool_response_chars if max_tool_response_chars is defined else 0 %}\n{%- set _has_tools = (tools is defined and tools and tools is iterable and tools is not mapping) %}\n{%- set _has_budget = (thinking_budget is defined and thinking_budget and (thinking_budget | int) > 0) or (max_thinking_tokens is defined and max_thinking_tokens and (max_thinking_tokens | int) > 0) %}\n{%- set _budget_val = (thinking_budget | int) if (thinking_budget is defined and thinking_budget and (thinking_budget | int) > 0) else ((max_thinking_tokens | int) if (max_thinking_tokens is defined and max_thinking_tokens) else 0) %}\n{%- set _terse_on = terse if terse is defined else (not is_explicit_regular) %}\n{%- set suppress_tool_instructions = suppress_tool_instructions if suppress_tool_instructions is defined else none %}\n\n{#- ================================================================== -#}\n{#- S3 PRIMITIVES — render & scan helpers (no cognitive content). -#}\n{#- ================================================================== -#}\n\n{#- Content renderer with vision support (render loop only). -#}\n{%- macro render_content(content, do_vision_count, is_system_content=false) %}\n {%- if content is string %}\n {{- content }}\n {%- elif content is iterable and content is not mapping %}\n {%- for item in content %}\n {%- if item is mapping %}\n {%- if item.type == 'image' or 'image' in item or 'image_url' in item %}\n {%- if is_system_content %}\n {{- raise_exception('System message cannot contain images.') }}\n {%- endif %}\n {%- if do_vision_count %}\n {%- set image_count.value = image_count.value + 1 %}\n {%- endif %}\n {%- if add_vision_id %}\n {{- 'Picture ' ~ image_count.value ~ ': ' }}\n {%- endif %}\n {{- '<|vision_start|><|image_pad|><|vision_end|>' }}\n {%- elif item.type == 'video' or 'video' in item or 'video_url' in item %}\n {%- if is_system_content %}\n {{- raise_exception('System message cannot contain videos.') }}\n {%- endif %}\n {%- if do_vision_count %}\n {%- set video_count.value = video_count.value + 1 %}\n {%- endif %}\n {%- if add_vision_id %}\n {{- 'Video ' ~ video_count.value ~ ': ' }}\n {%- endif %}\n {{- '<|vision_start|><|video_pad|><|vision_end|>' }}\n {%- elif 'text' in item %}\n {{- item.text }}\n {%- else %}\n {{- raise_exception('Unexpected item type in content.') }}\n {%- endif %}\n {%- else %}\n {{- item | string }}\n {%- endif %}\n {%- endfor %}\n {%- elif content is none or content is undefined %}\n {{- '' }}\n {%- else %}\n {{- raise_exception('Unexpected content type.') }}\n {%- endif %}\n{%- endmacro %}\n\n{#- Text-only scanner renderer: images/videos render as '' so the S1 scan -#}\n{#- pass never raises on multimodal messages (v2.x vision bug fixed). -#}\n{%- macro scan_text(content) %}\n {%- if content is string %}\n {{- content }}\n {%- elif content is iterable and content is not mapping %}\n {%- for item in content %}\n {%- if item is mapping and 'text' in item and item.text is string %}\n {{- item.text }}\n {%- elif item is string %}\n {{- item }}\n {%- endif %}\n {%- endfor %}\n {%- endif %}\n{%- endmacro %}\n\n{#- Strip every inline control tag from visible text. -#}\n{%- macro strip_control_tags(text) %}\n {%- set t = text %}\n {%- if '{REASON:' in t %}\n {%- set _raw = t.split('{REASON:')[1].split('}')[0] %}\n {%- set t = t.replace('{REASON:' ~ _raw ~ '}', '') %}\n {%- endif %}\n {%- if '[MODE:' in t %}\n {%- set _raw2 = t.split('[MODE:')[1].split(']')[0] %}\n {%- set t = t.replace('[MODE:' ~ _raw2 ~ ']', '') %}\n {%- endif %}\n {%- set t2 = t %}\n {%- set t3 = t2 | replace('<|think_on|>', '') | replace('<|think_off|>', '') | replace('<|think_minimal|>', '') | replace('<|think_low|>', '') | replace('<|think_medium|>', '') | replace('<|think_high|>', '') | replace('<|think_xhigh|>', '') | replace('<|think_ultracode|>', '') | replace('<|think_extreme|>', '') | replace('<|think_max|>', '') %}\n {#- NB: no for-loops here — Jinja set does not persist across loop -#}\n {#- iterations, so every strip must live in one chained expression. -#}\n {%- set out = t3 | replace('[regular]', '') | replace('[REGULAR]', '') | replace('[vanilla]', '') | replace('[standard]', '') | replace('[default]', '') | replace('[L10]', '') | replace('[l10]', '') | replace('[L0]', '') | replace('[l0]', '') | replace('[L1]', '') | replace('[l1]', '') | replace('[L2]', '') | replace('[l2]', '') | replace('[L3]', '') | replace('[l3]', '') | replace('[L4]', '') | replace('[l4]', '') | replace('[L5]', '') | replace('[l5]', '') | replace('[L6]', '') | replace('[l6]', '') | replace('[L7]', '') | replace('[l7]', '') | replace('[L8]', '') | replace('[l8]', '') | replace('[L9]', '') | replace('[l9]', '') %}\n {{- out }}\n{%- endmacro %}\n\n{#- Remove only a {REASON:...} / [MODE:...] tag (assistant history path). -#}\n{%- macro strip_mode_tag(text) %}\n {%- set t = text %}\n {%- if '{REASON:' in t %}\n {%- set _raw = t.split('{REASON:')[1].split('}')[0] %}\n {%- set t = t.replace('{REASON:' ~ _raw ~ '}', '') %}\n {%- elif '[MODE:' in t %}\n {%- set _raw = t.split('[MODE:')[1].split(']')[0] %}\n {%- set t = t.replace('[MODE:' ~ _raw ~ ']', '') %}\n {%- endif %}\n {{- t }}\n{%- endmacro %}\n\n{#- Tool output error classifier → 'error' | 'ok'. Shares ONE definition -#}\n{#- with the S1 failure pre-pass and the render-loop warning counter. -#}\n{%- macro classify_tool_output(content) %}\n {%- set _lower = content | lower %}\n {%- set _head = _lower[:120] %}\n {%- set _is_code_or_grep = ('throw new ' in _lower or 'throw error' in _lower or 'console.error' in _lower or 'logger.error' in _lower or 'logging.error' in _lower or 'import ' in _head or 'def ' in _head or 'function ' in _head) %}\n {%- set _exit_code_zero = ('exit code: 0' in _head or 'process exited with code 0' in _head) %}\n {%- set _error_field_ok = ('\"error\": null' in _head or '\"error\":null' in _head or '\"error\": false' in _head or '\"error\":false' in _head or '\"error\": \"\"' in _head or '\"error\":\"\"' in _head) %}\n {%- set _strong = (('\"error\":' in _head and not _error_field_ok) or '\"status\": \"error\"' in _head or '\"status\":\"error\"' in _head or 'traceback (most recent call last):' in _head or 'command not found' in _head or 'invalid syntax' in _head or 'fatal:' in _head or (('exit code: ' in _head or 'process exited with code' in _head) and not _exit_code_zero) or _head.startswith('exception:') or _head.startswith('failed to ')) %}\n {%- set _weak = ('error:' in _head or 'err!' in _head) %}\n {%- set _suppressed = ('$ ' in _head or 'took ' in _head or content | length >= 600) %}\n {%- if not _is_code_or_grep and (_strong or (_weak and not _suppressed)) %}\n {{- 'error' }}\n {%- else %}\n {{- 'ok' }}\n {%- endif %}\n{%- endmacro %}\n\n{#- ================================================================== -#}\n{#- S2 COGNITIVE PROFILES — pure text. Soft shares only; there are no -#}\n{#- token counts, word floors or ceilings anywhere in this section. -#}\n{#- ================================================================== -#}\n\n{%- set soft_budget_contract -%}\nPROTIUM OBJECTIVE-GATED REASONING CONTRACT:\n1. Target Anchor: At token 1, isolate the exact termination criteria — define what a completed, verified solution requires before executing.\n2. Forward-Only Solve: Advance directly along the deductive path. Systematically eliminate internal conversational monologues (\"let's see\", \"hmm\", \"wait\", \"now let me check\"). Discard rhetorical hesitation; execute continuous deductive steps.\n3. Anti-Pivot Invariant: Never emit reflexive hesitation pivots (\"Wait...\", \"On second thought...\", \"Hold on...\") unless a concrete mathematical, programmatic, or factual contradiction has been explicitly isolated. In the absence of an identified contradiction, maintain unbroken forward momentum.\n4. Active Disproof Gate: Never declare an answer complete on surface plausibility alone. Before unlocking exit, stress-test your candidate solution against the initial constraints and degenerate edge cases (nulls, zero, off-by-one, boundary limits, and trivial counterexamples).\n5. Objective Early Exit: The instant your solution withstands active constraint verification, terminate thinking immediately and deliver the final answer. Never pad, stall, or manufacture doubt once the proof holds.\n6. Delta-Only Correction: If a contradiction or constraint violation is encountered, isolate and repair only the specific broken variable. Never regress into circular overthinking loops or full restarts.\n7. Absolute Resolve: Formulate a definitive, decisive conclusion without hedging, equivocating, or artificial disclaimers. Correctness and crisp utility are the sole metrics.\n{%- endset %}\n\n{%- set terse_core -%}\nOperational Directives:\n- Zero preamble, pleasantries, or question restatements.\n- Deliver direct, unhedged answers with maximum information density.\n- Retain all essential mathematical, programmatic, and logical technical rigor.\n- If genuine ambiguity exists, resolve it along the most probable engineering standard or ask one targeted clarifying question.\n{%- endset %}\n\n{%- set inst_hermes -%}\nReasoning effort: Hermes — [L1] (rapid instinct).\nMindset: High-velocity execution. Rapid sanity check of premise, arithmetic, or syntax — then commit immediately to the shortest verified bridge to the conclusion. Conclude immediately once obvious.\n{%- endset %}\n{%- set inst_apollo -%}\nReasoning effort: Apollo — [L2] (disciplined deduction).\nMindset: Structured, transparent logic. Isolate given constraints, trace linear implications with zero detour, and exit thinking the instant premise validation is reached.\n{%- endset %}\n{%- set inst_artemis -%}\nReasoning effort: Artemis — [L3] (boundary & failure audit).\nMindset: Rigorous boundary validation. Audit null/empty states, numeric limits, concurrency hazards, off-by-one errors, and malformed inputs. Fortify against edge cases, then terminate thinking immediately.\n{%- endset %}\n{%- set inst_athena -%}\nReasoning effort: Athena — [L4] (strategic architecture).\nMindset: Modular synthesis. Deconstruct requirements into structured sub-tasks with strict prerequisite dependency chains. Weigh concrete trade-offs (performance vs maintainability, latency vs throughput) and execute the optimal vector.\n{%- endset %}\n{%- set inst_prometheus -%}\nReasoning effort: Prometheus — [L5] (defensive engineering).\nMindset: Second-order systemic modeling. Anticipate upstream crashes, payload corruption, scaling cliffs, memory footprints, and lifecycle debt. Embed fault tolerance and graceful degradation directly into the design.\n{%- endset %}\n{%- set inst_solstice -%}\nReasoning effort: Solstice — [L6] (deep systemic derivation).\nMindset: Axiomatic derivation. Establish fundamental invariants, formulate distinct candidate architectures, stress-test each against boundary constraints, and converge on the dominant derivation with zero assumptions taken on faith.\n{%- endset %}\n{%- set inst_hyperion -%}\nReasoning effort: Hyperion — [L7] (first-principles synthesis).\nMindset: Comprehensive first-principles synthesis. Decompose problems to atomic ground truths. Maintain continuous forward momentum across all proof surfaces. Immediate exit the instant resolution is achieved.\n{%- endset %}\n{%- set inst_einstein -%}\nReasoning effort: Einstein — [L8] (theoretical mastery).\nMindset: Invariant reduction and breakthrough synthesis. Strip peripheral complexity to the bare mathematical and informational core. Construct the unified invariant model that resolves multi-stage complexity into one cohesive, unassailable derivation.\n{%- endset %}\n{%- set inst_oracle -%}\nReasoning effort: Oracle — [L9] (proof-grade authority).\nMindset: Exhaustive formal verification. Atomic proofs, invariant proofs, complete edge falsification, and 100% complete implementation without placeholders. Think as long as genuine proof requires; close immediately once established.\n{%- endset %}\n{%- set inst_proteus -%}\nReasoning effort: Proteus — [L10] (autonomous freehand reasoning; default).\nMindset: Freehand cognitive autonomy. You are not bound by artificial tiers, rigid categories, or predetermined quotas. Freehand exactly the depth, structure, and rigor required by the problem's own constraints:\n- Autonomous Execution: Seamlessly weave whatever analytical techniques the solution demands—boundary audits, architectural trade-offs, defensive modeling, or axiomatic proofs—without categorizing yourself into rigid stages.\n- Unbroken Forward Momentum: Eliminate all self-conversational chatter (\"let's see\", \"hmm\", \"wait\"). Advance strictly through deductive steps.\n- Active Verification & Exit: Stress-test your derivation against initial boundary constraints; the millisecond the solution is verified and holds, terminate thinking immediately and deliver the final answer.\n{%- endset %}\n{%- set inst_swarm -%}\nReasoning effort: Swarm — 20-perspective divergent swarm (specialized mode).\nMindset: Four-phase convergent breakdown. Phase 1: Disassembly to core parameters. Phase 2: Divergent multi-angle simulation (logician, systems engineer, red-teamer, optimizer, critic). Phase 3: Cross-pollination and tension resolution. Phase 4: Convergence onto master deliverable.\nOutput contract: Conclude thinking and open final response with \"[SWARM VERDICT]\" followed by a decisive synthesis naming the winning vector and the primary objection survived.\n{%- endset %}\n{%- set inst_deep_swarm -%}\nReasoning effort: Council — adversarial research council (specialized mode).\nMindset: Five-protocol institutional deliberation. Protocol 1: Parameter calibration and success criteria. Protocol 2: Multi-specialist panel assembly. Protocol 3: Adversarial debate and stress-testing. Protocol 4: Trade-off scoring matrix. Protocol 5: Master architecture.\nOutput contract: Conclude thinking and open final response with \"[COUNCIL VERDICT]\" followed by the definitive ruling, key justification, and dissenting risk accounted for.\n{%- endset %}\n\n{#- ================================================================== -#}\n{#- S1 RESOLUTION CORE — one pass, one state, one resolver. -#}\n{#- ================================================================== -#}\n\n{#- Baseline: runtime kwarg (session default). thinking_level supported. -#}\n{%- set _kwarg_effort = '' %}\n\n{%- set reg_ns = namespace(active=false) %}\n{%- if (regular is defined and regular) or (mode is defined and mode in ('regular', 'vanilla', 'standard', 'default', 'clean')) %}\n {%- set reg_ns.active = true %}\n{%- endif %}\n{%- for msg in messages %}\n {%- if msg.content is string and ('[regular]' in msg.content or '[REGULAR]' in msg.content or '[vanilla]' in msg.content or '[standard]' in msg.content or '[default]' in msg.content) %}\n {%- set reg_ns.active = true %}\n {%- endif %}\n{%- endfor %}\n{%- set is_explicit_regular = reg_ns.active %}\n{%- if is_explicit_regular %}\n {%- set _kwarg_effort = 'regular' %}\n{%- endif %}\n{%- if reasoning_effort is defined and reasoning_effort is not none %}\n {%- set _kwarg_effort = reasoning_effort | string | lower | trim %}\n{%- elif thinking_level is defined and thinking_level is not none %}\n {%- set _kwarg_effort = thinking_level | string | lower | trim %}\n{%- endif %}\n{%- set _initial_thinking = enable_thinking %}\n{%- set _initial_effort = '10' %}\n{%- set _depth_explicit = false %}\n{%- if _kwarg_effort %}\n {%- set _depth_explicit = true %}\n {%- if _kwarg_effort in ('none', 'off', '0', 'mortal', 'disabled', 'regular', 'vanilla', 'standard', 'default', 'clean') %}\n {%- set _initial_thinking = false %}\n {%- else %}\n {%- set _initial_effort = _kwarg_effort %}\n {%- endif %}\n{%- endif %}\n{%- set ns_state = namespace(thinking=_initial_thinking, effort=_initial_effort, mode='level', silent_profile=false) %}\n{%- if auto_disable_thinking_with_tools and _has_tools %}\n {%- set ns_state.thinking = false %}\n{%- endif %}\n\n{#- Unified scan pass: collect mode tags, inline signals, cleaned messages. -#}\n{#- Later signals override earlier ones (mid-chat re-escalation works). -#}\n{%- set store = namespace(messages=[], raw_mode='', saw_inline=false) %}\n{%- if not messages %}\n {{- raise_exception('No messages provided.') }}\n{%- endif %}\n{%- for msg in messages %}\n {%- set _txt = scan_text(msg.content) | trim %}\n {%- set _role = msg.role %}\n {%- set _is_steering = (_role == 'system' or _role == 'developer' or _role == 'user') %}\n {%- set _tagged = ('{REASON:' in _txt) or ('[MODE:' in _txt) %}\n {%- set _low = _txt | lower %}\n {#- Does THIS message carry any inline signal? (multi-modal safe: text-only scan) -#}\n {#- NB: namespace probe, because plain set inside a for-loop does not -#}\n {#- propagate to the enclosing scope in Jinja2. -#}\n {%- set _hi = namespace(v=_tagged) %}\n {%- if _is_steering and '<|think_' in _low %}\n {%- set _hi.v = true %}\n {%- endif %}\n {%- if _is_steering and not _hi.v %}\n {%- for n in range(11) %}\n {%- if '[l' ~ n ~ ']' in _low %}\n {%- set _hi.v = true %}\n {%- endif %}\n {%- endfor %}\n {%- endif %}\n {%- set _has_inline = _hi.v %}\n {#- Inline think-tags + [L#] (steering roles only). Later messages win. -#}\n {%- if _is_steering %}\n {%- if '<|think_off|>' in _low %}\n {%- set ns_state.thinking = false %}\n {%- set store.saw_inline = true %}\n {%- elif '<|think_on|>' in _low %}\n {%- set ns_state.thinking = true %}\n {%- set store.saw_inline = true %}\n {%- elif '<|think_extreme|>' in _low or '<|think_max|>' in _low %}\n {%- set ns_state.thinking = true %}\n {%- set ns_state.effort = '9' %}\n {%- set ns_state.mode = 'level' %}\n {%- set store.saw_inline = true %}\n {%- elif '<|think_ultracode|>' in _low %}\n {%- set ns_state.thinking = true %}\n {%- set ns_state.effort = '8' %}\n {%- set ns_state.mode = 'level' %}\n {%- set store.saw_inline = true %}\n {%- elif '<|think_xhigh|>' in _low %}\n {%- set ns_state.thinking = true %}\n {%- set ns_state.effort = '7' %}\n {%- set ns_state.mode = 'level' %}\n {%- set store.saw_inline = true %}\n {%- elif '<|think_high|>' in _low %}\n {%- set ns_state.thinking = true %}\n {%- set ns_state.effort = '6' %}\n {%- set ns_state.mode = 'level' %}\n {%- set store.saw_inline = true %}\n {%- elif '<|think_medium|>' in _low %}\n {%- set ns_state.thinking = true %}\n {%- set ns_state.effort = '4' %}\n {%- set ns_state.mode = 'level' %}\n {%- set store.saw_inline = true %}\n {%- elif '<|think_low|>' in _low %}\n {%- set ns_state.thinking = true %}\n {%- set ns_state.effort = '2' %}\n {%- set ns_state.mode = 'level' %}\n {%- set store.saw_inline = true %}\n {%- elif '<|think_minimal|>' in _low %}\n {%- set ns_state.thinking = true %}\n {%- set ns_state.effort = '1' %}\n {%- set ns_state.mode = 'level' %}\n {%- set store.saw_inline = true %}\n {%- endif %}\n {%- if '[l10]' in _low %}\n {%- set ns_state.effort = '10' %}\n {%- set ns_state.mode = 'level' %}\n {%- set ns_state.thinking = true %}\n {%- set store.saw_inline = true %}\n {%- else %}\n {%- for n in range(10) %}\n {%- if '[l' ~ n ~ ']' in _low %}\n {%- set ns_state.effort = n | string %}\n {%- set ns_state.mode = 'level' %}\n {%- set store.saw_inline = true %}\n {%- if n == 0 %}\n {%- set ns_state.thinking = false %}\n {%- else %}\n {%- set ns_state.thinking = true %}\n {%- endif %}\n {%- endif %}\n {%- endfor %}\n {%- endif %}\n {%- endif %}\n {#- {REASON:...} / [MODE:...] extraction (any role). -#}\n {%- set _tagged = ('{REASON:' in _txt) or ('[MODE:' in _txt) %}\n {%- if _tagged %}\n {%- set _raw_reason = '' %}\n {%- if '{REASON:' in _txt %}\n {%- set _raw_reason = _txt.split('{REASON:')[1].split('}')[0] %}\n {%- elif '[MODE:' in _txt %}\n {%- set _raw_reason = _txt.split('[MODE:')[1].split(']')[0] %}\n {%- endif %}\n {%- if _raw_reason %}\n {%- set _mode_raw = _raw_reason | string | lower | trim %}\n {%- set store.raw_mode = _mode_raw %}\n {%- if _mode_raw.startswith('i') and _mode_raw | length > 1 %}\n {%- set ns_state.effort = _mode_raw[1:] %}\n {%- set ns_state.mode = 'level' %}\n {%- set ns_state.thinking = false %}\n {%- set ns_state.silent_profile = true %}\n {%- set store.saw_inline = true %}\n {%- else %}\n {%- set ns_state.effort = _mode_raw %}\n {%- set ns_state.mode = 'level' %}\n {%- set store.saw_inline = true %}\n {%- if _mode_raw in ('0', 'mortal', 'off', 'none', 'direct', 'chat', 'disabled', 'regular', 'vanilla', 'standard', 'default', 'clean') %}\n {%- set ns_state.thinking = false %}\n {%- else %}\n {%- set ns_state.thinking = true %}\n {%- endif %}\n {%- endif %}\n {%- endif %}\n {%- endif %}\n {#- Build cleaned message store. Messages WITHOUT inline signals pass -#}\n {#- through untouched, so multi-modal parts (images/videos) survive. -#}\n {%- if _tagged and _role == 'assistant' %}\n {%- set _clean = strip_mode_tag(_txt) | trim %}\n {%- set store.messages = store.messages + [{'role': _role, 'content': _clean, 'tool_calls': (msg.tool_calls if msg.tool_calls is defined else none), 'reasoning_content': (msg.reasoning_content if msg.reasoning_content is defined else none), 'thinking': (msg.thinking if msg.thinking is defined else none), 'reasoning': (msg.reasoning if msg.reasoning is defined else none)}] %}\n {%- elif _is_steering and _has_inline %}\n {#- Multi-modal aware strip: clean text items, keep image/video parts. -#}\n {%- if msg.content is string %}\n {%- set _clean = strip_control_tags(_txt) | trim %}\n {%- set store.messages = store.messages + [{'role': _role, 'content': _clean}] %}\n {%- elif msg.content is iterable and msg.content is not mapping %}\n {%- set _nc = namespace(items=[]) %}\n {%- for item in msg.content %}\n {%- if item is mapping and 'text' in item and item.text is string %}\n {%- set _nc.items = _nc.items + [{'type': 'text', 'text': strip_control_tags(item.text) | trim}] %}\n {%- else %}\n {%- set _nc.items = _nc.items + [item] %}\n {%- endif %}\n {%- endfor %}\n {%- set store.messages = store.messages + [{'role': _role, 'content': _nc.items}] %}\n {%- else %}\n {%- set store.messages = store.messages + [msg] %}\n {%- endif %}\n {%- else %}\n {%- set store.messages = store.messages + [msg] %}\n {%- endif %}\n{%- endfor %}\n{%- set messages = store.messages %}\n{%- set _depth_explicit = (_depth_explicit or store.saw_inline) %}\n\n{#- Continuous depth: pure integers 10-100 map onto the spectrum band. -#}\n{#- 0-9 stay legacy level numbers so old clients keep exact behaviour. -#}\n{#- NB: int-filter round-trip instead of .isdigit() — minja (llama.cpp) -#}\n{#- does not implement string.isdigit(). -#}\n{%- set _eff_int = ns_state.effort | int %}\n{%- if ns_state.mode == 'level' and ns_state.effort is string and (_eff_int | string) == ns_state.effort and _eff_int >= 11 %}\n {%- set _n = ns_state.effort | int %}\n {%- set ns_state.thinking = true %}\n {%- if _n <= 14 %}\n {%- set ns_state.effort = '1' %}\n {%- elif _n <= 29 %}\n {%- set ns_state.effort = '2' %}\n {%- elif _n <= 44 %}\n {%- set ns_state.effort = '3' %}\n {%- elif _n <= 59 %}\n {%- set ns_state.effort = '4' %}\n {%- elif _n <= 69 %}\n {%- set ns_state.effort = '5' %}\n {%- elif _n <= 79 %}\n {%- set ns_state.effort = '6' %}\n {%- elif _n <= 89 %}\n {%- set ns_state.effort = '7' %}\n {%- elif _n <= 96 %}\n {%- set ns_state.effort = '8' %}\n {%- else %}\n {%- set ns_state.effort = '9' %}\n {%- endif %}\n{%- endif %}\n\n{#- Depth-tool coupling, part A: trailing tool-failure streak pre-pass. -#}\n{%- set _streak = namespace(value=0) %}\n{%- for msg in messages %}\n {%- if msg.role == 'tool' %}\n {%- set _tc = scan_text(msg.content) | trim %}\n {%- if classify_tool_output(_tc) | trim == 'error' %}\n {%- set _streak.value = _streak.value + 1 %}\n {%- else %}\n {%- set _streak.value = 0 %}\n {%- endif %}\n {%- elif msg.role == 'user' %}\n {%- set _streak.value = 0 %}\n {%- endif %}\n{%- endfor %}\n\n{#- Depth-tool coupling, part B: state adjustment BEFORE rendering. -#}\n{#- Collapse: tools attached, no explicit depth signal → [L4]. -#}\n{#- Escalate: 2+ consecutive tool failures → +1 band, capped at [L7]. -#}\n{#- Swarm/council profiles are never auto-tuned (non-numeric effort). -#}\n{%- if _has_tools and not _depth_explicit and ns_state.thinking %}\n {%- set ns_state.effort = '4' %}\n{%- endif %}\n{%- if _streak.value >= 2 and ns_state.thinking %}\n {%- set _cur = ns_state.effort if ns_state.effort else '7' %}\n {%- if _cur == '1' %}\n {%- set ns_state.effort = '2' %}\n {%- elif _cur == '2' %}\n {%- set ns_state.effort = '3' %}\n {%- elif _cur == '3' %}\n {%- set ns_state.effort = '4' %}\n {%- elif _cur == '4' %}\n {%- set ns_state.effort = '5' %}\n {%- elif _cur == '5' %}\n {%- set ns_state.effort = '6' %}\n {%- elif _cur == '6' %}\n {%- set ns_state.effort = '7' %}\n {%- elif _cur in ('7', '8', '9') %}\n {%- set ns_state.effort = '7' %}\n {%- endif %}\n{%- endif %}\n\n{#- Alias resolver: number / name / compat alias → profile. Runs AFTER -#}\n{#- coupling, so the rendered profile always matches the final effort. -#}\n{#- Unknown input degrades gracefully to [L7]; it never hard-fails. -#}\n{#- Silent modes (i-prefix) still inject the depth profile: the model -#}\n{#- reasons at that quality internally while thinking tags stay closed. -#}\n{%- set reasoning_instructions = '' %}\n{%- if ns_state.thinking or ns_state.silent_profile %}\n {%- set target_mode = ns_state.effort if ns_state.effort else '10' %}\n {%- if target_mode in ('10', 'proteus', 'dynamic', 'auto', 'adaptive', 'fluid', 'default') %}\n {%- set reasoning_instructions = inst_proteus %}\n {%- elif target_mode in ('1', 'hermes', 'ulow', 'ultra-low', 'micro', 'minimal') %}\n {%- set reasoning_instructions = inst_hermes %}\n {%- elif target_mode in ('2', 'apollo', 'low') %}\n {%- set reasoning_instructions = inst_apollo %}\n {%- elif target_mode in ('3', 'artemis', 'lmed', 'low-medium') %}\n {%- set reasoning_instructions = inst_artemis %}\n {%- elif target_mode in ('4', 'athena', 'medium', 'med') %}\n {%- set reasoning_instructions = inst_athena %}\n {%- elif target_mode in ('5', 'prometheus', 'mhigh', 'medium-high') %}\n {%- set reasoning_instructions = inst_prometheus %}\n {%- elif target_mode in ('6', 'solstice', 'high') %}\n {%- set reasoning_instructions = inst_solstice %}\n {%- elif target_mode in ('7', 'hyperion', 'xhigh', 'default', 'extreme') %}\n {%- set reasoning_instructions = inst_hyperion %}\n {%- elif target_mode in ('8', 'einstein', 'uhigh', 'ultra-high') %}\n {%- set reasoning_instructions = inst_einstein %}\n {%- elif target_mode in ('9', 'oracle', 'amax', 'max', 'absolute-max') %}\n {%- set reasoning_instructions = inst_oracle %}\n {%- elif target_mode in ('swarm', 'einstein-swarm', '20-swarm', 'uhigh-swarm', 'divergent') %}\n {%- set reasoning_instructions = inst_swarm %}\n {%- elif target_mode in ('deep-swarm', 'oracle-swarm', 'council', 'amax-swarm', 'deep-research', 'spoon', 'adversarial') %}\n {%- set reasoning_instructions = inst_deep_swarm %}\n {%- else %}\n {%- set reasoning_instructions = inst_proteus %}\n {%- endif %}\n{%- endif %}\n\n{#- ================================================================== -#}\n{#- S3 RENDER PIPELINE — ChatML emission. -#}\n{#- ================================================================== -#}\n\n{#- Leading system-message grouping. -#}\n{%- set head = namespace(count=0, seen_non_system=false) %}\n{%- for message in messages %}\n {%- set _is_sys = (message.role == 'system' or message.role == 'developer') %}\n {%- if _is_sys and not head.seen_non_system %}\n {%- set head.count = head.count + 1 %}\n {%- else %}\n {%- set head.seen_non_system = true %}\n {%- endif %}\n{%- endfor %}\n{%- set sys_state = namespace(content='') %}\n{%- for message in messages[:head.count] %}\n {%- set _part = render_content(message.content, false) | trim %}\n {%- if _part %}\n {%- if sys_state.content %}\n {%- set sys_state.content = sys_state.content ~ '\\n\\n' ~ _part %}\n {%- else %}\n {%- set sys_state.content = _part %}\n {%- endif %}\n {%- endif %}\n{%- endfor %}\n{%- set _sc = sys_state.content %}\n{%- set _msgs = messages[head.count:] %}\n\n{%- set _terse_active = terse if terse is defined else (not is_explicit_regular) %}\n{%- if _terse_active %}\n {%- if not _sc %}\n {%- set _sc = terse_core | trim %}\n {%- else %}\n {%- set _sc = (_sc | trim) ~ '\\n\\n' ~ (terse_core | trim) %}\n {%- endif %}\n{%- endif %}\n\n{#- Some runtimes prepend their own tool protocol; stand down if seen. -#}\n{%- set _runtime_tool_protocol = (_sc is defined and _sc and '[TOOL_REQUEST]' in _sc) %}\n{%- if suppress_tool_instructions is not none %}\n {%- set _suppress_tools = suppress_tool_instructions %}\n{%- else %}\n {%- set _suppress_tools = _runtime_tool_protocol %}\n{%- endif %}\n\n{#- System emission: profile + soft contract + tools. -#}\n{%- if reasoning_instructions or _sc or (_has_tools and not _suppress_tools) %}\n {{- '<|im_start|>system\\n' }}\n {%- if reasoning_instructions %}\n {{- reasoning_instructions ~ '\\n\\n' ~ soft_budget_contract -}}\n {%- if _has_budget -%}\n {{- '\\n\\nBudget Directive: The host environment specifies an allocation ceiling of roughly ' ~ (_budget_val | string) ~ ' reasoning tokens. Calibrate your deductive steps to achieve full verification and early exit well within this boundary.' -}}\n {%- endif -%}\n {{- '\\n\\n' }}\n {%- endif %}\n {%- if _has_tools and not _suppress_tools %}\n {{- '# Tools\\n\\nYou have access to the following functions:\\n\\n' }}\n {%- for tool in tools %}\n {{- '\\n' }}\n {{- tool | tojson }}\n {%- endfor %}\n {{- '\\n' }}\n {%- if _tool_format == 'json' %}\n {{- '\\n\\nIf you choose to call a function ONLY reply in the following format with NO suffix:\\n\\n' }}\n {%- if ns_state.thinking %}\n {{- '\\nBrief explanation of tool call\\n\\n' }}\n {%- endif %}\n {{- '\\n{\"name\": \"example_function_name\", \"arguments\": {\"example_parameter_1\": \"value_1\", \"example_parameter_2\": \"This is the value for the second parameter\"}}\\n\\n\\n\\nReminder:\\n' }}\n {{- '- Function calls MUST follow the specified format: a single JSON object with \"name\" and \"arguments\" keys inside XML tags.\\n- The tag MUST be at the very beginning of a new line.\\n- To call multiple functions, output a separate, completely closed block for EACH function. Do NOT nest blocks.\\n- If you have all necessary data, provide your final answer directly to the user without any tool call.\\n' }}\n {%- else %}\n {{- '\\n\\nIf you choose to call a function ONLY reply in the following format with NO suffix:\\n\\n' }}\n {%- if ns_state.thinking %}\n {{- '\\nBrief explanation of tool call\\n\\n' }}\n {%- endif %}\n {{- '\\n\\n\\nvalue_1\\n\\n\\nThis is the value for the second parameter\\n\\n\\n\\n\\n\\nReminder:\\n' }}\n {{- '- Function calls MUST follow the specified format: an inner block must be nested within XML tags.\\n- The and tags MUST be at the very beginning of a new line.\\n- To call multiple functions, output a separate, completely closed block for EACH function. Do NOT nest blocks.\\n- If you have all necessary data, provide your final answer directly to the user without any tool call.\\n' }}\n {%- endif %}\n {%- if _sc %}\n {{- '\\n\\n' + _sc }}\n {%- endif %}\n {{- '<|im_end|>\\n' }}\n {%- else %}\n {%- if _sc %}\n {{- _sc + '<|im_end|>\\n' }}\n {%- else %}\n {{- '<|im_end|>\\n' }}\n {%- endif %}\n {%- endif %}\n{%- endif %}\n\n{#- Last real user turn (for preserve_thinking tail logic). -#}\n{%- set _last_idx = _msgs | length - 1 %}\n{%- set ns = namespace(multi_step_tool=true, last_query_index=_last_idx) %}\n{%- for message in _msgs[::-1] %}\n {%- set index = (_msgs | length - 1) - loop.index0 %}\n {%- if ns.multi_step_tool and message.role == 'user' %}\n {%- set _rc = render_content(message.content, false) | trim %}\n {%- if not (_rc.startswith('') and _rc.endswith('')) %}\n {%- set ns.multi_step_tool = false %}\n {%- set ns.last_query_index = index %}\n {%- endif %}\n {%- endif %}\n{%- endfor %}\n{%- if ns.multi_step_tool %}\n {%- if _last_idx > 50 %}\n {%- set ns.last_query_index = _last_idx %}\n {%- else %}\n {%- set ns.last_query_index = 0 %}\n {%- endif %}\n{%- endif %}\n\n{#- Message render loop. -#}\n{%- set ns2 = namespace(prev_role='', consecutive_failures=0) %}\n{%- for message in _msgs %}\n {%- set is_system = (message.role == \"system\" or message.role == \"developer\") %}\n {%- set content = render_content(message.content, true, is_system) | trim %}\n {%- if is_system %}\n {{- '<|im_start|>system\\n' + content + '<|im_end|>\\n' }}\n {%- elif message.role == 'user' %}\n {%- set ns2.consecutive_failures = 0 %}\n {{- '<|im_start|>user\\n' + (strip_control_tags(content) | trim) + '<|im_end|>\\n' }}\n {%- elif message.role == 'assistant' %}\n {%- set reasoning_content = '' %}\n {%- set _explicit_reasoning = '' %}\n {%- if message.reasoning_content is defined and message.reasoning_content is not none %}\n {%- if message.reasoning_content is string %}\n {%- set _explicit_reasoning = message.reasoning_content %}\n {%- else %}\n {%- set _explicit_reasoning = message.reasoning_content | string %}\n {%- endif %}\n {%- elif message.thinking is defined and message.thinking is not none %}\n {%- if message.thinking is string %}\n {%- set _explicit_reasoning = message.thinking %}\n {%- else %}\n {%- set _explicit_reasoning = message.thinking | string %}\n {%- endif %}\n {%- elif message.reasoning is defined and message.reasoning is not none %}\n {%- if message.reasoning is string %}\n {%- set _explicit_reasoning = message.reasoning %}\n {%- else %}\n {%- set _explicit_reasoning = message.reasoning | string %}\n {%- endif %}\n {%- endif %}\n {%- if _explicit_reasoning %}\n {%- set _lead_end = '' %}\n {%- if content.startswith('') and '' in content %}\n {%- set _lead_end = '' %}\n {%- elif content.startswith('') and '' in content %}\n {%- set _lead_end = '' %}\n {%- elif content.startswith('') %}\n {%- set _lead_end = '' %}\n {%- elif content.startswith('') %}\n {%- set _lead_end = '' %}\n {%- endif %}\n {%- if _lead_end %}\n {%- set content = content.split(_lead_end)[-1].lstrip('\\n') %}\n {%- endif %}\n {%- set reasoning_content = _explicit_reasoning %}\n {%- else %}\n {%- set _think_end = '' %}\n {%- if content.startswith('') %}\n {%- set _think_end = '' %}\n {%- elif content.startswith('') %}\n {%- set _think_end = '' %}\n {%- elif '\\n' in content %}\n {%- set _think_end = '\\n' %}\n {%- elif '\\n' in content %}\n {%- set _think_end = '\\n' %}\n {%- elif '\\n' in content %}\n {%- set _think_end = '\\n' %}\n {%- elif '\\n' in content %}\n {%- set _think_end = '\\n' %}\n {%- elif content.startswith('') and '' in content %}\n {%- set _think_end = '' %}\n {%- elif content.startswith('') and '' in content %}\n {%- set _think_end = '' %}\n {%- endif %}\n {%- if _think_end %}\n {%- if 'thinking' in _think_end %}\n {%- set _think_start = '' %}\n {%- else %}\n {%- set _think_start = '' %}\n {%- endif %}\n {%- set reasoning_content = content.split(_think_end)[0].rstrip('\\n') %}\n {%- if _think_start in reasoning_content %}\n {%- set reasoning_content = reasoning_content.split(_think_start)[-1].lstrip('\\n') %}\n {%- endif %}\n {%- set content = content.split(_think_end)[-1].lstrip('\\n') %}\n {%- endif %}\n {%- endif %}\n {%- set reasoning_content = reasoning_content | trim %}\n {%- if (_preserve_thinking or loop.index0 > ns.last_query_index) %}\n {{- '<|im_start|>assistant\\n\\n' + reasoning_content + '\\n\\n\\n' + content }}\n {%- else %}\n {{- '<|im_start|>assistant\\n' + content }}\n {%- endif %}\n {%- if message.tool_calls is defined and message.tool_calls and message.tool_calls is iterable and message.tool_calls is not mapping %}\n {%- for tool_call in message.tool_calls %}\n {%- if tool_call.function is defined and tool_call.function is not none %}\n {%- set tc = tool_call.function %}\n {%- else %}\n {%- set tc = tool_call %}\n {%- endif %}\n {%- set tc_name = tc.name if (tc.name is defined and tc.name is not none) else '' %}\n {%- if _tool_format == 'json' %}\n {%- if loop.first %}\n {%- if content | trim %}\n {{- '\\n\\n' }}\n {%- endif %}\n {%- else %}\n {{- '\\n' }}\n {%- endif %}\n {%- set _args = '{}' %}\n {%- if tc.arguments is defined and tc.arguments is not none %}\n {%- if tc.arguments is mapping %}\n {%- set _args = tc.arguments | tojson %}\n {%- elif tc.arguments is string %}\n {%- if tc.arguments %}\n {%- set _args = tc.arguments %}\n {%- endif %}\n {%- else %}\n {%- set _args = tc.arguments | tojson %}\n {%- endif %}\n {%- endif %}\n {{- '\\n{\"name\": ' }}{{- tc_name | tojson }}{{- ', \"arguments\": ' }}{{- _args }}{{- '}\\n' }}\n {%- else %}\n {%- if loop.first %}\n {%- if content | trim %}\n {{- '\\n\\n\\n\\n' }}\n {%- else %}\n {{- '\\n\\n' }}\n {%- endif %}\n {%- else %}\n {{- '\\n\\n\\n' }}\n {%- endif %}\n {%- if tc.arguments is defined and tc.arguments is not none %}\n {%- if tc.arguments is mapping %}\n {%- for args_name, args_value in tc.arguments.items() %}\n {{- '\\n' }}\n {%- if args_value is string %}\n {%- set _av = args_value %}\n {%- else %}\n {%- set _av = args_value | tojson %}\n {%- endif %}\n {%- if max_tool_arg_chars > 0 and _av | length > max_tool_arg_chars %}\n {{- _av[:max_tool_arg_chars] + '\\n[TRUNCATED - original length ' ~ (_av | length | string) ~ ' chars]' }}\n {%- else %}\n {{- _av }}\n {%- endif %}\n {{- '\\n\\n' }}\n {%- endfor %}\n {%- else %}\n {%- if tc.arguments is string %}\n {%- set _raw_args = tc.arguments %}\n {%- else %}\n {%- set _raw_args = tc.arguments | tojson %}\n {%- endif %}\n {%- if _raw_args %}\n {%- if max_tool_arg_chars > 0 and _raw_args | length > max_tool_arg_chars %}\n {{- _raw_args[:max_tool_arg_chars] + '\\n[TRUNCATED - original length ' ~ (_raw_args | length | string) ~ ' chars]' }}\n {%- else %}\n {{- _raw_args }}\n {%- endif %}\n {%- endif %}\n {%- endif %}\n {%- endif %}\n {{- '\\n' }}\n {%- endif %}\n {%- endfor %}\n {%- endif %}\n {{- '<|im_end|>\\n' }}\n {%- elif message.role == 'tool' %}\n {%- if classify_tool_output(content) | trim == 'error' %}\n {%- set ns2.consecutive_failures = ns2.consecutive_failures + 1 %}\n {%- else %}\n {%- set ns2.consecutive_failures = 0 %}\n {%- endif %}\n {%- if ns2.prev_role != 'tool' %}\n {{- '<|im_start|>user' }}\n {%- endif %}\n {%- set _is_json_payload = (_tool_format == 'json' and content | trim | length > 0 and (content | trim)[:1] in ('{', '[')) %}\n {%- if not _is_json_payload and max_tool_response_chars > 0 and content | length > max_tool_response_chars %}\n {%- set content = content[:max_tool_response_chars] + '\\n[TRUNCATED - original length ' ~ (content | length | string) ~ ' chars]' %}\n {%- endif %}\n {{- '\\n\\n' + content }}\n {%- if ns2.consecutive_failures >= 2 %}\n {{- '\\n\\n⚠️ SYSTEM WARNING: ' ~ ns2.consecutive_failures ~ ' consecutive tool errors detected. Your previous approach is incorrect. You MUST use a fundamentally different approach or corrected arguments.' }}\n {%- elif ns2.consecutive_failures == 1 %}\n {{- '\\n\\n⚠️ SYSTEM WARNING: The previous tool call returned an error. Diagnose the failure and retry with completely corrected arguments.' }}\n {%- endif %}\n {{- '\\n' }}\n {%- if loop.last %}\n {{- '<|im_end|>\\n' }}\n {%- else %}\n {%- set _next_role = _msgs[loop.index0 + 1].role %}\n {%- if _next_role != 'tool' %}\n {{- '<|im_end|>\\n' }}\n {%- endif %}\n {%- endif %}\n {%- else %}\n {{- '<|im_start|>user\\n[' + message.role + ']: ' + content + '<|im_end|>\\n' }}\n {%- endif %}\n {%- set ns2.prev_role = message.role %}\n{%- endfor %}\n\n{#- Generation prompt: open thinking when active (variable depth, the model -#}\n{#- decides how far to run), or pre-close it when disabled. -#}\n{%- if add_generation_prompt %}\n {{- '<|im_start|>assistant\\n' }}\n {%- if is_explicit_regular %}\n {#- Pure regular mode: no think block -#}\n {%- elif not ns_state.thinking %}\n {{- '\\n\\n\\n\\n' }}\n {%- else %}\n {{- '\\n' }}\n {%- endif %}\n{%- endif %}\n" }