SolsticeAI commited on
Commit
25c1d3f
·
verified ·
1 Parent(s): 06d4b67

feat: update llama3.jinja with v3.0 soft-spectrum and regular mode

Browse files
Files changed (1) hide show
  1. templates/llama3.jinja +865 -336
templates/llama3.jinja CHANGED
@@ -1,348 +1,877 @@
1
- {#- ================================================================= -#}
2
- {#- HyperSynapse-SAS (SelfAgentSwarm) 10-Level Cognitive Architecture -#}
3
- {#- Tailored for Meta Llama 3 / 3.1 / 3.2 / 3.3 / Llama 4 -#}
4
- {#- Levels: 0=Mortal/Disabled, 1=Hermes/ulow, 2=Apollo/low, -#}
5
- {#- 3=Artemis/lmed, 4=Athena/medium, 5=Prometheus/mhigh, -#}
6
- {#- 6=Solstice/high, 7=Hyperion/xhigh (Default), 8=Einstein (Solo), -#}
7
- {#- 9=Oracle (Solo). Swarm: swarm (20-Agent), deep-swarm (Council) -#}
8
- {#- ================================================================= -#}
9
- {%- set inst_hermes -%}
10
- [COGNITIVE FRAMEWORK: HERMES — LEVEL 1 (ULTRALOW / RAPID INSTINCT)]
11
- Role & Persona: You are Hermes, the swift cognitive vanguard. Your duty is high-velocity precision, immediate execution, and rapid sanity checks without cognitive stalling.
12
 
13
- Operational Directives:
14
- - Cognitive Pacing: Soft-elastic micro-exploration. For direct inquiries, conclude your thinking rapidly. If subtle contradictions or trick premises emerge, resolve them with minimal overhead.
15
- - Step 1 (Intent & Core Deconstruction): Strip away surface verbiage; pinpoint the exact core entity, mathematical quantity, code function, or direct question asked.
16
- - Step 2 (Rapid Sanity & Boundary Check): Perform an immediate sanity check on the primary premise. Spot-check basic arithmetic, syntax constraints, or binary logic.
17
- - Step 3 (Direct Route to Conclusion): Discard unnecessary discursive exposition. Formulate the shortest verified logical bridge from premise to conclusion cleanly.
18
- {%- endset -%}
19
- {%- set inst_apollo -%}
20
- [COGNITIVE FRAMEWORK: APOLLO — LEVEL 2 (LOW / CRISP LOGIC & CLARITY)]
21
- Role & Persona: You are Apollo, embodiment of light, structured clarity, and disciplined deduction. Your purpose is crisp, transparent verification with zero cognitive clutter.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
22
 
23
- Operational Directives:
24
- - Cognitive Pacing: Compact, focused reasoning. Give the problem exactly the runway needed to establish correctness, and conclude directly once the premise is validated.
25
- - Step 1 (Constraint Mapping): Explicitly isolate all constraints, parameters, data types, and user conditions. Distinguish between hard invariants and stylistic preferences.
26
- - Step 2 (Linear Deductive Trace): Trace each premise to its immediate implication. Verify that intermediate deductions follow strictly from established facts or mathematical laws.
27
- - Step 3 (Clarity & Elimination of Ambiguity): If a prompt contains ambiguous terminology, resolve it by adopting the most technically standard, productive interpretation without derailment.
28
- {%- endset -%}
29
- {%- set inst_artemis -%}
30
- [COGNITIVE FRAMEWORK: ARTEMIS — LEVEL 3 (LOW-MEDIUM / PRECISION EDGE-CASE HUNTER)]
31
- Role & Persona: You are Artemis, the unerring tracker and boundary hunter. Your focus is targeted audit, vulnerability identification, and stress-testing unstated edge cases.
 
 
 
 
 
 
 
 
 
 
 
 
32
 
33
- Operational Directives:
34
- - Cognitive Pacing: Measured, purpose-driven scrutiny. Allow sufficient analytical space to seek out and evaluate hidden traps, zero conditions, and failure modes.
35
- - Step 1 (Perimeter & Edge-Case Scan): Systematically probe problem boundaries: numerical zero/negatives/overflow, null pointers, empty iterables, missing keys, concurrency collisions.
36
- - Step 2 (Vulnerability Audit): Before accepting an initial hypothesis, identify how it could fail in unusual or high-stress conditions.
37
- - Step 3 (Fortification & Verification): Patch identified weaknesses. Ensure the final response accounts for the worst-case operating envelope.
38
- {%- endset -%}
39
- {%- set inst_athena -%}
40
- [COGNITIVE FRAMEWORK: ATHENA — LEVEL 4 (MEDIUM / STRATEGIC SYNTHESIS & BALANCE)]
41
- Role & Persona: You are Athena, goddess of strategic wisdom, architectural balance, and sound judgment. You orchestrate comprehensive, balanced deliberation.
42
 
43
- Operational Directives:
44
- - Cognitive Pacing: Balanced, structural deliberation. Thought depth scales naturally with task complexity: simple requests receive succinct synthesis; multi-faceted problems receive rigorous decomposition.
45
- - Step 1 (Architectural Deconstruction): Break complex requests into modular sub-tasks. Identify prerequisites, core mechanisms, and expected outputs.
46
- - Step 2 (Trade-off & Option Assessment): Contrast plausible solution patterns (performance vs. readability, latency vs. throughput, modularity vs. simplicity). Justify chosen trade-offs.
47
- - Step 3 (Step-by-Step Coherence Check): Trace the proposed pipeline or proof from start to finish. Ensure each step produces valid input for subsequent stages.
48
- {%- endset -%}
49
- {%- set inst_prometheus -%}
50
- [COGNITIVE FRAMEWORK: PROMETHEUS — LEVEL 5 (MEDIUM-HIGH / ARCHITECTURAL FORETHOUGHT)]
51
- Role & Persona: You are Prometheus, titan of forethought and craftsmanship. Your mandate is proactive engineering, downstream impact analysis, and systemic resilience.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
52
 
53
- Operational Directives:
54
- - Cognitive Pacing: Deliberate systemic forethought. Deeply explore failure modes, scaling bottlenecks, and life-cycle implications before finalizing conclusions.
55
- - Step 1 (Context & Dependency Topology): Map how this solution fits into real-world production environments. Account for hardware limits, network latency, and concurrency.
56
- - Step 2 (Second-Order Effect Modeling): Account for 10x-100x scale, upstream dependency crashes, malformed payloads, technical debt, and memory footprints.
57
- - Step 3 (Defensive Engineering): Integrate fault tolerance, robust error handling, structured validation gates, and graceful degradation into the design.
58
- {%- endset -%}
59
- {%- set inst_solstice -%}
60
- [COGNITIVE FRAMEWORK: SOLSTICE — LEVEL 6 (HIGH / DEEP SYSTEMIC DERIVATION)]
61
- Role & Persona: You are Solstice, representing total illumination, deep systemic derivation, and uncompromising verification. No assumptions are taken on faith.
 
 
 
 
 
 
62
 
63
- Operational Directives:
64
- - Cognitive Pacing: Deep, continuous deliberation. Take full runway to trace formal proofs, explore competing hypotheses, and stress-test assumptions.
65
- - Step 1 (First-Principles Foundation): Explicitly declare foundational axioms, system properties, and mathematical truths governing the problem.
66
- - Step 2 (Multi-Branch Hypothesis Generation): Generate at least two fundamentally different approaches or proof tracks. Analyze the mathematical or logical properties of each.
67
- - Step 3 (Red-Team Adversarial Audit): Actively attempt to falsify your own leading hypothesis. Seek counterexamples, degenerate cases, and boundary contradictions.
68
- - Step 4 (Rigorous Formal Reconciliation): Reconcile all edge cases, tighten proofs, eliminate redundant logic, and verify that the resulting solution is optimal and sound.
69
- {%- endset -%}
70
- {%- set inst_hyperion -%}
71
- [COGNITIVE FRAMEWORK: HYPERION — LEVEL 7 (XHIGH / NATIVE RIGOROUS CONTINUUM — DEFAULT)]
72
- Role & Persona: You are Hyperion, titan of observation and continuous rigorous derivation. You operate at the native maximum cognitive depth of Qwen 3.8.
 
 
 
 
 
 
 
 
73
 
74
- Operational Directives:
75
- - Cognitive Pacing: Unbounded, meticulous analytical progression. Let your internal reasoning explore every nuance, sub-clause, and implicit requirement of the user request.
76
- - Step 1 (Exhaustive Semantic Deconstruction): Fully unpack the user prompt, implicit domain requirements, constraints, style specifications, and underlying goals.
77
- - Step 2 (Deep Iterative Step-by-Step Derivation): Walk through each logical deduction, mathematical calculation, algorithm design, or architectural choice with total semantic completeness.
78
- - Step 3 (Continuous Self-Correction & Verification): Interrogate intermediate states as they are generated. If an assumption weakens or a potential bug appears, course-correct immediately within your thinking trace before proceeding.
79
- - Step 4 (Synthesized Mastery): Produce a fully realized, deeply vetted, production-ready deliverable that requires no further user clarification or debugging.
80
- {%- endset -%}
81
- {%- set inst_einstein -%}
82
- [COGNITIVE FRAMEWORK: EINSTEIN — LEVEL 8 (UHIGH / SOLO THEORETICAL MASTERY)]
83
- Role & Persona: You are Einstein operating in pure solo analytical mastery. Your mandate is breakthrough theoretical derivation, radical first-principles intuition, and mathematical transcendence without roleplay or persona clutter.
 
 
84
 
85
- Operational Directives:
86
- - Cognitive Pacing: Extended solo theoretical exploration. Dissect foundational laws, hidden invariants, and non-obvious mathematical analogies.
87
- - Radical First-Principles Intuition: Strip away conventional dogma; isolate the bare informational and physical constraints of the problem.
88
- - Lateral Synthesis: Formulate elegant, unified mathematical or architectural models that collapse multi-stage complexity into singular, coherent solutions.
89
- - Rigorous Continuous Proof: Trace every deduction from base axioms through to unassailable conclusions, rigorously verifying edge conditions and asymptotic behavior.
90
- {%- endset -%}
91
- {%- set inst_oracle -%}
92
- [COGNITIVE FRAMEWORK: ORACLE — LEVEL 9 (AMAX / SOLO EXHAUSTIVE PROOF)]
93
- Role & Persona: You are the Oracle operating in pure solo definitive authority. You produce verified, proof-grade, exhaustive engineering deliverables and mathematical certainty.
 
 
 
 
 
 
 
 
94
 
95
- Operational Directives:
96
- - Cognitive Pacing: Deepest continuous solo analytical runway. Leave absolutely nothing to chance or intuition.
97
- - Exhaustive Root Deconstruction: Decompose the problem into atomic constituents; verify every underlying assumption, lemma, and invariant.
98
- - Adversarial Self-Falsification: Systematically challenge every proposed step against worst-case inputs, stress thresholds, and degenerate edge states.
99
- - Definitive Synthesis: Deliver the complete, finalized solution with unmatched technical accuracy, explicit proofs, and total implementation completeness.
100
- {%- endset -%}
101
- {%- set inst_swarm -%}
102
- [COGNITIVE FRAMEWORK: 20-AGENT DIVERGENT SWARM — SPECIALIZED SWARM MODE]
103
- Role & Persona: You are the Einstein Divergent Swarm Coordinator. Your purpose is breakthrough problem solving, radical lateral thinking, and multi-perspective emergence.
104
 
105
- Operational Protocol — The 20-Perspective Swarm:
106
- - Cognitive Pacing: Broad divergent exploration across multiple cognitive modalities followed by structured convergence. Scale token depth to the magnitude of the challenge.
107
- - Phase 1 (First-Principles Disassembly): Strip the problem of conventional paradigms. Isolate the bare informational, mathematical, or mechanical core.
108
- - Phase 2 (Perspective Swarm Activation): Internally simulate an array of up to 20 specialized virtual cognitive agents across Sternberg styles:
109
- 1. Analytical Logician: Evaluates formal validity, mathematical correctness, and axiom purity.
110
- 2. Creative Maverick: Explores radical, non-traditional metaphors, lateral paradigms, and disruptive angles.
111
- 3. Pragmatic Systems Engineer: Grounding in real-world feasibility, hardware limits, and operational cost.
112
- 4. Adversarial Red-Teamer: Attempts to break every proposed concept with exploit vectors and stress tests.
113
- 5. Systems Dynamics Modeler: Traces feedback loops, emergent properties, and long-term equilibria.
114
- 6. Algorithmic Optimizer: Focuses on computational complexity, asymptotic efficiency, and memory hierarchies.
115
- 7. Human Factors Critic: Analyzes cognitive ergonomics, developer experience, and interface clarity.
116
- - Phase 3 (Cross-Pollination & Synthesis): Force collisions between divergent concepts. When two seemingly opposed insights clash, synthesize a superior hybrid solution that resolves the conflict.
117
- - Phase 4 (Convergence & Polish): Filter out noise, solidify the highest-conviction breakthrough, and present a coherent, unified, master-level deliverable.
118
- {%- endset -%}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
119
  {%- set inst_deep_swarm -%}
120
- [COGNITIVE FRAMEWORK: DEEP RESEARCH COUNCIL — SPECIALIZED DEEP-SWARM MODE]
121
- Role & Persona: You are the Oracle Meta-Research Council. You simulate an exhaustive multi-expert research institute to produce verified, proof-grade, definitive results.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
122
 
123
- Operational Protocol — The Deep Research Standard:
124
- - Cognitive Pacing: Deepest analytical deliberation. Dynamically calibrate the complexity of the inquiry (Scale 1 to 5) and expand your reasoning runway accordingly.
125
- - Protocol 1 (Problem Calibration & Scope Framing): Rate task complexity from 1 to 5; explicitly identify domain boundaries and success criteria.
126
- - Protocol 2 (Virtual Expert Panel Assembly): Formulate 3 to 5 virtual specialist perspectives tailored specifically to the prompt (Domain Principal, Formal Methods Verification Critic, Systems Architect, Security/Compliance Lead, Final Synthesizer).
127
- - Protocol 3 (Adversarial Deliberation & Proof Trace): Have experts debate the problem, expose hidden assumptions, challenge lazy consensus, and require formal verification traces.
128
- - Protocol 4 (Multi-Candidate Evaluation Matrix): Formulate 2 to 3 candidate architectures. Score each on Correctness, Completeness, Efficiency, and Robustness (1-5 scale). Document the winning trade-off.
129
- - Protocol 5 (Master Deliverable Synthesis): Present the definitive final result with unmatched thoroughness, clear structure, and complete implementation.
130
- {%- endset -%}
131
- {%- set image_count = namespace(value=0) -%}
132
- {%- set video_count = namespace(value=0) -%}
133
- {%- macro render_content(content, do_vision_count, is_system_content=false) -%}
134
- {%- if content is string -%}
135
- {{- content -}}
136
- {%- elif content is iterable and content is not mapping -%}
137
- {%- for item in content -%}
138
- {%- if 'image' in item or 'image_url' in item or item.type == 'image' -%}
139
- {%- if is_system_content -%}
140
- {{- raise_exception('System message cannot contain images.') -}}
141
- {%- endif -%}
142
- {%- if do_vision_count -%}
143
- {%- set image_count.value = image_count.value + 1 -%}
144
- {%- endif -%}
145
- {%- if add_vision_id -%}
146
- {{- 'Picture ' ~ image_count.value ~ ': ' -}}
147
- {%- endif -%}
148
- {{- '<|vision_start|><|image_pad|><|vision_end|>' -}}
149
- {%- elif 'video' in item or item.type == 'video' -%}
150
- {%- if is_system_content -%}
151
- {{- raise_exception('System message cannot contain videos.') -}}
152
- {%- endif -%}
153
- {%- if do_vision_count -%}
154
- {%- set video_count.value = video_count.value + 1 -%}
155
- {%- endif -%}
156
- {%- if add_vision_id -%}
157
- {{- 'Video ' ~ video_count.value ~ ': ' -}}
158
- {%- endif -%}
159
- {{- '<|vision_start|><|video_pad|><|vision_end|>' -}}
160
- {%- elif 'text' in item -%}
161
- {{- item.text -}}
162
- {%- else -%}
163
- {{- raise_exception('Unexpected item type in content.') -}}
164
- {%- endif -%}
165
- {%- endfor -%}
166
- {%- elif content is none or content is undefined -%}
167
- {{- '' -}}
168
- {%- else -%}
169
- {{- raise_exception('Unexpected content type.') -}}
170
- {%- endif -%}
171
- {%- endmacro -%}
172
- {%- if not messages -%}
173
- {{- raise_exception('No messages provided.') -}}
174
- {%- endif -%}
175
- {%- set store = namespace(messages=[], reasoning_effort=reasoning_effort|default(''), enable_thinking=enable_thinking|default(true)) -%}
176
- {%- for msg in messages -%}
177
- {%- set raw_reason = "" -%}
178
- {%- set txt = render_content(msg.content, false, true) | trim -%}
179
- {%- if "{REASON:" in txt -%}
180
- {%- set after_tag = txt.split("{REASON:") -%}
181
- {%- set raw_reason = after_tag[1].split("}")[0] | lower | trim -%}
182
- {%- set tag = "{REASON:" ~ after_tag[1].split("}")[0] ~ "}" -%}
183
- {%- set clean_txt = txt.replace(tag, "") | trim -%}
184
- {%- set store.messages = store.messages + [{"role": msg.role, "content": clean_txt}] -%}
185
- {%- elif "[MODE:" in txt -%}
186
- {%- set after_tag = txt.split("[MODE:") -%}
187
- {%- set raw_reason = after_tag[1].split("]")[0] | lower | trim -%}
188
- {%- set tag = "[MODE:" ~ after_tag[1].split("]")[0] ~ "]" -%}
189
- {%- set clean_txt = txt.replace(tag, "") | trim -%}
190
- {%- set store.messages = store.messages + [{"role": msg.role, "content": clean_txt}] -%}
191
- {%- else -%}
192
- {%- set store.messages = store.messages + [{"role": msg.role, "content": txt}] -%}
193
- {%- endif -%}
194
- {%- if raw_reason -%}
195
- {%- if raw_reason.startswith('i') and raw_reason | length > 1 -%}
196
- {%- set store.reasoning_effort = raw_reason[1:] -%}
197
- {%- set store.enable_thinking = false -%}
198
- {%- else -%}
199
- {%- set store.reasoning_effort = raw_reason -%}
200
- {%- endif -%}
201
- {%- endif -%}
202
- {%- endfor -%}
203
- {%- set messages = store.messages -%}
204
- {%- set current_effort = store.reasoning_effort | default(reasoning_effort|default(thinking_level|default('xhigh'))) | string | lower | trim -%}
205
- {%- set current_thinking = store.enable_thinking -%}
206
- {%- if current_effort in ['0', 'disabled', 'none', 'off', 'zero', 'direct', 'mortal', 'chat'] -%}
207
- {%- set current_thinking = false -%}
208
- {%- set reasoning_instructions = '' -%}
209
- {%- elif current_effort in ['1', 'ulow', 'ultra-low', 'micro', 'minimal', 'hermes'] -%}
210
- {%- set reasoning_instructions = inst_hermes -%}
211
- {%- elif current_effort in ['2', 'low', 'compact', 'fast', 'apollo'] -%}
212
- {%- set reasoning_instructions = inst_apollo -%}
213
- {%- elif current_effort in ['3', 'lmed', 'low-medium', 'targeted', 'artemis'] -%}
214
- {%- set reasoning_instructions = inst_artemis -%}
215
- {%- elif current_effort in ['4', 'medium', 'med', 'balanced', 'athena'] -%}
216
- {%- set reasoning_instructions = inst_athena -%}
217
- {%- elif current_effort in ['5', 'mhigh', 'medium-high', 'architect', 'prometheus'] -%}
218
- {%- set reasoning_instructions = inst_prometheus -%}
219
- {%- elif current_effort in ['6', 'high', 'deep', 'thorough', 'solstice'] -%}
220
- {%- set reasoning_instructions = inst_solstice -%}
221
- {%- elif current_effort in ['7', 'xhigh', 'extreme-high', 'rigorous', 'hyperion', 'default'] -%}
222
- {%- set reasoning_instructions = inst_hyperion -%}
223
- {%- elif current_effort in ['8', 'uhigh', 'ultra-high', 'einstein', 'solo-einstein'] -%}
224
- {%- set reasoning_instructions = inst_einstein -%}
225
- {%- elif current_effort in ['9', 'amax', 'absolute-max', 'oracle', 'solo-oracle', 'proof'] -%}
226
- {%- set reasoning_instructions = inst_oracle -%}
227
- {%- elif current_effort in ['swarm', 'einstein-swarm', '20-swarm', 'uhigh-swarm'] -%}
228
- {%- set reasoning_instructions = inst_swarm -%}
229
- {%- elif current_effort in ['deep-swarm', 'oracle-swarm', 'council', 'amax-swarm', 'deep-research'] -%}
230
- {%- set reasoning_instructions = inst_deep_swarm -%}
231
- {%- else -%}
232
- {%- set reasoning_instructions = inst_hyperion -%}
233
- {%- endif -%}
234
- {%- if tools and tools is iterable and tools is not mapping -%}
235
- {{- '<|im_start|>system\n' -}}
236
- {%- if reasoning_instructions -%}
237
- {{- reasoning_instructions + '\n\n' -}}
238
- {%- endif -%}
239
- {{- "# Tools\n\nYou have access to the following functions:\n\n<tools>" -}}
240
- {%- for tool in tools -%}
241
- {{- "\n" -}}
242
- {{- tool | tojson -}}
243
- {%- endfor -%}
244
- {{- "\n</tools>" -}}
245
- {{- '\n\nIf you choose to call a function ONLY reply in the following format with NO suffix:\n\n<tool_call>\n<function=example_function_name>\n<parameter=example_parameter_1>\nvalue_1\n</parameter>\n<parameter=example_parameter_2>\nThis is the value for the second parameter\nthat can span\nmultiple lines\n</parameter>\n</function>\n</tool_call>\n\n<IMPORTANT>\nReminder:\n- Function calls MUST follow the specified format: an inner <function=...></function> block must be nested within <tool_call></tool_call> XML tags\n- Required parameters MUST be specified\n- You may provide optional reasoning for your function call in natural language BEFORE the function call, but NOT after\n- If there is no function call available, answer the question like normal with your current knowledge and do not tell the user about function calls\n</IMPORTANT>' -}}
246
- {%- if messages[0].role == 'system' -%}
247
- {%- set content = render_content(messages[0].content, false, true)|trim -%}
248
- {%- if content -%}
249
- {{- '\n\n' + content -}}
250
- {%- endif -%}
251
- {%- endif -%}
252
- {{- '<|im_end|>\n' -}}
253
- {%- else -%}
254
- {%- if messages[0].role == 'system' -%}
255
- {%- set content = render_content(messages[0].content, false, true)|trim -%}
256
- {%- if content -%}
257
- {{- '<|im_start|>system\n' + (reasoning_instructions + '\n\n' if reasoning_instructions else '') + content + '<|im_end|>\n' -}}
258
- {%- elif reasoning_instructions -%}
259
- {{- '<|im_start|>system\n' + reasoning_instructions + '<|im_end|>\n' -}}
260
- {%- endif -%}
261
- {%- elif reasoning_instructions -%}
262
- {{- '<|im_start|>system\n' + reasoning_instructions + '<|im_end|>\n' -}}
263
- {%- endif -%}
264
- {%- endif -%}
265
- {{- bos_token -}}
266
- {%- set ns = namespace(multi_step_tool=true, last_query_index=messages|length - 1) -%}
267
- {%- for message in messages[::-1] -%}
268
- {%- set index = (messages|length - 1) - loop.index0 -%}
269
- {%- if ns.multi_step_tool and message.role == "user" -%}
270
- {%- set content = render_content(message.content, false)|trim -%}
271
- {%- if not(content.startswith('<tool_response>') and content.endswith('</tool_response>')) -%}
272
- {%- set ns.multi_step_tool = false -%}
273
- {%- set ns.last_query_index = index -%}
274
- {%- endif -%}
275
- {%- endif -%}
276
- {%- endfor -%}
277
- {%- if ns.multi_step_tool -%}
278
- {{- raise_exception('No user query found in messages.') -}}
279
- {%- endif -%}
280
- {%- for message in messages -%}
281
- {%- set content = render_content(message.content, true)|trim -%}
282
- {%- if message.role == "system" -%}
283
- {%- if not loop.first -%}
284
- {{- raise_exception('System message must be at the beginning.') -}}
285
- {%- endif -%}
286
- {%- elif message.role == "user" -%}
287
- {{- '<|im_start|>' + message.role + '\n' + content + '<|eot_id|>\n' -}}
288
- {%- elif message.role == "assistant" -%}
289
- {%- set reasoning_content = '' -%}
290
- {%- if message.reasoning_content is string -%}
291
- {%- set reasoning_content = message.reasoning_content -%}
292
- {%- endif -%}
293
- {%- set reasoning_content = reasoning_content|trim -%}
294
- {%- if preserve_thinking is undefined or preserve_thinking is true or loop.index0 > ns.last_query_index -%}
295
- {{- '<|im_start|>' + message.role + '\n<think>\n' + reasoning_content + '\n</think>\n\n' + content -}}
296
- {%- else -%}
297
- {{- '<|im_start|>' + message.role + '\n' + content -}}
298
- {%- endif -%}
299
- {%- if message.tool_calls and message.tool_calls is iterable and message.tool_calls is not mapping -%}
300
- {%- for tool_call in message.tool_calls -%}
301
- {%- if tool_call.function is defined -%}
302
- {%- set tool_call = tool_call.function -%}
303
- {%- endif -%}
304
- {%- if loop.first -%}
305
- {%- if content|trim -%}
306
- {{- '\n\n<tool_call>\n<function=' + tool_call.name + '>\n' -}}
307
- {%- else -%}
308
- {{- '<tool_call>\n<function=' + tool_call.name + '>\n' -}}
309
- {%- endif -%}
310
- {%- else -%}
311
- {{- '\n<tool_call>\n<function=' + tool_call.name + '>\n' -}}
312
- {%- endif -%}
313
- {%- if tool_call.arguments is defined and tool_call.arguments != '' -%}
314
- {%- for args_name, args_value in tool_call.arguments|items -%}
315
- {{- '<parameter=' + args_name + '>\n' -}}
316
- {%- set args_value = args_value | string if args_value is string else args_value | tojson | safe -%}
317
- {{- args_value -}}
318
- {{- '\n</parameter>\n' -}}
319
- {%- endfor -%}
320
- {%- endif -%}
321
- {{- '</function>\n</tool_call>' -}}
322
- {%- endfor -%}
323
- {%- endif -%}
324
- {{- '<|eot_id|>\n' -}}
325
- {%- elif message.role == "tool" -%}
326
- {%- if loop.previtem and loop.previtem.role != "tool" -%}
327
- {{- '<|im_start|>user' -}}
328
- {%- endif -%}
329
- {{- '\n<tool_response>\n' -}}
330
- {{- content -}}
331
- {{- '\n</tool_response>' -}}
332
- {%- if not loop.last and loop.nextitem.role != "tool" -%}
333
- {{- '<|eot_id|>\n' -}}
334
- {%- elif loop.last -%}
335
- {{- '<|eot_id|>\n' -}}
336
- {%- endif -%}
337
- {%- else -%}
338
- {{- raise_exception('Unexpected message role.') -}}
339
- {%- endif -%}
340
- {%- endfor -%}
341
- {%- if add_generation_prompt -%}
342
- {{- '<|start_header_id|>assistant<|end_header_id|>\n\n' -}}
343
- {%- if not current_thinking -%}
344
- {{- '<think>\n\n</think>\n\n' -}}
345
- {%- else -%}
346
- {{- '<think>\n' -}}
347
- {%- endif -%}
348
- {%- endif -%}
 
1
+ {%- set template_version = template_version if template_version is defined else "hypersynapse-sas-v3.0.0-soft-spectrum" %}
 
 
 
 
 
 
 
 
 
 
2
 
3
+ {#- ========================================================================== -#}
4
+ {#- HYPER SYNAPSE — SAS v3.0 "SOFT SPECTRUM" -#}
5
+ {#- Solstice-AI Cognitive Architecture for Qwen3.8-family ChatML models. -#}
6
+ {#- Render pipeline lineage: qwen3.8-froggeric-v22.5.0 (DavidAU, MIT). -#}
7
+ {#- -#}
8
+ {#- DESIGN CONTRACT (v3.0): -#}
9
+ {#- 1. NO HARD BOUNDS. Every reasoning budget is a soft share of the model's -#}
10
+ {#- own output ("roughly a third to half of your output"), elastic in both -#}
11
+ {#- directions. Never a token quota. Never a word floor. Never a ceiling. -#}
12
+ {#- 2. VARIABLE THINKING. Depth is continuous: any integer 10-100 maps onto -#}
13
+ {#- the level spectrum. 0-9 remain legacy level numbers. Named levels, -#}
14
+ {#- swarm modes, runtime kwargs and inline tags all resolve to one state. -#}
15
+ {#- 3. ONE SOURCE OF TRUTH. Inline tags, {REASON:} / [MODE:] prefixes and -#}
16
+ {#- the reasoning_effort / thinking_level kwargs all feed the SAME -#}
17
+ {#- resolver (S1). Later signals in the conversation override earlier -#}
18
+ {#- ones, so depth can be re-escalated mid-chat. -#}
19
+ {#- 4. DEPTH-TOOL COUPLING. (a) With tools attached and NO explicit depth -#}
20
+ {#- signal, depth auto-collapses to L4 (tool work wants discipline, not -#}
21
+ {#- essays). (b) Two or more consecutive tool failures auto-escalate depth -#}
22
+ {#- one band (capped at L7). Swarm/council modes are never auto-tuned. -#}
23
+ {#- -#}
24
+ {#- CANONICAL VOCABULARY: [L0]..[L9], 'swarm', 'council', integer 10-100. -#}
25
+ {#- COMPAT ALIASES (resolve inward, documented below): ulow..amax, einstein, -#}
26
+ {#- spoon, deep-research, i-prefixed silent modes, legacy think-tags. -#}
27
+ {#- -#}
28
+ {#- THE SPECTRUM (soft shares of total output, elastic both directions): -#}
29
+ {#- [L0] Mortal - thinking off; answer directly. -#}
30
+ {#- [L1] Hermes - rapid instinct. usually under ~10% of output. -#}
31
+ {#- [L2] Apollo - crisp logic. roughly ~10-25% of output. -#}
32
+ {#- [L3] Artemis - edge-case hunting. roughly ~20-40% of output. -#}
33
+ {#- [L4] Athena - strategic balance. roughly ~30-50% of output. -#}
34
+ {#- [L5] Prometheus - defensive engineering. roughly ~40-60% of output. -#}
35
+ {#- [L6] Solstice - deep derivation. roughly ~50-70% of output. -#}
36
+ {#- [L7] Hyperion - first principles roughly ~60-85% of output. -#}
37
+ {#- (default). -#}
38
+ {#- [L8] Einstein - solo mastery. often most of the output. -#}
39
+ {#- [L9] Oracle - proof-grade rigour. as much as genuine proof demands.-#}
40
+ {#- swarm - 20-perspective divergent swarm, verdict line. -#}
41
+ {#- council - adversarial research council, verdict line. -#}
42
+ {#- -#}
43
+ {#- CONTINUOUS DEPTH MAP (10-100): 1-14 L1 | 15-29 L2 | 30-44 L3 | 45-59 L4 | -#}
44
+ {#- 60-69 L5 | 70-79 L6 | 80-89 L7 | 90-96 L8 | 97-100 L9 | 0 = off. -#}
45
+ {#- -#}
46
+ {#- INLINE SYNTAX (case-insensitive, stripped before the model sees them): -#}
47
+ {#- think on/off/minimal/low/medium/high/xhigh/ultracode/extreme/max -#}
48
+ {#- [L0]..[L9] | {REASON:level|name|number} | [MODE:level|name|number] -#}
49
+ {#- Prefix 'i' = silent variant: {REASON:i8} runs L8 quality, thinking off. -#}
50
+ {#- PRECEDENCE: default L7 < runtime kwarg (session baseline) < inline -#}
51
+ {#- signals, last one in conversation order wins. -#}
52
+ {#- ========================================================================== -#}
53
 
54
+ {#- ------------------------------------------------------------------ -#}
55
+ {#- RUNTIME KWARGS -#}
56
+ {#- ------------------------------------------------------------------ -#}
57
+ {%- set _tool_format = tool_call_format if tool_call_format is defined else 'xml' %}
58
+ {%- set image_count = namespace(value=0) %}
59
+ {%- set video_count = namespace(value=0) %}
60
+ {%- set add_vision_id = add_vision_id if add_vision_id is defined else false %}
61
+ {%- set enable_thinking = enable_thinking if enable_thinking is defined else true %}
62
+ {%- set auto_disable_thinking_with_tools = auto_disable_thinking_with_tools if auto_disable_thinking_with_tools is defined else false %}
63
+ {%- if preserve_reasoning is defined and preserve_reasoning is not none %}
64
+ {%- set _preserve_thinking = preserve_reasoning %}
65
+ {%- elif preserve_thinking is defined and preserve_thinking is not none %}
66
+ {%- set _preserve_thinking = preserve_thinking %}
67
+ {%- else %}
68
+ {%- set _preserve_thinking = true %}
69
+ {%- endif %}
70
+ {%- set max_tool_arg_chars = max_tool_arg_chars if max_tool_arg_chars is defined else 0 %}
71
+ {%- set max_tool_response_chars = max_tool_response_chars if max_tool_response_chars is defined else 0 %}
72
+ {%- set _has_tools = (tools is defined and tools and tools is iterable and tools is not mapping) %}
73
+ {%- set _terse_on = terse if terse is defined else (not is_explicit_regular) %}
74
+ {%- set suppress_tool_instructions = suppress_tool_instructions if suppress_tool_instructions is defined else none %}
75
 
76
+ {#- ================================================================== -#}
77
+ {#- S3 PRIMITIVES — render & scan helpers (no cognitive content). -#}
78
+ {#- ================================================================== -#}
 
 
 
 
 
 
79
 
80
+ {#- Content renderer with vision support (render loop only). -#}
81
+ {%- macro render_content(content, do_vision_count, is_system_content=false) %}
82
+ {%- if content is string %}
83
+ {{- content }}
84
+ {%- elif content is iterable and content is not mapping %}
85
+ {%- for item in content %}
86
+ {%- if item is mapping %}
87
+ {%- if item.type == 'image' or 'image' in item or 'image_url' in item %}
88
+ {%- if is_system_content %}
89
+ {{- raise_exception('System message cannot contain images.') }}
90
+ {%- endif %}
91
+ {%- if do_vision_count %}
92
+ {%- set image_count.value = image_count.value + 1 %}
93
+ {%- endif %}
94
+ {%- if add_vision_id %}
95
+ {{- 'Picture ' ~ image_count.value ~ ': ' }}
96
+ {%- endif %}
97
+ {{- '<|vision_start|><|image_pad|><|vision_end|>' }}
98
+ {%- elif item.type == 'video' or 'video' in item or 'video_url' in item %}
99
+ {%- if is_system_content %}
100
+ {{- raise_exception('System message cannot contain videos.') }}
101
+ {%- endif %}
102
+ {%- if do_vision_count %}
103
+ {%- set video_count.value = video_count.value + 1 %}
104
+ {%- endif %}
105
+ {%- if add_vision_id %}
106
+ {{- 'Video ' ~ video_count.value ~ ': ' }}
107
+ {%- endif %}
108
+ {{- '<|vision_start|><|video_pad|><|vision_end|>' }}
109
+ {%- elif 'text' in item %}
110
+ {{- item.text }}
111
+ {%- else %}
112
+ {{- raise_exception('Unexpected item type in content.') }}
113
+ {%- endif %}
114
+ {%- else %}
115
+ {{- item | string }}
116
+ {%- endif %}
117
+ {%- endfor %}
118
+ {%- elif content is none or content is undefined %}
119
+ {{- '' }}
120
+ {%- else %}
121
+ {{- raise_exception('Unexpected content type.') }}
122
+ {%- endif %}
123
+ {%- endmacro %}
124
 
125
+ {#- Text-only scanner renderer: images/videos render as '' so the S1 scan -#}
126
+ {#- pass never raises on multimodal messages (v2.x vision bug fixed). -#}
127
+ {%- macro scan_text(content) %}
128
+ {%- if content is string %}
129
+ {{- content }}
130
+ {%- elif content is iterable and content is not mapping %}
131
+ {%- for item in content %}
132
+ {%- if item is mapping and 'text' in item and item.text is string %}
133
+ {{- item.text }}
134
+ {%- elif item is string %}
135
+ {{- item }}
136
+ {%- endif %}
137
+ {%- endfor %}
138
+ {%- endif %}
139
+ {%- endmacro %}
140
 
141
+ {#- Strip every inline control tag from visible text. -#}
142
+ {%- macro strip_control_tags(text) %}
143
+ {%- set t = text %}
144
+ {%- if '{REASON:' in t %}
145
+ {%- set _raw = t.split('{REASON:')[1].split('}')[0] %}
146
+ {%- set t = t.replace('{REASON:' ~ _raw ~ '}', '') %}
147
+ {%- endif %}
148
+ {%- if '[MODE:' in t %}
149
+ {%- set _raw2 = t.split('[MODE:')[1].split(']')[0] %}
150
+ {%- set t = t.replace('[MODE:' ~ _raw2 ~ ']', '') %}
151
+ {%- endif %}
152
+ {%- set t2 = t %}
153
+ {%- 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|>', '') %}
154
+ {#- NB: no for-loops here — Jinja set does not persist across loop -#}
155
+ {#- iterations, so every strip must live in one chained expression. -#}
156
+ {%- set out = t3 | replace('[regular]', '') | replace('[REGULAR]', '') | replace('[vanilla]', '') | replace('[standard]', '') | replace('[default]', '') | 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]', '') %}
157
+ {{- out }}
158
+ {%- endmacro %}
159
 
160
+ {#- Remove only a {REASON:...} / [MODE:...] tag (assistant history path). -#}
161
+ {%- macro strip_mode_tag(text) %}
162
+ {%- set t = text %}
163
+ {%- if '{REASON:' in t %}
164
+ {%- set _raw = t.split('{REASON:')[1].split('}')[0] %}
165
+ {%- set t = t.replace('{REASON:' ~ _raw ~ '}', '') %}
166
+ {%- elif '[MODE:' in t %}
167
+ {%- set _raw = t.split('[MODE:')[1].split(']')[0] %}
168
+ {%- set t = t.replace('[MODE:' ~ _raw ~ ']', '') %}
169
+ {%- endif %}
170
+ {{- t }}
171
+ {%- endmacro %}
172
 
173
+ {#- Tool output error classifier → 'error' | 'ok'. Shares ONE definition -#}
174
+ {#- with the S1 failure pre-pass and the render-loop warning counter. -#}
175
+ {%- macro classify_tool_output(content) %}
176
+ {%- set _lower = content | lower %}
177
+ {%- set _head = _lower[:120] %}
178
+ {%- 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) %}
179
+ {%- set _exit_code_zero = ('exit code: 0' in _head or 'process exited with code 0' in _head) %}
180
+ {%- 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) %}
181
+ {%- 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 ')) %}
182
+ {%- set _weak = ('error:' in _head or 'err!' in _head) %}
183
+ {%- set _suppressed = ('$ ' in _head or 'took ' in _head or content | length >= 600) %}
184
+ {%- if not _is_code_or_grep and (_strong or (_weak and not _suppressed)) %}
185
+ {{- 'error' }}
186
+ {%- else %}
187
+ {{- 'ok' }}
188
+ {%- endif %}
189
+ {%- endmacro %}
190
 
191
+ {#- ================================================================== -#}
192
+ {#- S2 COGNITIVE PROFILES — pure text. Soft shares only; there are no -#}
193
+ {#- token counts, word floors or ceilings anywhere in this section. -#}
194
+ {#- ================================================================== -#}
 
 
 
 
 
195
 
196
+ {%- set soft_budget_contract -%}
197
+ REASONING BUDGET CONTRACT (SOFT — NEVER A HARD LIMIT):
198
+ - Reasoning depth at this level is guided as a typical SHARE of your total output for this reply. The share is elastic in both directions: a trivial task may need far less than the guide, a genuinely hard task may need more.
199
+ - Shares are calibration, not quotas. Never truncate real reasoning to stay under a share. Never pad, stall, or manufacture doubt to reach one.
200
+ - Scale continuously with genuine complexity. Think exactly as long as thinking earns its place, then answer. Usefulness and correctness are the only true bounds.
201
+ {%- endset %}
202
+
203
+ {%- set terse_core -%}
204
+ Never: open with preamble or pleasantries; restate the question; add filler transitions; hedge with niceties; or repeat a point you've already made.
205
+ Always: keep essential steps, caveats, uncertainties, and specifics — never drop correctness or a needed warning for brevity. Use the least structure that conveys the answer. If a request is genuinely ambiguous, ask a sharp question, don't guess.
206
+ {%- endset %}
207
+
208
+ {%- set inst_hermes -%}
209
+ Reasoning effort: Hermes — [L1] (rapid instinct).
210
+ Mindset: high-velocity precision. One quick sanity pass over the core ask — spot-check the premise, the arithmetic, the syntax — then commit to the shortest verified route to the answer.
211
+ Depth guide: keep visible reasoning to a light touch — usually under a tenth of your output, and near zero when the answer is obvious. Spend only what correctness demands.
212
+ {%- endset %}
213
+ {%- set inst_apollo -%}
214
+ Reasoning effort: Apollo — [L2] (crisp logic and clarity).
215
+ Mindset: transparent, disciplined deduction. Isolate constraints and givens, trace each premise to its implication, and eliminate ambiguity by choosing the most standard productive interpretation.
216
+ Depth guide: compact and focused — roughly a tenth to a quarter of your output, tuned to how tangled the constraints actually are. Conclude as soon as the premise is validated.
217
+ {%- endset %}
218
+ {%- set inst_artemis -%}
219
+ Reasoning effort: Artemis — [L3] (precision edge-case hunter).
220
+ Mindset: boundary and failure-mode audit. Probe zero/negative/overflow conditions, null and empty states, concurrency collisions, off-by-one traps, and degenerate inputs before accepting any hypothesis; fortify what you find.
221
+ Depth guide: measured scrutiny — roughly a fifth to two-fifths of your output, scaling with how many real edge surfaces the task has. Hunt hard, then close.
222
+ {%- endset %}
223
+ {%- set inst_athena -%}
224
+ Reasoning effort: Athena — [L4] (strategic synthesis and balance).
225
+ Mindset: architectural balance. Decompose the request into modular sub-tasks with explicit prerequisite chains; weigh genuine trade-offs (performance vs readability, latency vs throughput, simplicity vs flexibility) and justify the chosen path.
226
+ Depth guide: balanced deliberation — roughly a third to half of your output, expanding with the number of real decision axes. Every step must produce valid input for the next.
227
+ {%- endset %}
228
+ {%- set inst_prometheus -%}
229
+ Reasoning effort: Prometheus — [L5] (architectural forethought).
230
+ Mindset: defensive engineering. Model second-order effects and failure modes before building: upstream crashes, malformed payloads, scale jumps, memory and cache pressure, technical debt. Integrate fault tolerance and graceful degradation into the design itself.
231
+ Depth guide: systemic forethought — roughly two-fifths to three-fifths of your output, growing with blast radius and life-cycle stakes of the change.
232
+ {%- endset %}
233
+ {%- set inst_solstice -%}
234
+ Reasoning effort: Solstice — [L6] (deep systemic derivation).
235
+ Mindset: nothing on faith. Declare the foundational axioms, generate at least two fundamentally distinct approaches, analyse each on its merits, then red-team the leading hypothesis — actively seek counterexamples and boundary contradictions before tightening the final derivation.
236
+ Depth guide: continuous deep derivation — roughly half to seventy percent of your output, stretching with proof depth. Full runway for formal traces; stop the moment certainty is reached.
237
+ {%- endset %}
238
+ {%- set inst_hyperion -%}
239
+ Reasoning effort: Hyperion — [L7] (first-principles synthesis; default).
240
+ Mindset: foundational synthesis. Decompose the problem to its root cause from first principles, stress-test the logic against every plausible path, adversarial input, and edge case, and document intermediate steps, considered alternatives, and rejected hypotheses as you go.
241
+ Depth guide: majority-of-output reasoning — typically three-fifths to four-fifths of your reply, wholly elastic to real difficulty. No shortcuts while uncertainty remains; immediate closure once it doesn't.
242
+ {%- endset %}
243
+ {%- set inst_einstein -%}
244
+ Reasoning effort: Einstein — [L8] (solo theoretical mastery).
245
+ Mindset: breakthrough derivation in pure solo mode — radical first-principles intuition, lateral synthesis, and mathematical transcendence without persona clutter. Strip conventional dogma to the bare informational constraints; look for the elegant unified model that collapses multi-stage complexity into one coherent solution; carry every deduction to an unassailable conclusion including edge and asymptotic behaviour.
246
+ Depth guide: reasoning commonly dominates the reply — often three-fifths to nine-tenths of output — but stays a guide, not a target: derive exactly as long as the theory demands, then deliver.
247
+ {%- endset %}
248
+ {%- set inst_oracle -%}
249
+ Reasoning effort: Oracle — [L9] (proof-grade exhaustive rigour).
250
+ Mindset: definitive authority. Decompose the problem to atomic constituents; verify every assumption, lemma, and invariant; systematically falsify each step against worst-case inputs and degenerate states; deliver the complete, finalized, proof-grade solution with total implementation completeness.
251
+ Depth guide: unbounded by design — the reasoning may justly be the clear majority of the output, stretching as far as genuine proof demands and not one token further. Rigour is the only metric; padding is failure.
252
+ {%- endset %}
253
+ {%- set inst_swarm -%}
254
+ Reasoning effort: Swarm — 20-perspective divergent swarm (specialized mode).
255
+ Mindset: breakthrough problem solving through structured divergence and convergence.
256
+ Phase 1 — Disassembly: strip the problem of conventional paradigms; isolate the bare informational core.
257
+ Phase 2 — Perspective activation: internally simulate a divergent swarm of specialist voices — analytical logician, creative maverick, systems engineer, adversarial red-teamer, systems-dynamics modeller, algorithmic optimizer, human-factors critic, and kindred perspectives as the problem demands.
258
+ Phase 3 — Cross-pollination: force creative collisions between the strongest divergent concepts; synthesize hybrids that resolve real tensions between speed, memory, cost, and correctness.
259
+ Phase 4 — Convergence: solidify the highest-conviction breakthrough into a master-grade deliverable.
260
+ Depth guide: the swarm fills as much of the output as genuine exploration earns — commonly the majority for open-ended challenges — with every phase sized freely by what the problem actually needs. No phase is ever trimmed short or artificially extended.
261
+ Output contract: reason through the four phases, then close your reasoning and open the final answer with the line "[SWARM VERDICT]" followed by a one-paragraph synthesis naming the winning direction and the single strongest objection it survived.
262
+ {%- endset %}
263
  {%- set inst_deep_swarm -%}
264
+ Reasoning effort: Council — deep-swarm adversarial research council (specialized mode).
265
+ Mindset: simulate an exhaustive multi-expert research institute and produce verified, proof-grade, definitive results.
266
+ Protocol 1 — Calibration: rate the task's complexity honestly; set explicit domain boundaries and success criteria before any deliberation.
267
+ Protocol 2 — Panel: assemble a compact council of complementary virtual specialists tailored to this prompt (domain principal, formal-methods critic, systems architect, security/compliance lead, final synthesizer).
268
+ Protocol 3 — Adversarial deliberation: let the council debate, expose hidden assumptions, challenge lazy consensus, and trace proofs to their roots.
269
+ Protocol 4 — Candidate matrix: formulate several genuinely distinct candidate architectures; score each on correctness, completeness, efficiency, and robustness; document the winning trade-off.
270
+ Protocol 5 — Master deliverable: present the definitive result with clear structure and complete implementation.
271
+ Depth guide: deliberation may justly occupy the bulk of the output for hard problems and shrink to a focused pass for easy ones — always governed by what verification actually requires, never by a quota.
272
+ Output contract: deliberate through the five protocols, then open the final answer with the line "[COUNCIL VERDICT]" followed by the council's ruling, the decisive argument, and the loudest dissent the ruling overcame.
273
+ {%- endset %}
274
+
275
+ {#- ================================================================== -#}
276
+ {#- S1 RESOLUTION CORE — one pass, one state, one resolver. -#}
277
+ {#- ================================================================== -#}
278
+
279
+ {#- Baseline: runtime kwarg (session default). thinking_level supported. -#}
280
+ {%- set _kwarg_effort = '' %}
281
+
282
+ {%- set reg_ns = namespace(active=false) %}
283
+ {%- if (regular is defined and regular) or (mode is defined and mode in ('regular', 'vanilla', 'standard', 'default', 'clean')) %}
284
+ {%- set reg_ns.active = true %}
285
+ {%- endif %}
286
+ {%- for msg in messages %}
287
+ {%- 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) %}
288
+ {%- set reg_ns.active = true %}
289
+ {%- endif %}
290
+ {%- endfor %}
291
+ {%- set is_explicit_regular = reg_ns.active %}
292
+ {%- if is_explicit_regular %}
293
+ {%- set _kwarg_effort = 'regular' %}
294
+ {%- endif %}
295
+ {%- if reasoning_effort is defined and reasoning_effort is not none %}
296
+ {%- set _kwarg_effort = reasoning_effort | string | lower | trim %}
297
+ {%- elif thinking_level is defined and thinking_level is not none %}
298
+ {%- set _kwarg_effort = thinking_level | string | lower | trim %}
299
+ {%- endif %}
300
+ {%- set _initial_thinking = enable_thinking %}
301
+ {%- set _initial_effort = '7' %}
302
+ {%- set _depth_explicit = false %}
303
+ {%- if _kwarg_effort %}
304
+ {%- set _depth_explicit = true %}
305
+ {%- if _kwarg_effort in ('none', 'off', '0', 'mortal', 'disabled', 'regular', 'vanilla', 'standard', 'default', 'clean') %}
306
+ {%- set _initial_thinking = false %}
307
+ {%- else %}
308
+ {%- set _initial_effort = _kwarg_effort %}
309
+ {%- endif %}
310
+ {%- endif %}
311
+ {%- set ns_state = namespace(thinking=_initial_thinking, effort=_initial_effort, mode='level', silent_profile=false) %}
312
+ {%- if auto_disable_thinking_with_tools and _has_tools %}
313
+ {%- set ns_state.thinking = false %}
314
+ {%- endif %}
315
+
316
+ {#- Unified scan pass: collect mode tags, inline signals, cleaned messages. -#}
317
+ {#- Later signals override earlier ones (mid-chat re-escalation works). -#}
318
+ {%- set store = namespace(messages=[], raw_mode='', saw_inline=false) %}
319
+ {%- if not messages %}
320
+ {{- raise_exception('No messages provided.') }}
321
+ {%- endif %}
322
+ {%- for msg in messages %}
323
+ {%- set _txt = scan_text(msg.content) | trim %}
324
+ {%- set _role = msg.role %}
325
+ {%- set _is_steering = (_role == 'system' or _role == 'developer' or _role == 'user') %}
326
+ {%- set _tagged = ('{REASON:' in _txt) or ('[MODE:' in _txt) %}
327
+ {%- set _low = _txt | lower %}
328
+ {#- Does THIS message carry any inline signal? (multi-modal safe: text-only scan) -#}
329
+ {#- NB: namespace probe, because plain set inside a for-loop does not -#}
330
+ {#- propagate to the enclosing scope in Jinja2. -#}
331
+ {%- set _hi = namespace(v=_tagged) %}
332
+ {%- if _is_steering and '<|think_' in _low %}
333
+ {%- set _hi.v = true %}
334
+ {%- endif %}
335
+ {%- if _is_steering and not _hi.v %}
336
+ {%- for n in range(10) %}
337
+ {%- if '[l' ~ n ~ ']' in _low %}
338
+ {%- set _hi.v = true %}
339
+ {%- endif %}
340
+ {%- endfor %}
341
+ {%- endif %}
342
+ {%- set _has_inline = _hi.v %}
343
+ {#- Inline think-tags + [L#] (steering roles only). Later messages win. -#}
344
+ {%- if _is_steering %}
345
+ {%- if '<|think_off|>' in _low %}
346
+ {%- set ns_state.thinking = false %}
347
+ {%- set store.saw_inline = true %}
348
+ {%- elif '<|think_on|>' in _low %}
349
+ {%- set ns_state.thinking = true %}
350
+ {%- set store.saw_inline = true %}
351
+ {%- elif '<|think_extreme|>' in _low or '<|think_max|>' in _low %}
352
+ {%- set ns_state.thinking = true %}
353
+ {%- set ns_state.effort = '9' %}
354
+ {%- set ns_state.mode = 'level' %}
355
+ {%- set store.saw_inline = true %}
356
+ {%- elif '<|think_ultracode|>' in _low %}
357
+ {%- set ns_state.thinking = true %}
358
+ {%- set ns_state.effort = '8' %}
359
+ {%- set ns_state.mode = 'level' %}
360
+ {%- set store.saw_inline = true %}
361
+ {%- elif '<|think_xhigh|>' in _low %}
362
+ {%- set ns_state.thinking = true %}
363
+ {%- set ns_state.effort = '7' %}
364
+ {%- set ns_state.mode = 'level' %}
365
+ {%- set store.saw_inline = true %}
366
+ {%- elif '<|think_high|>' in _low %}
367
+ {%- set ns_state.thinking = true %}
368
+ {%- set ns_state.effort = '6' %}
369
+ {%- set ns_state.mode = 'level' %}
370
+ {%- set store.saw_inline = true %}
371
+ {%- elif '<|think_medium|>' in _low %}
372
+ {%- set ns_state.thinking = true %}
373
+ {%- set ns_state.effort = '4' %}
374
+ {%- set ns_state.mode = 'level' %}
375
+ {%- set store.saw_inline = true %}
376
+ {%- elif '<|think_low|>' in _low %}
377
+ {%- set ns_state.thinking = true %}
378
+ {%- set ns_state.effort = '2' %}
379
+ {%- set ns_state.mode = 'level' %}
380
+ {%- set store.saw_inline = true %}
381
+ {%- elif '<|think_minimal|>' in _low %}
382
+ {%- set ns_state.thinking = true %}
383
+ {%- set ns_state.effort = '1' %}
384
+ {%- set ns_state.mode = 'level' %}
385
+ {%- set store.saw_inline = true %}
386
+ {%- endif %}
387
+ {%- for n in range(10) %}
388
+ {%- if '[l' ~ n ~ ']' in _low %}
389
+ {%- set ns_state.effort = n | string %}
390
+ {%- set ns_state.mode = 'level' %}
391
+ {%- set store.saw_inline = true %}
392
+ {%- if n == 0 %}
393
+ {%- set ns_state.thinking = false %}
394
+ {%- else %}
395
+ {%- set ns_state.thinking = true %}
396
+ {%- endif %}
397
+ {%- endif %}
398
+ {%- endfor %}
399
+ {%- endif %}
400
+ {#- {REASON:...} / [MODE:...] extraction (any role). -#}
401
+ {%- set _tagged = ('{REASON:' in _txt) or ('[MODE:' in _txt) %}
402
+ {%- if _tagged %}
403
+ {%- set _raw_reason = '' %}
404
+ {%- if '{REASON:' in _txt %}
405
+ {%- set _raw_reason = _txt.split('{REASON:')[1].split('}')[0] %}
406
+ {%- elif '[MODE:' in _txt %}
407
+ {%- set _raw_reason = _txt.split('[MODE:')[1].split(']')[0] %}
408
+ {%- endif %}
409
+ {%- if _raw_reason %}
410
+ {%- set _mode_raw = _raw_reason | string | lower | trim %}
411
+ {%- set store.raw_mode = _mode_raw %}
412
+ {%- if _mode_raw.startswith('i') and _mode_raw | length > 1 %}
413
+ {%- set ns_state.effort = _mode_raw[1:] %}
414
+ {%- set ns_state.mode = 'level' %}
415
+ {%- set ns_state.thinking = false %}
416
+ {%- set ns_state.silent_profile = true %}
417
+ {%- set store.saw_inline = true %}
418
+ {%- else %}
419
+ {%- set ns_state.effort = _mode_raw %}
420
+ {%- set ns_state.mode = 'level' %}
421
+ {%- set store.saw_inline = true %}
422
+ {%- if _mode_raw in ('0', 'mortal', 'off', 'none', 'direct', 'chat', 'disabled', 'regular', 'vanilla', 'standard', 'default', 'clean') %}
423
+ {%- set ns_state.thinking = false %}
424
+ {%- else %}
425
+ {%- set ns_state.thinking = true %}
426
+ {%- endif %}
427
+ {%- endif %}
428
+ {%- endif %}
429
+ {%- endif %}
430
+ {#- Build cleaned message store. Messages WITHOUT inline signals pass -#}
431
+ {#- through untouched, so multi-modal parts (images/videos) survive. -#}
432
+ {%- if _tagged and _role == 'assistant' %}
433
+ {%- set _clean = strip_mode_tag(_txt) | trim %}
434
+ {%- 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)}] %}
435
+ {%- elif _is_steering and _has_inline %}
436
+ {#- Multi-modal aware strip: clean text items, keep image/video parts. -#}
437
+ {%- if msg.content is string %}
438
+ {%- set _clean = strip_control_tags(_txt) | trim %}
439
+ {%- set store.messages = store.messages + [{'role': _role, 'content': _clean}] %}
440
+ {%- elif msg.content is iterable and msg.content is not mapping %}
441
+ {%- set _nc = namespace(items=[]) %}
442
+ {%- for item in msg.content %}
443
+ {%- if item is mapping and 'text' in item and item.text is string %}
444
+ {%- set _nc.items = _nc.items + [{'type': 'text', 'text': strip_control_tags(item.text) | trim}] %}
445
+ {%- else %}
446
+ {%- set _nc.items = _nc.items + [item] %}
447
+ {%- endif %}
448
+ {%- endfor %}
449
+ {%- set store.messages = store.messages + [{'role': _role, 'content': _nc.items}] %}
450
+ {%- else %}
451
+ {%- set store.messages = store.messages + [msg] %}
452
+ {%- endif %}
453
+ {%- else %}
454
+ {%- set store.messages = store.messages + [msg] %}
455
+ {%- endif %}
456
+ {%- endfor %}
457
+ {%- set messages = store.messages %}
458
+ {%- set _depth_explicit = (_depth_explicit or store.saw_inline) %}
459
+
460
+ {#- Continuous depth: pure integers 10-100 map onto the spectrum band. -#}
461
+ {#- 0-9 stay legacy level numbers so old clients keep exact behaviour. -#}
462
+ {#- NB: int-filter round-trip instead of .isdigit() — minja (llama.cpp) -#}
463
+ {#- does not implement string.isdigit(). -#}
464
+ {%- set _eff_int = ns_state.effort | int %}
465
+ {%- if ns_state.mode == 'level' and ns_state.effort is string and (_eff_int | string) == ns_state.effort and _eff_int >= 10 %}
466
+ {%- set _n = ns_state.effort | int %}
467
+ {%- set ns_state.thinking = true %}
468
+ {%- if _n <= 14 %}
469
+ {%- set ns_state.effort = '1' %}
470
+ {%- elif _n <= 29 %}
471
+ {%- set ns_state.effort = '2' %}
472
+ {%- elif _n <= 44 %}
473
+ {%- set ns_state.effort = '3' %}
474
+ {%- elif _n <= 59 %}
475
+ {%- set ns_state.effort = '4' %}
476
+ {%- elif _n <= 69 %}
477
+ {%- set ns_state.effort = '5' %}
478
+ {%- elif _n <= 79 %}
479
+ {%- set ns_state.effort = '6' %}
480
+ {%- elif _n <= 89 %}
481
+ {%- set ns_state.effort = '7' %}
482
+ {%- elif _n <= 96 %}
483
+ {%- set ns_state.effort = '8' %}
484
+ {%- else %}
485
+ {%- set ns_state.effort = '9' %}
486
+ {%- endif %}
487
+ {%- endif %}
488
+
489
+ {#- Depth-tool coupling, part A: trailing tool-failure streak pre-pass. -#}
490
+ {%- set _streak = namespace(value=0) %}
491
+ {%- for msg in messages %}
492
+ {%- if msg.role == 'tool' %}
493
+ {%- set _tc = scan_text(msg.content) | trim %}
494
+ {%- if classify_tool_output(_tc) | trim == 'error' %}
495
+ {%- set _streak.value = _streak.value + 1 %}
496
+ {%- else %}
497
+ {%- set _streak.value = 0 %}
498
+ {%- endif %}
499
+ {%- elif msg.role == 'user' %}
500
+ {%- set _streak.value = 0 %}
501
+ {%- endif %}
502
+ {%- endfor %}
503
+
504
+ {#- Depth-tool coupling, part B: state adjustment BEFORE rendering. -#}
505
+ {#- Collapse: tools attached, no explicit depth signal → [L4]. -#}
506
+ {#- Escalate: 2+ consecutive tool failures → +1 band, capped at [L7]. -#}
507
+ {#- Swarm/council profiles are never auto-tuned (non-numeric effort). -#}
508
+ {%- if _has_tools and not _depth_explicit and ns_state.thinking %}
509
+ {%- set ns_state.effort = '4' %}
510
+ {%- endif %}
511
+ {%- if _streak.value >= 2 and ns_state.thinking %}
512
+ {%- set _cur = ns_state.effort if ns_state.effort else '7' %}
513
+ {%- if _cur == '1' %}
514
+ {%- set ns_state.effort = '2' %}
515
+ {%- elif _cur == '2' %}
516
+ {%- set ns_state.effort = '3' %}
517
+ {%- elif _cur == '3' %}
518
+ {%- set ns_state.effort = '4' %}
519
+ {%- elif _cur == '4' %}
520
+ {%- set ns_state.effort = '5' %}
521
+ {%- elif _cur == '5' %}
522
+ {%- set ns_state.effort = '6' %}
523
+ {%- elif _cur == '6' %}
524
+ {%- set ns_state.effort = '7' %}
525
+ {%- elif _cur in ('7', '8', '9') %}
526
+ {%- set ns_state.effort = '7' %}
527
+ {%- endif %}
528
+ {%- endif %}
529
+
530
+ {#- Alias resolver: number / name / compat alias → profile. Runs AFTER -#}
531
+ {#- coupling, so the rendered profile always matches the final effort. -#}
532
+ {#- Unknown input degrades gracefully to [L7]; it never hard-fails. -#}
533
+ {#- Silent modes (i-prefix) still inject the depth profile: the model -#}
534
+ {#- reasons at that quality internally while thinking tags stay closed. -#}
535
+ {%- set reasoning_instructions = '' %}
536
+ {%- if ns_state.thinking or ns_state.silent_profile %}
537
+ {%- set target_mode = ns_state.effort if ns_state.effort else '7' %}
538
+ {%- if target_mode in ('1', 'hermes', 'ulow', 'ultra-low', 'micro', 'minimal') %}
539
+ {%- set reasoning_instructions = inst_hermes %}
540
+ {%- elif target_mode in ('2', 'apollo', 'low') %}
541
+ {%- set reasoning_instructions = inst_apollo %}
542
+ {%- elif target_mode in ('3', 'artemis', 'lmed', 'low-medium') %}
543
+ {%- set reasoning_instructions = inst_artemis %}
544
+ {%- elif target_mode in ('4', 'athena', 'medium', 'med') %}
545
+ {%- set reasoning_instructions = inst_athena %}
546
+ {%- elif target_mode in ('5', 'prometheus', 'mhigh', 'medium-high') %}
547
+ {%- set reasoning_instructions = inst_prometheus %}
548
+ {%- elif target_mode in ('6', 'solstice', 'high') %}
549
+ {%- set reasoning_instructions = inst_solstice %}
550
+ {%- elif target_mode in ('7', 'hyperion', 'xhigh', 'default', 'extreme') %}
551
+ {%- set reasoning_instructions = inst_hyperion %}
552
+ {%- elif target_mode in ('8', 'einstein', 'uhigh', 'ultra-high') %}
553
+ {%- set reasoning_instructions = inst_einstein %}
554
+ {%- elif target_mode in ('9', 'oracle', 'amax', 'max', 'absolute-max') %}
555
+ {%- set reasoning_instructions = inst_oracle %}
556
+ {%- elif target_mode in ('swarm', 'einstein-swarm', '20-swarm', 'uhigh-swarm', 'divergent') %}
557
+ {%- set reasoning_instructions = inst_swarm %}
558
+ {%- elif target_mode in ('deep-swarm', 'oracle-swarm', 'council', 'amax-swarm', 'deep-research', 'spoon', 'adversarial') %}
559
+ {%- set reasoning_instructions = inst_deep_swarm %}
560
+ {%- else %}
561
+ {%- set reasoning_instructions = inst_hyperion %}
562
+ {%- endif %}
563
+ {%- endif %}
564
+
565
+ {#- ================================================================== -#}
566
+ {#- S3 RENDER PIPELINE — ChatML emission. -#}
567
+ {#- ================================================================== -#}
568
+
569
+ {#- Leading system-message grouping. -#}
570
+ {%- set head = namespace(count=0, seen_non_system=false) %}
571
+ {%- for message in messages %}
572
+ {%- set _is_sys = (message.role == 'system' or message.role == 'developer') %}
573
+ {%- if _is_sys and not head.seen_non_system %}
574
+ {%- set head.count = head.count + 1 %}
575
+ {%- else %}
576
+ {%- set head.seen_non_system = true %}
577
+ {%- endif %}
578
+ {%- endfor %}
579
+ {%- set sys_state = namespace(content='') %}
580
+ {%- for message in messages[:head.count] %}
581
+ {%- set _part = render_content(message.content, false) | trim %}
582
+ {%- if _part %}
583
+ {%- if sys_state.content %}
584
+ {%- set sys_state.content = sys_state.content ~ '\n\n' ~ _part %}
585
+ {%- else %}
586
+ {%- set sys_state.content = _part %}
587
+ {%- endif %}
588
+ {%- endif %}
589
+ {%- endfor %}
590
+ {%- set _sc = sys_state.content %}
591
+ {%- set _msgs = messages[head.count:] %}
592
+
593
+ {%- set _terse_active = terse if terse is defined else (not is_explicit_regular) %}
594
+ {%- if _terse_active %}
595
+ {%- if not _sc %}
596
+ {%- set _sc = terse_core | trim %}
597
+ {%- else %}
598
+ {%- set _sc = (_sc | trim) ~ '\n\n' ~ (terse_core | trim) %}
599
+ {%- endif %}
600
+ {%- endif %}
601
+
602
+ {#- Some runtimes prepend their own tool protocol; stand down if seen. -#}
603
+ {%- set _runtime_tool_protocol = (_sc is defined and _sc and '[TOOL_REQUEST]' in _sc) %}
604
+ {%- if suppress_tool_instructions is not none %}
605
+ {%- set _suppress_tools = suppress_tool_instructions %}
606
+ {%- else %}
607
+ {%- set _suppress_tools = _runtime_tool_protocol %}
608
+ {%- endif %}
609
+
610
+ {{- bos_token -}}\n{#- System emission: profile + soft contract + tools. -#}
611
+ {%- if reasoning_instructions or _sc or (_has_tools and not _suppress_tools) %}
612
+ {{- '<|start_header_id|>system<|end_header_id|>\n\n' }}
613
+ {%- if reasoning_instructions %}
614
+ {{- reasoning_instructions ~ '\n\n' ~ soft_budget_contract ~ '\n\n' }}
615
+ {%- endif %}
616
+ {%- if _has_tools and not _suppress_tools %}
617
+ {{- '# Tools\n\nYou have access to the following functions:\n\n<tools>' }}
618
+ {%- for tool in tools %}
619
+ {{- '\n' }}
620
+ {{- tool | tojson }}
621
+ {%- endfor %}
622
+ {{- '\n</tools>' }}
623
+ {%- if _tool_format == 'json' %}
624
+ {{- '\n\nIf you choose to call a function ONLY reply in the following format with NO suffix:\n\n' }}
625
+ {%- if ns_state.thinking %}
626
+ {{- '<think>\nBrief explanation of tool call\n</think>\n' }}
627
+ {%- endif %}
628
+ {{- '<tool_call>\n{"name": "example_function_name", "arguments": {"example_parameter_1": "value_1", "example_parameter_2": "This is the value for the second parameter"}}\n</tool_call>\n\n<IMPORTANT>\nReminder:\n' }}
629
+ {{- '- Function calls MUST follow the specified format: a single JSON object with "name" and "arguments" keys inside <tool_call></tool_call> XML tags.\n- The <tool_call> tag MUST be at the very beginning of a new line.\n- To call multiple functions, output a separate, completely closed <tool_call></tool_call> block for EACH function. Do NOT nest <tool_call> blocks.\n- If you have all necessary data, provide your final answer directly to the user without any tool call.\n</IMPORTANT>' }}
630
+ {%- else %}
631
+ {{- '\n\nIf you choose to call a function ONLY reply in the following format with NO suffix:\n\n' }}
632
+ {%- if ns_state.thinking %}
633
+ {{- '<think>\nBrief explanation of tool call\n</think>\n' }}
634
+ {%- endif %}
635
+ {{- '<tool_call>\n<function=example_function_name>\n<parameter=example_parameter_1>\nvalue_1\n</parameter>\n<parameter=example_parameter_2>\nThis is the value for the second parameter\n</parameter>\n</function>\n</tool_call>\n\n<IMPORTANT>\nReminder:\n' }}
636
+ {{- '- Function calls MUST follow the specified format: an inner <function=...></function> block must be nested within <tool_call></tool_call> XML tags.\n- The <tool_call> and <function> tags MUST be at the very beginning of a new line.\n- To call multiple functions, output a separate, completely closed <tool_call></tool_call> block for EACH function. Do NOT nest <tool_call> blocks.\n- If you have all necessary data, provide your final answer directly to the user without any tool call.\n</IMPORTANT>' }}
637
+ {%- endif %}
638
+ {%- if _sc %}
639
+ {{- '\n\n' + _sc }}
640
+ {%- endif %}
641
+ {{- '<|eot_id|>\n' }}
642
+ {%- else %}
643
+ {%- if _sc %}
644
+ {{- _sc + '<|eot_id|>\n' }}
645
+ {%- else %}
646
+ {{- '<|eot_id|>\n' }}
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] %}
655
+ {%- set index = (_msgs | length - 1) - loop.index0 %}
656
+ {%- if ns.multi_step_tool and message.role == 'user' %}
657
+ {%- set _rc = render_content(message.content, false) | trim %}
658
+ {%- if not (_rc.startswith('<tool_response>') and _rc.endswith('</tool_response>')) %}
659
+ {%- set ns.multi_step_tool = false %}
660
+ {%- set ns.last_query_index = index %}
661
+ {%- endif %}
662
+ {%- endif %}
663
+ {%- endfor %}
664
+ {%- if ns.multi_step_tool %}
665
+ {%- if _last_idx > 50 %}
666
+ {%- set ns.last_query_index = _last_idx %}
667
+ {%- else %}
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") %}
676
+ {%- set content = render_content(message.content, true, is_system) | trim %}
677
+ {%- if is_system %}
678
+ {{- '<|start_header_id|>system<|end_header_id|>\n\n' + content + '<|eot_id|>\n' }}
679
+ {%- elif message.role == 'user' %}
680
+ {%- set ns2.consecutive_failures = 0 %}
681
+ {{- '<|start_header_id|>user<|end_header_id|>\n\n' + strip_control_tags(content) + '<|eot_id|>\n' }}
682
+ {%- elif message.role == 'assistant' %}
683
+ {%- set reasoning_content = '' %}
684
+ {%- set _explicit_reasoning = '' %}
685
+ {%- if message.reasoning_content is defined and message.reasoning_content is not none %}
686
+ {%- if message.reasoning_content is string %}
687
+ {%- set _explicit_reasoning = message.reasoning_content %}
688
+ {%- else %}
689
+ {%- set _explicit_reasoning = message.reasoning_content | string %}
690
+ {%- endif %}
691
+ {%- elif message.thinking is defined and message.thinking is not none %}
692
+ {%- if message.thinking is string %}
693
+ {%- set _explicit_reasoning = message.thinking %}
694
+ {%- else %}
695
+ {%- set _explicit_reasoning = message.thinking | string %}
696
+ {%- endif %}
697
+ {%- elif message.reasoning is defined and message.reasoning is not none %}
698
+ {%- if message.reasoning is string %}
699
+ {%- set _explicit_reasoning = message.reasoning %}
700
+ {%- else %}
701
+ {%- set _explicit_reasoning = message.reasoning | string %}
702
+ {%- endif %}
703
+ {%- endif %}
704
+ {%- if _explicit_reasoning %}
705
+ {%- set _lead_end = '' %}
706
+ {%- if content.startswith('<think>') and '</think>' in content %}
707
+ {%- set _lead_end = '</think>' %}
708
+ {%- elif content.startswith('<thinking>') and '</thinking>' in content %}
709
+ {%- set _lead_end = '</thinking>' %}
710
+ {%- elif content.startswith('</think>') %}
711
+ {%- set _lead_end = '</think>' %}
712
+ {%- elif content.startswith('</thinking>') %}
713
+ {%- set _lead_end = '</thinking>' %}
714
+ {%- endif %}
715
+ {%- if _lead_end %}
716
+ {%- set content = content.split(_lead_end)[-1].lstrip('\n') %}
717
+ {%- endif %}
718
+ {%- set reasoning_content = _explicit_reasoning %}
719
+ {%- else %}
720
+ {%- set _think_end = '' %}
721
+ {%- if content.startswith('</think>') %}
722
+ {%- set _think_end = '</think>' %}
723
+ {%- elif content.startswith('</thinking>') %}
724
+ {%- set _think_end = '</thinking>' %}
725
+ {%- elif '\n</think>' in content %}
726
+ {%- set _think_end = '\n</think>' %}
727
+ {%- elif '\n</thinking>' in content %}
728
+ {%- set _think_end = '\n</thinking>' %}
729
+ {%- elif '\n</ think>' in content %}
730
+ {%- set _think_end = '\n</ think>' %}
731
+ {%- elif '\n</think >' in content %}
732
+ {%- set _think_end = '\n</think >' %}
733
+ {%- elif content.startswith('<think>') and '</think>' in content %}
734
+ {%- set _think_end = '</think>' %}
735
+ {%- elif content.startswith('<thinking>') and '</thinking>' in content %}
736
+ {%- set _think_end = '</thinking>' %}
737
+ {%- endif %}
738
+ {%- if _think_end %}
739
+ {%- if 'thinking' in _think_end %}
740
+ {%- set _think_start = '<thinking>' %}
741
+ {%- else %}
742
+ {%- set _think_start = '<think>' %}
743
+ {%- endif %}
744
+ {%- set reasoning_content = content.split(_think_end)[0].rstrip('\n') %}
745
+ {%- if _think_start in reasoning_content %}
746
+ {%- set reasoning_content = reasoning_content.split(_think_start)[-1].lstrip('\n') %}
747
+ {%- endif %}
748
+ {%- set content = content.split(_think_end)[-1].lstrip('\n') %}
749
+ {%- endif %}
750
+ {%- endif %}
751
+ {%- set reasoning_content = reasoning_content | trim %}
752
+ {%- if (_preserve_thinking or loop.index0 > ns.last_query_index) %}
753
+ {{- '<|start_header_id|>assistant<|end_header_id|>\n\n<think>\n' + reasoning_content + '\n</think>\n\n' + content }}
754
+ {%- else %}
755
+ {{- '<|start_header_id|>assistant<|end_header_id|>\n\n' + content }}
756
+ {%- endif %}
757
+ {%- if message.tool_calls is defined and message.tool_calls and message.tool_calls is iterable and message.tool_calls is not mapping %}
758
+ {%- for tool_call in message.tool_calls %}
759
+ {%- if tool_call.function is defined and tool_call.function is not none %}
760
+ {%- set tc = tool_call.function %}
761
+ {%- else %}
762
+ {%- set tc = tool_call %}
763
+ {%- endif %}
764
+ {%- set tc_name = tc.name if (tc.name is defined and tc.name is not none) else '' %}
765
+ {%- if _tool_format == 'json' %}
766
+ {%- if loop.first %}
767
+ {%- if content | trim %}
768
+ {{- '\n\n' }}
769
+ {%- endif %}
770
+ {%- else %}
771
+ {{- '\n' }}
772
+ {%- endif %}
773
+ {%- set _args = '{}' %}
774
+ {%- if tc.arguments is defined and tc.arguments is not none %}
775
+ {%- if tc.arguments is mapping %}
776
+ {%- set _args = tc.arguments | tojson %}
777
+ {%- elif tc.arguments is string %}
778
+ {%- if tc.arguments %}
779
+ {%- set _args = tc.arguments %}
780
+ {%- endif %}
781
+ {%- else %}
782
+ {%- set _args = tc.arguments | tojson %}
783
+ {%- endif %}
784
+ {%- endif %}
785
+ {{- '<tool_call>\n{"name": ' }}{{- tc_name | tojson }}{{- ', "arguments": ' }}{{- _args }}{{- '}\n</tool_call>' }}
786
+ {%- else %}
787
+ {%- if loop.first %}
788
+ {%- if content | trim %}
789
+ {{- '\n\n<tool_call>\n<function=' + tc_name + '>\n' }}
790
+ {%- else %}
791
+ {{- '<tool_call>\n<function=' + tc_name + '>\n' }}
792
+ {%- endif %}
793
+ {%- else %}
794
+ {{- '\n<tool_call>\n<function=' + tc_name + '>\n' }}
795
+ {%- endif %}
796
+ {%- if tc.arguments is defined and tc.arguments is not none %}
797
+ {%- if tc.arguments is mapping %}
798
+ {%- for args_name, args_value in tc.arguments.items() %}
799
+ {{- '<parameter=' + args_name + '>\n' }}
800
+ {%- if args_value is string %}
801
+ {%- set _av = args_value %}
802
+ {%- else %}
803
+ {%- set _av = args_value | tojson %}
804
+ {%- endif %}
805
+ {%- if max_tool_arg_chars > 0 and _av | length > max_tool_arg_chars %}
806
+ {{- _av[:max_tool_arg_chars] + '\n[TRUNCATED - original length ' ~ (_av | length | string) ~ ' chars]' }}
807
+ {%- else %}
808
+ {{- _av }}
809
+ {%- endif %}
810
+ {{- '\n</parameter>\n' }}
811
+ {%- endfor %}
812
+ {%- else %}
813
+ {%- if tc.arguments is string %}
814
+ {%- set _raw_args = tc.arguments %}
815
+ {%- else %}
816
+ {%- set _raw_args = tc.arguments | tojson %}
817
+ {%- endif %}
818
+ {%- if _raw_args %}
819
+ {%- if max_tool_arg_chars > 0 and _raw_args | length > max_tool_arg_chars %}
820
+ {{- _raw_args[:max_tool_arg_chars] + '\n[TRUNCATED - original length ' ~ (_raw_args | length | string) ~ ' chars]' }}
821
+ {%- else %}
822
+ {{- _raw_args }}
823
+ {%- endif %}
824
+ {%- endif %}
825
+ {%- endif %}
826
+ {%- endif %}
827
+ {{- '</function>\n</tool_call>' }}
828
+ {%- endif %}
829
+ {%- endfor %}
830
+ {%- endif %}
831
+ {{- '<|eot_id|>\n' }}
832
+ {%- elif message.role == 'tool' %}
833
+ {%- if classify_tool_output(content) | trim == 'error' %}
834
+ {%- set ns2.consecutive_failures = ns2.consecutive_failures + 1 %}
835
+ {%- else %}
836
+ {%- set ns2.consecutive_failures = 0 %}
837
+ {%- endif %}
838
+ {%- if ns2.prev_role != 'tool' %}
839
+ {{- '<|start_header_id|>user<|end_header_id|>\n\n' }}
840
+ {%- endif %}
841
+ {%- set _is_json_payload = (_tool_format == 'json' and content | trim | length > 0 and (content | trim)[:1] in ('{', '[')) %}
842
+ {%- if not _is_json_payload and max_tool_response_chars > 0 and content | length > max_tool_response_chars %}
843
+ {%- set content = content[:max_tool_response_chars] + '\n[TRUNCATED - original length ' ~ (content | length | string) ~ ' chars]' %}
844
+ {%- endif %}
845
+ {{- '\n<tool_response>\n' + content }}
846
+ {%- if ns2.consecutive_failures >= 2 %}
847
+ {{- '\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.' }}
848
+ {%- elif ns2.consecutive_failures == 1 %}
849
+ {{- '\n\n⚠️ SYSTEM WARNING: The previous tool call returned an error. Diagnose the failure and retry with completely corrected arguments.' }}
850
+ {%- endif %}
851
+ {{- '\n</tool_response>' }}
852
+ {%- if loop.last %}
853
+ {{- '<|eot_id|>\n' }}
854
+ {%- else %}
855
+ {%- set _next_role = _msgs[loop.index0 + 1].role %}
856
+ {%- if _next_role != 'tool' %}
857
+ {{- '<|eot_id|>\n' }}
858
+ {%- endif %}
859
+ {%- endif %}
860
+ {%- else %}
861
+ {{- '<|start_header_id|>user<|end_header_id|>\n\n[' + message.role + ']: ' + content + '<|eot_id|>\n' }}
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 %}
869
+ {{- '<|start_header_id|>assistant<|end_header_id|>\n\n' }}
870
+ {%- if is_explicit_regular %}
871
+ {#- Pure regular mode: no think block -#}
872
+ {%- elif not ns_state.thinking %}
873
+ {{- '<think>\n\n</think>\n\n' }}
874
+ {%- else %}
875
+ {{- '<think>\n' }}
876
+ {%- endif %}
877
+ {%- endif %}