SolsticeAI commited on
Commit
e211ef1
Β·
verified Β·
1 Parent(s): d6215f5

Fix universal.jinja: remove dead _terse_on set referencing is_explicit_regular before definition (crashes under StrictUndefined)

Browse files
Files changed (1) hide show
  1. templates/universal.jinja +137 -1
templates/universal.jinja CHANGED
@@ -1,4 +1,76 @@
1
  {%- set template_version = template_version if template_version is defined else "protium-v1.0.0-objective-gated" %}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2
  {%- macro render_content(content, do_vision_count, is_system_content=false) %}
3
  {%- if content is string %}
4
  {{- content }}
@@ -42,6 +114,9 @@
42
  {{- raise_exception('Unexpected content type.') }}
43
  {%- endif %}
44
  {%- endmacro %}
 
 
 
45
  {%- macro scan_text(content) %}
46
  {%- if content is string %}
47
  {{- content }}
@@ -55,6 +130,7 @@
55
  {%- endfor %}
56
  {%- endif %}
57
  {%- endmacro %}
 
58
  {#- Strip every inline control tag from visible text. -#}
59
  {%- macro strip_control_tags(text) %}
60
  {%- set t = text %}
@@ -73,6 +149,8 @@
73
  {%- 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]', '') %}
74
  {{- out }}
75
  {%- endmacro %}
 
 
76
  {%- macro strip_mode_tag(text) %}
77
  {%- set t = text %}
78
  {%- if '{REASON:' in t %}
@@ -84,6 +162,9 @@
84
  {%- endif %}
85
  {{- t }}
86
  {%- endmacro %}
 
 
 
87
  {%- macro classify_tool_output(content) %}
88
  {%- set _lower = content | lower %}
89
  {%- set _head = _lower[:120] %}
@@ -99,6 +180,12 @@
99
  {{- 'ok' }}
100
  {%- endif %}
101
  {%- endmacro %}
 
 
 
 
 
 
102
  {%- set soft_budget_contract -%}
103
  PROTIUM OBJECTIVE-GATED REASONING CONTRACT:
104
  1. Target Anchor: At token 1, isolate the exact termination criteria β€” define what a completed, verified solution requires before executing.
@@ -109,6 +196,7 @@ PROTIUM OBJECTIVE-GATED REASONING CONTRACT:
109
  6. 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.
110
  7. Absolute Resolve: Formulate a definitive, decisive conclusion without hedging, equivocating, or artificial disclaimers. Correctness and crisp utility are the sole metrics.
111
  {%- endset %}
 
112
  {%- set terse_core -%}
113
  Operational Directives:
114
  - Zero preamble, pleasantries, or question restatements.
@@ -116,6 +204,7 @@ Operational Directives:
116
  - Retain all essential mathematical, programmatic, and logical technical rigor.
117
  - If genuine ambiguity exists, resolve it along the most probable engineering standard or ask one targeted clarifying question.
118
  {%- endset %}
 
119
  {%- set inst_hermes -%}
120
  Reasoning effort: Hermes β€” [L1] (rapid instinct).
121
  Mindset: 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.
@@ -169,7 +258,14 @@ Reasoning effort: Council β€” adversarial research council (specialized mode).
169
  Mindset: 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.
170
  Output contract: Conclude thinking and open final response with "[COUNCIL VERDICT]" followed by the definitive ruling, key justification, and dissenting risk accounted for.
171
  {%- endset %}
 
 
 
 
 
 
172
  {%- set _kwarg_effort = '' %}
 
173
  {%- set reg_ns = namespace(active=false) %}
174
  {%- if (regular is defined and regular) or (mode is defined and mode in ('regular', 'vanilla', 'standard', 'default', 'clean')) %}
175
  {%- set reg_ns.active = true %}
@@ -203,6 +299,9 @@ Output contract: Conclude thinking and open final response with "[COUNCIL VERDIC
203
  {%- if auto_disable_thinking_with_tools and _has_tools %}
204
  {%- set ns_state.thinking = false %}
205
  {%- endif %}
 
 
 
206
  {%- set store = namespace(messages=[], raw_mode='', saw_inline=false) %}
207
  {%- if not messages %}
208
  {{- raise_exception('No messages provided.') }}
@@ -228,6 +327,7 @@ Output contract: Conclude thinking and open final response with "[COUNCIL VERDIC
228
  {%- endfor %}
229
  {%- endif %}
230
  {%- set _has_inline = _hi.v %}
 
231
  {%- if _is_steering %}
232
  {%- if '<|think_off|>' in _low %}
233
  {%- set ns_state.thinking = false %}
@@ -291,6 +391,7 @@ Output contract: Conclude thinking and open final response with "[COUNCIL VERDIC
291
  {%- endfor %}
292
  {%- endif %}
293
  {%- endif %}
 
294
  {%- set _tagged = ('{REASON:' in _txt) or ('[MODE:' in _txt) %}
295
  {%- if _tagged %}
296
  {%- set _raw_reason = '' %}
@@ -320,10 +421,13 @@ Output contract: Conclude thinking and open final response with "[COUNCIL VERDIC
320
  {%- endif %}
321
  {%- endif %}
322
  {%- endif %}
 
 
323
  {%- if _tagged and _role == 'assistant' %}
324
  {%- set _clean = strip_mode_tag(_txt) | trim %}
325
  {%- 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)}] %}
