SolsticeAI commited on
Commit
4fb7470
·
verified ·
1 Parent(s): 6f00192

feat: update to Solstice 10-level solo + swarm cognitive architecture

Browse files
Files changed (1) hide show
  1. chat_template.jinja +347 -170
chat_template.jinja CHANGED
@@ -1,170 +1,347 @@
1
- {%- set image_count = namespace(value=0) %}
2
- {%- set video_count = namespace(value=0) %}
3
- {%- macro render_content(content, do_vision_count, is_system_content=false) %}
4
- {%- if content is string %}
5
- {{- content }}
6
- {%- elif content is iterable and content is not mapping %}
7
- {%- for item in content %}
8
- {%- if 'image' in item or 'image_url' in item or item.type == 'image' %}
9
- {%- if is_system_content %}
10
- {{- raise_exception('System message cannot contain images.') }}
11
- {%- endif %}
12
- {%- if do_vision_count %}
13
- {%- set image_count.value = image_count.value + 1 %}
14
- {%- endif %}
15
- {%- if add_vision_id %}
16
- {{- 'Picture ' ~ image_count.value ~ ': ' }}
17
- {%- endif %}
18
- {{- '<|vision_start|><|image_pad|><|vision_end|>' }}
19
- {%- elif 'video' in item or item.type == 'video' %}
20
- {%- if is_system_content %}
21
- {{- raise_exception('System message cannot contain videos.') }}
22
- {%- endif %}
23
- {%- if do_vision_count %}
24
- {%- set video_count.value = video_count.value + 1 %}
25
- {%- endif %}
26
- {%- if add_vision_id %}
27
- {{- 'Video ' ~ video_count.value ~ ': ' }}
28
- {%- endif %}
29
- {{- '<|vision_start|><|video_pad|><|vision_end|>' }}
30
- {%- elif 'text' in item %}
31
- {{- item.text }}
32
- {%- else %}
33
- {{- raise_exception('Unexpected item type in content.') }}
34
- {%- endif %}
35
- {%- endfor %}
36
- {%- elif content is none or content is undefined %}
37
- {{- '' }}
38
- {%- else %}
39
- {{- raise_exception('Unexpected content type.') }}
40
- {%- endif %}
41
- {%- endmacro %}
42
- {%- if not messages %}
43
- {{- raise_exception('No messages provided.') }}
44
- {%- endif %}
45
- {%- set reasoning_instructions = '' %}
46
- {%- if enable_thinking is undefined or enable_thinking is true %}
47
- {%- set resolved_reasoning_effort = reasoning_effort|default('xhigh') %}
48
- {%- if resolved_reasoning_effort not in ('xhigh', 'medium', 'low') %}
49
- {{- raise_exception('Unexpected reasoning effort ' ~ reasoning_effort ~ '. Supported types are xhigh (default), medium, and low.') }}
50
- {%- endif %}
51
- {%- if resolved_reasoning_effort == 'xhigh' %}
52
- {%- set reasoning_instructions = 'Reasoning effort is set to xhigh. Please think carefully through the task, validate key assumptions, consider plausible alternatives, and prioritize correctness, consistency, and clarity in the final answer.' %}
53
- {%- elif resolved_reasoning_effort == 'low' %}
54
- {%- set reasoning_instructions = 'Reasoning effort is set to low. Keep your thinking brief and focused, moving directly to the conclusion without unnecessary elaboration.' %}
55
- {%- endif %}
56
- {%- endif %}
57
- {%- if tools and tools is iterable and tools is not mapping %}
58
- {{- '<|im_start|>system\n' }}
59
- {%- if reasoning_instructions %}
60
- {{- reasoning_instructions + '\n\n' }}
61
- {%- endif %}
62
- {{- "# Tools\n\nYou have access to the following functions:\n\n<tools>" }}
63
- {%- for tool in tools %}
64
- {{- "\n" }}
65
- {{- tool | tojson }}
66
- {%- endfor %}
67
- {{- "\n</tools>" }}
68
- {{- '\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>' }}
69
- {%- if messages[0].role == 'system' %}
70
- {%- set content = render_content(messages[0].content, false, true)|trim %}
71
- {%- if content %}
72
- {{- '\n\n' + content }}
73
- {%- endif %}
74
- {%- endif %}
75
- {{- '<|im_end|>\n' }}
76
- {%- else %}
77
- {%- if messages[0].role == 'system' %}
78
- {%- set content = render_content(messages[0].content, false, true)|trim %}
79
- {%- if content %}
80
- {{- '<|im_start|>system\n' + (reasoning_instructions + '\n\n' if reasoning_instructions else '') + content + '<|im_end|>\n' }}
81
- {%- elif reasoning_instructions %}
82
- {{- '<|im_start|>system\n' + reasoning_instructions + '<|im_end|>\n' }}
83
- {%- endif %}
84
- {%- elif reasoning_instructions %}
85
- {{- '<|im_start|>system\n' + reasoning_instructions + '<|im_end|>\n' }}
86
- {%- endif %}
87
- {%- endif %}
88
- {%- set ns = namespace(multi_step_tool=true, last_query_index=messages|length - 1) %}
89
- {%- for message in messages[::-1] %}
90
- {%- set index = (messages|length - 1) - loop.index0 %}
91
- {%- if ns.multi_step_tool and message.role == "user" %}
92
- {%- set content = render_content(message.content, false)|trim %}
93
- {%- if not(content.startswith('<tool_response>') and content.endswith('</tool_response>')) %}
94
- {%- set ns.multi_step_tool = false %}
95
- {%- set ns.last_query_index = index %}
96
- {%- endif %}
97
- {%- endif %}
98
- {%- endfor %}
99
- {%- if ns.multi_step_tool %}
100
- {{- raise_exception('No user query found in messages.') }}
101
- {%- endif %}
102
- {%- for message in messages %}
103
- {%- set content = render_content(message.content, true)|trim %}
104
- {%- if message.role == "system" %}
105
- {%- if not loop.first %}
106
- {{- raise_exception('System message must be at the beginning.') }}
107
- {%- endif %}
108
- {%- elif message.role == "user" %}
109
- {{- '<|im_start|>' + message.role + '\n' + content + '<|im_end|>' + '\n' }}
110
- {%- elif message.role == "assistant" %}
111
- {%- set reasoning_content = '' %}
112
- {%- if message.reasoning_content is string %}
113
- {%- set reasoning_content = message.reasoning_content %}
114
- {%- endif %}
115
- {%- set reasoning_content = reasoning_content|trim %}
116
- {%- if preserve_thinking is undefined or preserve_thinking is true or loop.index0 > ns.last_query_index %}
117
- {{- '<|im_start|>' + message.role + '\n<think>\n' + reasoning_content + '\n</think>\n\n' + content }}
118
- {%- else %}
119
- {{- '<|im_start|>' + message.role + '\n' + content }}
120
- {%- endif %}
121
- {%- if message.tool_calls and message.tool_calls is iterable and message.tool_calls is not mapping %}
122
- {%- for tool_call in message.tool_calls %}
123
- {%- if tool_call.function is defined %}
124
- {%- set tool_call = tool_call.function %}
125
- {%- endif %}
126
- {%- if loop.first %}
127
- {%- if content|trim %}
128
- {{- '\n\n<tool_call>\n<function=' + tool_call.name + '>\n' }}
129
- {%- else %}
130
- {{- '<tool_call>\n<function=' + tool_call.name + '>\n' }}
131
- {%- endif %}
132
- {%- else %}
133
- {{- '\n<tool_call>\n<function=' + tool_call.name + '>\n' }}
134
- {%- endif %}
135
- {%- if tool_call.arguments is defined and tool_call.arguments != '' %}
136
- {%- for args_name, args_value in tool_call.arguments|items %}
137
- {{- '<parameter=' + args_name + '>\n' }}
138
- {%- set args_value = args_value | string if args_value is string else args_value | tojson | safe %}
139
- {{- args_value }}
140
- {{- '\n</parameter>\n' }}
141
- {%- endfor %}
142
- {%- endif %}
143
- {{- '</function>\n</tool_call>' }}
144
- {%- endfor %}
145
- {%- endif %}
146
- {{- '<|im_end|>\n' }}
147
- {%- elif message.role == "tool" %}
148
- {%- if loop.previtem and loop.previtem.role != "tool" %}
149
- {{- '<|im_start|>user' }}
150
- {%- endif %}
151
- {{- '\n<tool_response>\n' }}
152
- {{- content }}
153
- {{- '\n</tool_response>' }}
154
- {%- if not loop.last and loop.nextitem.role != "tool" %}
155
- {{- '<|im_end|>\n' }}
156
- {%- elif loop.last %}
157
- {{- '<|im_end|>\n' }}
158
- {%- endif %}
159
- {%- else %}
160
- {{- raise_exception('Unexpected message role.') }}
161
- {%- endif %}
162
- {%- endfor %}
163
- {%- if add_generation_prompt %}
164
- {{- '<|im_start|>assistant\n' }}
165
- {%- if enable_thinking is defined and enable_thinking is false %}
166
- {{- '<think>\n\n</think>\n\n' }}
167
- {%- else %}
168
- {{- '<think>\n' }}
169
- {%- endif %}
170
- {%- endif %}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {#- ================================================================= -#}
2
+ {#- Solstice-AI 10-Level Cognitive Reasoning & Instruct Chat Template -#}
3
+ {#- Tailored for Qwen3.8 / Qwopus ChatML Architecture -#}
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
+ {%- set ns = namespace(multi_step_tool=true, last_query_index=messages|length - 1) -%}
266
+ {%- for message in messages[::-1] -%}
267
+ {%- set index = (messages|length - 1) - loop.index0 -%}
268
+ {%- if ns.multi_step_tool and message.role == "user" -%}
269
+ {%- set content = render_content(message.content, false)|trim -%}
270
+ {%- if not(content.startswith('<tool_response>') and content.endswith('</tool_response>')) -%}
271
+ {%- set ns.multi_step_tool = false -%}
272
+ {%- set ns.last_query_index = index -%}
273
+ {%- endif -%}
274
+ {%- endif -%}
275
+ {%- endfor -%}
276
+ {%- if ns.multi_step_tool -%}
277
+ {{- raise_exception('No user query found in messages.') -}}
278
+ {%- endif -%}
279
+ {%- for message in messages -%}
280
+ {%- set content = render_content(message.content, true)|trim -%}
281
+ {%- if message.role == "system" -%}
282
+ {%- if not loop.first -%}
283
+ {{- raise_exception('System message must be at the beginning.') -}}
284
+ {%- endif -%}
285
+ {%- elif message.role == "user" -%}
286
+ {{- '<|im_start|>' + message.role + '\n' + content + '<|im_end|>\n' -}}
287
+ {%- elif message.role == "assistant" -%}
288
+ {%- set reasoning_content = '' -%}
289
+ {%- if message.reasoning_content is string -%}
290
+ {%- set reasoning_content = message.reasoning_content -%}
291
+ {%- endif -%}
292
+ {%- set reasoning_content = reasoning_content|trim -%}
293
+ {%- if preserve_thinking is undefined or preserve_thinking is true or loop.index0 > ns.last_query_index -%}
294
+ {{- '<|im_start|>' + message.role + '\n<think>\n' + reasoning_content + '\n</think>\n\n' + content -}}
295
+ {%- else -%}
296
+ {{- '<|im_start|>' + message.role + '\n' + content -}}
297
+ {%- endif -%}
298
+ {%- if message.tool_calls and message.tool_calls is iterable and message.tool_calls is not mapping -%}
299
+ {%- for tool_call in message.tool_calls -%}
300
+ {%- if tool_call.function is defined -%}
301
+ {%- set tool_call = tool_call.function -%}
302
+ {%- endif -%}
303
+ {%- if loop.first -%}
304
+ {%- if content|trim -%}
305
+ {{- '\n\n<tool_call>\n<function=' + tool_call.name + '>\n' -}}
306
+ {%- else -%}
307
+ {{- '<tool_call>\n<function=' + tool_call.name + '>\n' -}}
308
+ {%- endif -%}
309
+ {%- else -%}
310
+ {{- '\n<tool_call>\n<function=' + tool_call.name + '>\n' -}}
311
+ {%- endif -%}
312
+ {%- if tool_call.arguments is defined and tool_call.arguments != '' -%}
313
+ {%- for args_name, args_value in tool_call.arguments|items -%}
314
+ {{- '<parameter=' + args_name + '>\n' -}}
315
+ {%- set args_value = args_value | string if args_value is string else args_value | tojson | safe -%}
316
+ {{- args_value -}}
317
+ {{- '\n</parameter>\n' -}}
318
+ {%- endfor -%}
319
+ {%- endif -%}
320
+ {{- '</function>\n</tool_call>' -}}
321
+ {%- endfor -%}
322
+ {%- endif -%}
323
+ {{- '<|im_end|>\n' -}}
324
+ {%- elif message.role == "tool" -%}
325
+ {%- if loop.previtem and loop.previtem.role != "tool" -%}
326
+ {{- '<|im_start|>user' -}}
327
+ {%- endif -%}
328
+ {{- '\n<tool_response>\n' -}}
329
+ {{- content -}}
330
+ {{- '\n</tool_response>' -}}
331
+ {%- if not loop.last and loop.nextitem.role != "tool" -%}
332
+ {{- '<|im_end|>\n' -}}
333
+ {%- elif loop.last -%}
334
+ {{- '<|im_end|>\n' -}}
335
+ {%- endif -%}
336
+ {%- else -%}
337
+ {{- raise_exception('Unexpected message role.') -}}
338
+ {%- endif -%}
339
+ {%- endfor -%}
340
+ {%- if add_generation_prompt -%}
341
+ {{- '<|im_start|>assistant\n' -}}
342
+ {%- if not current_thinking -%}
343
+ {{- '<think>\n\n</think>\n\n' -}}
344
+ {%- else -%}
345
+ {{- '<think>\n' -}}
346
+ {%- endif -%}
347
+ {%- endif -%}