326
  {%- elif _is_steering and _has_inline %}
 
327
  {%- if msg.content is string %}
328
  {%- set _clean = strip_control_tags(_txt) | trim %}
329
  {%- set store.messages = store.messages + [{'role': _role, 'content': _clean}] %}
@@ -346,6 +450,11 @@ Output contract: Conclude thinking and open final response with "[COUNCIL VERDIC
346
  {%- endfor %}
347
  {%- set messages = store.messages %}
348
  {%- set _depth_explicit = (_depth_explicit or store.saw_inline) %}
 
 
 
 
 
349
  {%- set _eff_int = ns_state.effort | int %}
350
  {%- if ns_state.mode == 'level' and ns_state.effort is string and (_eff_int | string) == ns_state.effort and _eff_int >= 11 %}
351
  {%- set _n = ns_state.effort | int %}
@@ -370,6 +479,8 @@ Output contract: Conclude thinking and open final response with "[COUNCIL VERDIC
370
  {%- set ns_state.effort = '9' %}
371
  {%- endif %}
372
  {%- endif %}
 
 
373
  {%- set _streak = namespace(value=0) %}
374
  {%- for msg in messages %}
375
  {%- if msg.role == 'tool' %}
@@ -383,6 +494,11 @@ Output contract: Conclude thinking and open final response with "[COUNCIL VERDIC
383
  {%- set _streak.value = 0 %}
384
  {%- endif %}
385
  {%- endfor %}
 
 
 
 
 
386
  {%- if _has_tools and not _depth_explicit and ns_state.thinking %}
387
  {%- set ns_state.effort = '4' %}
388
  {%- endif %}
@@ -404,6 +520,12 @@ Output contract: Conclude thinking and open final response with "[COUNCIL VERDIC
404
  {%- set ns_state.effort = '7' %}
405
  {%- endif %}
406
  {%- endif %}
 
 
 
 
 
 
407
  {%- set reasoning_instructions = '' %}
408
  {%- if ns_state.thinking or ns_state.silent_profile %}
409
  {%- set target_mode = ns_state.effort if ns_state.effort else '10' %}
@@ -435,6 +557,11 @@ Output contract: Conclude thinking and open final response with "[COUNCIL VERDIC
435
  {%- set reasoning_instructions = inst_proteus %}
436
  {%- endif %}
437
  {%- endif %}
 
 
 
 
 
438
  {#- Leading system-message grouping. -#}
439
  {%- set head = namespace(count=0, seen_non_system=false) %}
440
  {%- for message in messages %}
@@ -467,12 +594,16 @@ Output contract: Conclude thinking and open final response with "[COUNCIL VERDIC
467
  {%- set _sc = (_sc | trim) ~ '\n\n' ~ (terse_core | trim) %}
468
  {%- endif %}
469
  {%- endif %}
 
 
470
  {%- set _runtime_tool_protocol = (_sc is defined and _sc and '[TOOL_REQUEST]' in _sc) %}
471
  {%- if suppress_tool_instructions is not none %}
472
  {%- set _suppress_tools = suppress_tool_instructions %}
473
  {%- else %}
474
  {%- set _suppress_tools = _runtime_tool_protocol %}
475
  {%- endif %}
 
 
476
  {%- if reasoning_instructions or _sc or (_has_tools and not _suppress_tools) %}
477
  {{- '<|im_start|>system\n' }}
478
  {%- if reasoning_instructions %}
@@ -516,6 +647,8 @@ Output contract: Conclude thinking and open final response with "[COUNCIL VERDIC
516
  {%- endif %}
517
  {%- endif %}
518
  {%- endif %}
 
 
519
  {%- set _last_idx = _msgs | length - 1 %}
520
  {%- set ns = namespace(multi_step_tool=true, last_query_index=_last_idx) %}
521
  {%- for message in _msgs[::-1] %}
@@ -535,6 +668,8 @@ Output contract: Conclude thinking and open final response with "[COUNCIL VERDIC
535
  {%- set ns.last_query_index = 0 %}
536
  {%- endif %}
537
  {%- endif %}
 
 
538
  {%- set ns2 = namespace(prev_role='', consecutive_failures=0) %}
539
  {%- for message in _msgs %}
540
  {%- set is_system = (message.role == "system" or message.role == "developer") %}
@@ -727,6 +862,7 @@ Output contract: Conclude thinking and open final response with "[COUNCIL VERDIC
727
  {%- endif %}
728
  {%- set ns2.prev_role = message.role %}
729
  {%- endfor %}
 
730
  {#- Generation prompt: open thinking when active (variable depth, the model -#}
731
  {#- decides how far to run), or pre-close it when disabled. -#}
732
  {%- if add_generation_prompt %}
@@ -738,4 +874,4 @@ Output contract: Conclude thinking and open final response with "[COUNCIL VERDIC
738
  {%- else %}
739
  {{- '<think>\n' }}
740
  {%- endif %}
741
- {%- endif %}
 
1
  {%- set template_version = template_version if template_version is defined else "protium-v1.0.0-objective-gated" %}
2
+
3
+ {#- ========================================================================== -#}
4
+ {#- PROTIUM-1.0 β€” OBJECTIVE-GATED COGNITIVE ARCHITECTURE -#}
5
+ {#- Solstice-AI Zero-Waste Protocol for High-Efficiency Reasoning Models -#}
6
+ {#- Named after Protium (1H): Zero Neutrons. Zero Dead Weight. Pure Thrust. -#}
7
+ {#- Lineage: qwen3.8-froggeric-v22.5.0 (DavidAU, MIT) -> Solstice-AI -#}
8
+ {#- -#}
9
+ {#- CORE TENETS: -#}
10
+ {#- 1. TOKEN 1 TARGET ANCHOR: Lock the termination condition at step 1. -#}
11
+ {#- 2. FORWARD-ONLY SOLVE: Advance directly toward the target. Eliminate -#}
12
+ {#- conversational filler ("let's see", "hmm", "wait"). No rhetorical -#}
13
+ {#- hesitation; execute pure continuous deduction. -#}
14
+ {#- 3. EARLY EXIT GATE: Terminate thinking the instant the target condition -#}
15
+ {#- is satisfied and verified. Never dwell, stall, or manufacture doubt. -#}
16
+ {#- 4. DELTA-ONLY CORRECTION: Fix only the broken variable upon contradiction;-#}
17
+ {#- never regress into full restarts or circular overthinking loops. -#}
18
+ {#- 5. ABSOLUTE RESOLVE: Decisive, unhedged final delivery. Zero preamble. -#}
19
+ {#- -#}
20
+ {#- THE SPECTRUM (governed purely by problem constraints & verification): -#}
21
+ {#- [L0] Mortal - thinking off; execute directly. -#}
22
+ {#- [L1] Hermes - rapid instinct; immediate verification pass. -#}
23
+ {#- [L2] Apollo - disciplined deduction; linear constraint trace. -#}
24
+ {#- [L3] Artemis - edge-case & boundary vulnerability audit. -#}
25
+ {#- [L4] Athena - strategic synthesis; architectural trade-offs. -#}
26
+ {#- [L5] Prometheus - defensive engineering; second-order failure modeling. -#}
27
+ {#- [L6] Solstice - axiomatic derivation; multi-hypothesis stress testing. -#}
28
+ {#- [L7] Hyperion - ground-up first-principles decomposition. -#}
29
+ {#- [L8] Einstein - theoretical mastery; unified invariant reduction. -#}
30
+ {#- [L9] Oracle - proof-grade formal authority; zero placeholders. -#}
31
+ {#- [L10] Proteus - dynamic cognitive adaptation (Default); auto-calibrated -#}
32
+ {#- impedance matching across all levels with early exit. -#}
33
+ {#- swarm - 20-perspective divergent swarm, verdict line. -#}
34
+ {#- council - adversarial research council, verdict line. -#}
35
+ {#- -#}
36
+ {#- CONTINUOUS DEPTH MAP (10-100): 1-14 L1 | 15-29 L2 | 30-44 L3 | 45-59 L4 | -#}
37
+ {#- 60-69 L5 | 70-79 L6 | 80-89 L7 | 90-96 L8 | 97-100 L9 | 0 = off. -#}
38
+ {#- -#}
39
+ {#- INLINE SYNTAX (case-insensitive, stripped before model sees them): -#}
40
+ {#- [L0]..[L9] | {REASON:level|name|number} | [MODE:level|name|number] -#}
41
+ {#- [regular] | [vanilla] | [standard] | [default] -#}
42
+ {#- Prefix 'i' = silent variant: {REASON:i8} runs L8 rigor, thinking hidden. -#}
43
+ {#- PRECEDENCE: default L7 < runtime kwarg < inline signals (last wins). -#}
44
+ {#- ========================================================================== -#}
45
+
46
+ {#- ------------------------------------------------------------------ -#}
47
+ {#- RUNTIME KWARGS -#}
48
+ {#- ------------------------------------------------------------------ -#}
49
+ {%- set _tool_format = tool_call_format if tool_call_format is defined else 'xml' %}
50
+ {%- set image_count = namespace(value=0) %}
51
+ {%- set video_count = namespace(value=0) %}
52
+ {%- set add_vision_id = add_vision_id if add_vision_id is defined else false %}
53
+ {%- set enable_thinking = enable_thinking if enable_thinking is defined else true %}
54
+ {%- set auto_disable_thinking_with_tools = auto_disable_thinking_with_tools if auto_disable_thinking_with_tools is defined else false %}
55
+ {%- if preserve_reasoning is defined and preserve_reasoning is not none %}
56
+ {%- set _preserve_thinking = preserve_reasoning %}
57
+ {%- elif preserve_thinking is defined and preserve_thinking is not none %}
58
+ {%- set _preserve_thinking = preserve_thinking %}
59
+ {%- else %}
60
+ {%- set _preserve_thinking = true %}
61
+ {%- endif %}
62
+ {%- set max_tool_arg_chars = max_tool_arg_chars if max_tool_arg_chars is defined else 0 %}
63
+ {%- set max_tool_response_chars = max_tool_response_chars if max_tool_response_chars is defined else 0 %}
64
+ {%- set _has_tools = (tools is defined and tools and tools is iterable and tools is not mapping) %}
65
+ {%- 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) %}
66
+ {%- 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) %}
67
+ {%- set suppress_tool_instructions = suppress_tool_instructions if suppress_tool_instructions is defined else none %}
68
+
69
+ {#- ================================================================== -#}
70
+ {#- S3 PRIMITIVES β€” render & scan helpers (no cognitive content). -#}
71
+ {#- ================================================================== -#}
72
+
73
+ {#- Content renderer with vision support (render loop only). -#}
74
  {%- macro render_content(content, do_vision_count, is_system_content=false) %}
75
  {%- if content is string %}
76
  {{- content }}
 
114
  {{- raise_exception('Unexpected content type.') }}
115
  {%- endif %}
116
  {%- endmacro %}
117
+
118
+ {#- Text-only scanner renderer: images/videos render as '' so the S1 scan -#}
119
+ {#- pass never raises on multimodal messages (v2.x vision bug fixed). -#}
120
  {%- macro scan_text(content) %}
121
  {%- if content is string %}
122
  {{- content }}
 
130
  {%- endfor %}
131
  {%- endif %}
132
  {%- endmacro %}
133
+
134
  {#- Strip every inline control tag from visible text. -#}
135
  {%- macro strip_control_tags(text) %}
136
  {%- set t = text %}
 
149
  {%- 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]', '') %}
150
  {{- out }}
151
  {%- endmacro %}
152
+
153
+ {#- Remove only a {REASON:...} / [MODE:...] tag (assistant history path). -#}
154
  {%- macro strip_mode_tag(text) %}
155
  {%- set t = text %}
156
  {%- if '{REASON:' in t %}
 
162
  {%- endif %}
163
  {{- t }}
164
  {%- endmacro %}
165
+
166
+ {#- Tool output error classifier β†’ 'error' | 'ok'. Shares ONE definition -#}
167
+ {#- with the S1 failure pre-pass and the render-loop warning counter. -#}
168
  {%- macro classify_tool_output(content) %}
169
  {%- set _lower = content | lower %}
170
  {%- set _head = _lower[:120] %}
 
180
  {{- 'ok' }}
181
  {%- endif %}
182
  {%- endmacro %}
183
+
184
+ {#- ================================================================== -#}
185
+ {#- S2 COGNITIVE PROFILES β€” pure text. Soft shares only; there are no -#}
186
+ {#- token counts, word floors or ceilings anywhere in this section. -#}
187
+ {#- ================================================================== -#}
188
+
189
  {%- set soft_budget_contract -%}
190
  PROTIUM OBJECTIVE-GATED REASONING CONTRACT:
191
  1. Target Anchor: At token 1, isolate the exact termination criteria β€” define what a completed, verified solution requires before executing.
 
196
  6. 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.
197
  7. Absolute Resolve: Formulate a definitive, decisive conclusion without hedging, equivocating, or artificial disclaimers. Correctness and crisp utility are the sole metrics.
198
  {%- endset %}
199
+
200
  {%- set terse_core -%}
201
  Operational Directives:
202
  - Zero preamble, pleasantries, or question restatements.
 
204
  - Retain all essential mathematical, programmatic, and logical technical rigor.
205
  - If genuine ambiguity exists, resolve it along the most probable engineering standard or ask one targeted clarifying question.
206
  {%- endset %}
207
+
208
  {%- set inst_hermes -%}
209
  Reasoning effort: Hermes β€” [L1] (rapid instinct).
210
  Mindset: 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.
 
258
  Mindset: 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.
259
  Output contract: Conclude thinking and open final response with "[COUNCIL VERDICT]" followed by the definitive ruling, key justification, and dissenting risk accounted for.
260
  {%- endset %}
261
+
262
+ {#- ================================================================== -#}
263
+ {#- S1 RESOLUTION CORE β€” one pass, one state, one resolver. -#}
264
+ {#- ================================================================== -#}
265
+
266
+ {#- Baseline: runtime kwarg (session default). thinking_level supported. -#}
267
  {%- set _kwarg_effort = '' %}
268
+
269
  {%- set reg_ns = namespace(active=false) %}
270
  {%- if (regular is defined and regular) or (mode is defined and mode in ('regular', 'vanilla', 'standard', 'default', 'clean')) %}
271
  {%- set reg_ns.active = true %}
 
299
  {%- if auto_disable_thinking_with_tools and _has_tools %}
300
  {%- set ns_state.thinking = false %}
301
  {%- endif %}
302
+
303
+ {#- Unified scan pass: collect mode tags, inline signals, cleaned messages. -#}
304
+ {#- Later signals override earlier ones (mid-chat re-escalation works). -#}
305
  {%- set store = namespace(messages=[], raw_mode='', saw_inline=false) %}
306
  {%- if not messages %}
307
  {{- raise_exception('No messages provided.') }}
 
327
  {%- endfor %}
328
  {%- endif %}
329
  {%- set _has_inline = _hi.v %}
330
+ {#- Inline think-tags + [L#] (steering roles only). Later messages win. -#}
331
  {%- if _is_steering %}
332
  {%- if '<|think_off|>' in _low %}
333
  {%- set ns_state.thinking = false %}
 
391
  {%- endfor %}
392
  {%- endif %}
393
  {%- endif %}
394
+ {#- {REASON:...} / [MODE:...] extraction (any role). -#}
395
  {%- set _tagged = ('{REASON:' in _txt) or ('[MODE:' in _txt) %}
396
  {%- if _tagged %}
397
  {%- set _raw_reason = '' %}
 
421
  {%- endif %}
422
  {%- endif %}
423
  {%- endif %}
424
+ {#- Build cleaned message store. Messages WITHOUT inline signals pass -#}
425
+ {#- through untouched, so multi-modal parts (images/videos) survive. -#}
426
  {%- if _tagged and _role == 'assistant' %}
427
  {%- set _clean = strip_mode_tag(_txt) | trim %}
428
  {%- 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)}] %}
429
  {%- elif _is_steering and _has_inline %}
430
+ {#- Multi-modal aware strip: clean text items, keep image/video parts. -#}
431
  {%- if msg.content is string %}
432
  {%- set _clean = strip_control_tags(_txt) | trim %}
433
  {%- set store.messages = store.messages + [{'role': _role, 'content': _clean}] %}
 
450
  {%- endfor %}
451
  {%- set messages = store.messages %}
452
  {%- set _depth_explicit = (_depth_explicit or store.saw_inline) %}
453
+
454
+ {#- Continuous depth: pure integers 10-100 map onto the spectrum band. -#}
455
+ {#- 0-9 stay legacy level numbers so old clients keep exact behaviour. -#}
456
+ {#- NB: int-filter round-trip instead of .isdigit() β€” minja (llama.cpp) -#}
457
+ {#- does not implement string.isdigit(). -#}
458
  {%- set _eff_int = ns_state.effort | int %}
459
  {%- if ns_state.mode == 'level' and ns_state.effort is string and (_eff_int | string) == ns_state.effort and _eff_int >= 11 %}
460
  {%- set _n = ns_state.effort | int %}
 
479
  {%- set ns_state.effort = '9' %}
480
  {%- endif %}
481
  {%- endif %}
482
+
483
+ {#- Depth-tool coupling, part A: trailing tool-failure streak pre-pass. -#}
484
  {%- set _streak = namespace(value=0) %}
485
  {%- for msg in messages %}
486
  {%- if msg.role == 'tool' %}
 
494
  {%- set _streak.value = 0 %}
495
  {%- endif %}
496
  {%- endfor %}
497
+
498
+ {#- Depth-tool coupling, part B: state adjustment BEFORE rendering. -#}
499
+ {#- Collapse: tools attached, no explicit depth signal β†’ [L4]. -#}
500
+ {#- Escalate: 2+ consecutive tool failures β†’ +1 band, capped at [L7]. -#}
501
+ {#- Swarm/council profiles are never auto-tuned (non-numeric effort). -#}
502
  {%- if _has_tools and not _depth_explicit and ns_state.thinking %}
503
  {%- set ns_state.effort = '4' %}
504
  {%- endif %}
 
520
  {%- set ns_state.effort = '7' %}
521
  {%- endif %}
522
  {%- endif %}
523
+
524
+ {#- Alias resolver: number / name / compat alias β†’ profile. Runs AFTER -#}
525
+ {#- coupling, so the rendered profile always matches the final effort. -#}
526
+ {#- Unknown input degrades gracefully to [L7]; it never hard-fails. -#}
527
+ {#- Silent modes (i-prefix) still inject the depth profile: the model -#}
528
+ {#- reasons at that quality internally while thinking tags stay closed. -#}
529
  {%- set reasoning_instructions = '' %}
530
  {%- if ns_state.thinking or ns_state.silent_profile %}
531
  {%- set target_mode = ns_state.effort if ns_state.effort else '10' %}
 
557
  {%- set reasoning_instructions = inst_proteus %}
558
  {%- endif %}
559
  {%- endif %}
560
+
561
+ {#- ================================================================== -#}
562
+ {#- S3 RENDER PIPELINE β€” ChatML emission. -#}
563
+ {#- ================================================================== -#}
564
+
565
  {#- Leading system-message grouping. -#}
566
  {%- set head = namespace(count=0, seen_non_system=false) %}
567
  {%- for message in messages %}
 
594
  {%- set _sc = (_sc | trim) ~ '\n\n' ~ (terse_core | trim) %}
595
  {%- endif %}
596
  {%- endif %}
597
+
598
+ {#- Some runtimes prepend their own tool protocol; stand down if seen. -#}
599
  {%- set _runtime_tool_protocol = (_sc is defined and _sc and '[TOOL_REQUEST]' in _sc) %}
600
  {%- if suppress_tool_instructions is not none %}
601
  {%- set _suppress_tools = suppress_tool_instructions %}
602
  {%- else %}
603
  {%- set _suppress_tools = _runtime_tool_protocol %}
604
  {%- endif %}
605
+
606
+ {#- System emission: profile + soft contract + tools. -#}
607
  {%- if reasoning_instructions or _sc or (_has_tools and not _suppress_tools) %}
608
  {{- '<|im_start|>system\n' }}
609
  {%- if reasoning_instructions %}
 
647
  {%- endif %}
648
  {%- endif %}
649
  {%- endif %}
650
+
651
+ {#- Last real user turn (for preserve_thinking tail logic). -#}
652
  {%- set _last_idx = _msgs | length - 1 %}
653
  {%- set ns = namespace(multi_step_tool=true, last_query_index=_last_idx) %}
654
  {%- for message in _msgs[::-1] %}
 
668
  {%- set ns.last_query_index = 0 %}
669
  {%- endif %}
670
  {%- endif %}
671
+
672
+ {#- Message render loop. -#}
673
  {%- set ns2 = namespace(prev_role='', consecutive_failures=0) %}
674
  {%- for message in _msgs %}
675
  {%- set is_system = (message.role == "system" or message.role == "developer") %}
 
862
  {%- endif %}
863
  {%- set ns2.prev_role = message.role %}
864
  {%- endfor %}
865
+
866
  {#- Generation prompt: open thinking when active (variable depth, the model -#}
867
  {#- decides how far to run), or pre-close it when disabled. -#}
868
  {%- if add_generation_prompt %}
 
874
  {%- else %}
875
  {{- '<think>\n' }}
876
  {%- endif %}
877
+ {%- endif %}