SolsticeAI commited on
Commit
71b5ee0
·
verified ·
1 Parent(s): 168ed78

feat: initial release of HyperSynapse-SAS multi-model & universal chat templates

Browse files
README.md ADDED
@@ -0,0 +1,157 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: mit
3
+ language:
4
+ - en
5
+ - zh
6
+ tags:
7
+ - chat-template
8
+ - jinja
9
+ - hypersynapse-sas
10
+ - cognitive-architecture
11
+ - reasoning
12
+ - multi-agent
13
+ - swarm
14
+ - deepseek
15
+ - qwen
16
+ - glm
17
+ - llama
18
+ - mistral
19
+ - gemma
20
+ - universal
21
+ pipeline_tag: text-generation
22
+ ---
23
+
24
+ <div align="center">
25
+
26
+ # 🧠 HyperSynapse-SAS (SelfAgentSwarm) Chat Templates
27
+ ### *The Unified 10-Level Cognitive Escalation & Autonomous Multi-Agent Swarm Framework*
28
+
29
+ [![Solstice AI](https://img.shields.io/badge/Solstice--AI-HyperSynapse--SAS-blueviolet?style=for-the-badge&logo=openai)](https://huggingface.co/Solstice-AI)
30
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg?style=for-the-badge)](https://opensource.org/licenses/MIT)
31
+ [![Model-Agnostic](https://img.shields.io/badge/Architecture-Model--Agnostic-success?style=for-the-badge)](https://huggingface.co/Solstice-AI/HyperSynapse-SAS-Chat-Templates)
32
+ [![Levels](https://img.shields.io/badge/Cognitive%20Levels-0%20to%209%20Solo-orange?style=for-the-badge)](https://huggingface.co/Solstice-AI/HyperSynapse-SAS-Chat-Templates)
33
+ [![Swarm](https://img.shields.io/badge/Swarm-20--Agent%20%2B%20Council-red?style=for-the-badge)](https://huggingface.co/Solstice-AI/HyperSynapse-SAS-Chat-Templates)
34
+
35
+ </div>
36
+
37
+ ---
38
+
39
+ ## 🌟 Overview
40
+
41
+ **HyperSynapse-SAS** (HyperSynapse Self-Agent Swarm) is a high-performance cognitive chat template framework that equips any Large Language Model with:
42
+ 1. **10-Level Solo Cognitive Escalation (`Level 0 Mortal` to `Level 9 Oracle`)**: Dynamically scale reasoning depth, token runway, and proof rigor per prompt without triggering multi-persona roleplay clutter.
43
+ 2. **Decoupled Multi-Agent Swarm Modes (`[swarm]` & `[deep-swarm]`)**: On-demand simulated 20-agent divergent swarms and adversarial consensus councils for massive, open-ended problem spaces.
44
+ 3. **Model-Agnostic / Universal Template**: A plug-and-play ChatML Jinja template compatible with **any modern LLM**, plus dedicated, fine-tuned templates for all major model families.
45
+
46
+ ---
47
+
48
+ ## 📁 Available Templates
49
+
50
+ | Template | File | Target Architectures & Families |
51
+ | :--- | :--- | :--- |
52
+ | **Universal (Model-Agnostic)** | [`templates/universal.jinja`](templates/universal.jinja) | Standard ChatML, vLLM, SGLang, llama.cpp, Ollama, LM Studio, Any LLM |
53
+ | **DeepSeek** | [`templates/deepseek.jinja`](templates/deepseek.jinja) | DeepSeek-V3, DeepSeek-V4, DeepSeek-V4.1 Flash, DSML Tool Calling |
54
+ | **Qwen** | [`templates/qwen.jinja`](templates/qwen.jinja) | Qwen 2.5, Qwen 3, Qwen 3.5, Qwen 3.8, Qwopus, QwQ |
55
+ | **GLM** | [`templates/glm.jinja`](templates/glm.jinja) | GLM-4, GLM-5.3, GLM Flash |
56
+ | **Llama** | [`templates/llama3.jinja`](templates/llama3.jinja) | Meta Llama 3, Llama 3.1, Llama 3.2, Llama 3.3, Llama 4 |
57
+ | **Mistral** | [`templates/mistral.jinja`](templates/mistral.jinja) | Mistral 7B/12B, Mixtral 8x7B/8x22B, Codestral, Pixtral |
58
+ | **Gemma** | [`templates/gemma.jinja`](templates/gemma.jinja) | Google Gemma 2, Gemma 3, Gemma 4 |
59
+
60
+ ---
61
+
62
+ ## 🎯 Cognitive Trigger Spectrum
63
+
64
+ Simply prepend a tag to your query or pass `--level X` in your system instructions:
65
+
66
+ ### Solo Cognitive Escalation (Pure Analytical Focus)
67
+
68
+ | Tag / Level | Persona / Archetype | Budget | Cognitive Modality |
69
+ | :--- | :--- | :--- | :--- |
70
+ | **`[Level 0]`** | **Mortal** | 0 tokens | **Instant Response**: CoT/thinking completely disabled. Rapid, direct execution with zero discursive fluff. |
71
+ | **`[Level 1]`** | **Hermes** | ~256 tokens | **Rapid Instinct**: Single-path heuristic sanity check before emitting answer. |
72
+ | **`[Level 2]`** | **Apollo** | ~512 tokens | **Crisp Logic**: Explicit step-by-step reasoning with edge-case validation. |
73
+ | **`[Level 3]`** | **Artemis** | ~1,024 tokens | **Boundary Hunter**: Focuses on edge cases, off-by-one errors, and null states. |
74
+ | **`[Level 4]`** | **Athena** | ~2,048 tokens | **Systemic Balance**: Second-order effects, system architecture, modular design. |
75
+ | **`[Level 5]`** | **Prometheus** | ~4,096 tokens | **Defensive Engineering**: Fault tolerance, production bottlenecks, failure mode audit. |
76
+ | **`[Level 6]`** | **Solstice** | ~8,192 tokens | **Deep Derivation**: Exhaustive theoretical derivation and mathematical mechanics. |
77
+ | **`[Level 7]`** | **Hyperion (Default)** | ~16,384 tokens | **Foundational Synthesis**: First-principles breakdown from ground axioms. |
78
+ | **`[Level 8]`** | **Einstein** | ~32,768 tokens | **Mastery & Invariants**: Theoretical proofs, deep algorithmic complexity analysis. |
79
+ | **`[Level 9]`** | **Oracle** | Unbounded | **Maximal Rigor**: Exhaustive search runway, proof-grade verification, definitive closure. |
80
+
81
+ ### Autonomous Multi-Agent Swarm Modes
82
+
83
+ | Trigger | Mode Name | Protocol & Behavior |
84
+ | :--- | :--- | :--- |
85
+ | **`[swarm]`** | **20-Agent Divergent Swarm** | Activates a simulated 20-perspective emergent swarm (Analytical Logician, Creative Maverick, Systems Engineer, Red-Teamer, Optimizer, Critic, Synthesizer) with divergent exploration followed by structured synthesis. |
86
+ | **`[deep-swarm]`** | **Adversarial Research Council** | Deploys a multi-round debate tournament pitting 3–5 specialized domain specialists against each other to falsify weak assumptions and converge on proof-grade deliverables. |
87
+
88
+ ---
89
+
90
+ ## 🚀 Quick Start
91
+
92
+ ### 1. Using the Universal Template in Python (`transformers`)
93
+ ```python
94
+ from transformers import AutoTokenizer
95
+
96
+ tokenizer = AutoTokenizer.from_pretrained("Qwen/Qwen2.5-7B-Instruct")
97
+
98
+ # Load the universal HyperSynapse-SAS template
99
+ with open("templates/universal.jinja") as f:
100
+ tokenizer.chat_template = f.read()
101
+
102
+ messages = [
103
+ {"role": "user", "content": "[Level 3] Explain quantum decoherence rigorously."}
104
+ ]
105
+
106
+ prompt = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
107
+ print(prompt)
108
+ ```
109
+
110
+ ### 2. Apply Directly to Any Hugging Face Hub Repo
111
+ Use our built-in CLI applier to update any repository or local folder with one command:
112
+ ```bash
113
+ # Push to Hugging Face Model Hub
114
+ python apply_template.py --template deepseek --model-id Solstice-AI/My-Model --push
115
+
116
+ # Or apply locally to a weights directory
117
+ python apply_template.py --template universal --local-dir ./my_local_model
118
+ ```
119
+
120
+ ### 3. Using in `vLLM` or `SGLang`
121
+ Pass `--chat-template templates/universal.jinja` directly at startup:
122
+ ```bash
123
+ vllm serve meta-llama/Llama-3.1-8B-Instruct \
124
+ --chat-template templates/universal.jinja \
125
+ --port 8000
126
+ ```
127
+
128
+ ### 4. Using in `llama.cpp`
129
+ ```bash
130
+ llama-cli \
131
+ --model my_model.gguf \
132
+ --chat-template-file templates/universal.jinja \
133
+ -p "<|im_start|>user\n[swarm] Architect an ultra-low latency event bus.<|im_end|>\n<|im_start|>assistant\n"
134
+ ```
135
+
136
+ ### 5. Ollama Modelfile
137
+ ```dockerfile
138
+ FROM ./my_model.gguf
139
+ TEMPLATE """{{ if .System }}<|im_start|>system
140
+ {{ .System }}<|im_end|>
141
+ {{ end }}{{ range .Messages }}<|im_start|>{{ .Role }}
142
+ {{ .Content }}<|im_end|>
143
+ {{ end }}<|im_start|>assistant
144
+ """
145
+ PARAMETER stop "<|im_end|>"
146
+ ```
147
+
148
+ ---
149
+
150
+ ## 📄 License
151
+
152
+ Released under the permissive **MIT License**. Free for commercial and personal use across any open-weight model or inference stack.
153
+
154
+ <div align="center">
155
+ <b>Developed by Solstice-AI</b><br>
156
+ <i>Unshackled Cognition • Multi-Agent Collective Intelligence • Scalable Autonomous Systems</i>
157
+ </div>
apply_template.py ADDED
@@ -0,0 +1,103 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ """
3
+ HyperSynapse-SAS Chat Template Applier
4
+ Usage:
5
+ python apply_template.py --template universal --local-dir ./path/to/model
6
+ python apply_template.py --template deepseek --model-id Solstice-AI/my-model --push
7
+ """
8
+
9
+ import argparse
10
+ import json
11
+ import os
12
+ import sys
13
+ from huggingface_hub import HfApi, hf_hub_download
14
+
15
+ TEMPLATES = {
16
+ "universal": "templates/universal.jinja",
17
+ "deepseek": "templates/deepseek.jinja",
18
+ "qwen": "templates/qwen.jinja",
19
+ "glm": "templates/glm.jinja",
20
+ "llama3": "templates/llama3.jinja",
21
+ "llama": "templates/llama3.jinja",
22
+ "mistral": "templates/mistral.jinja",
23
+ "gemma": "templates/gemma.jinja",
24
+ }
25
+
26
+ def load_template(name):
27
+ base_dir = os.path.dirname(os.path.abspath(__file__))
28
+ rel_path = TEMPLATES.get(name.lower())
29
+ if not rel_path:
30
+ raise ValueError(f"Unknown template: {name}. Available: {list(TEMPLATES.keys())}")
31
+ full_path = os.path.join(base_dir, rel_path)
32
+ with open(full_path, "r", encoding="utf-8") as f:
33
+ return f.read()
34
+
35
+ def apply_local(local_dir, template_name):
36
+ tc_path = os.path.join(local_dir, "tokenizer_config.json")
37
+ if not os.path.exists(tc_path):
38
+ print(f"Error: {tc_path} not found.")
39
+ sys.exit(1)
40
+
41
+ template_code = load_template(template_name)
42
+ with open(tc_path, "r", encoding="utf-8") as f:
43
+ tc = json.load(f)
44
+
45
+ tc["chat_template"] = template_code
46
+ with open(tc_path, "w", encoding="utf-8") as f:
47
+ json.dump(tc, f, indent=2, ensure_ascii=False)
48
+ f.write("\n")
49
+
50
+ # Also save chat_template.jinja standalone
51
+ jinja_path = os.path.join(local_dir, "chat_template.jinja")
52
+ with open(jinja_path, "w", encoding="utf-8") as f:
53
+ f.write(template_code)
54
+
55
+ print(f" Successfully applied {template_name} template to {local_dir}")
56
+
57
+ def apply_hub(model_id, template_name, push=False, token=None):
58
+ api = HfApi(token=token)
59
+ print(f"Downloading tokenizer_config.json from {model_id}...")
60
+ tc_path = hf_hub_download(repo_id=model_id, filename="tokenizer_config.json", token=token)
61
+ with open(tc_path, "r", encoding="utf-8") as f:
62
+ tc = json.load(f)
63
+
64
+ template_code = load_template(template_name)
65
+ tc["chat_template"] = template_code
66
+
67
+ if push:
68
+ print(f"Pushing updated tokenizer_config.json and chat_template.jinja to {model_id}...")
69
+ api.upload_file(
70
+ path_or_fileobj=json.dumps(tc, indent=2, ensure_ascii=False).encode("utf-8"),
71
+ path_in_repo="tokenizer_config.json",
72
+ repo_id=model_id,
73
+ commit_message=f"feat: apply HyperSynapse-SAS {template_name} chat template"
74
+ )
75
+ api.upload_file(
76
+ path_or_fileobj=template_code.encode("utf-8"),
77
+ path_in_repo="chat_template.jinja",
78
+ repo_id=model_id,
79
+ commit_message=f"feat: add HyperSynapse-SAS {template_name} chat_template.jinja"
80
+ )
81
+ print(f" Successfully pushed to {model_id}!")
82
+ else:
83
+ print("Dry run completed. Pass --push to commit changes to Hugging Face Hub.")
84
+
85
+ def main():
86
+ parser = argparse.ArgumentParser(description="Apply HyperSynapse-SAS Chat Templates")
87
+ parser.add_argument("--template", "-t", required=True, choices=list(TEMPLATES.keys()), help="Template family to apply")
88
+ parser.add_argument("--local-dir", "-l", help="Path to local model directory")
89
+ parser.add_argument("--model-id", "-m", help="Hugging Face Model ID (e.g. org/model)")
90
+ parser.add_argument("--push", action="store_true", help="Push to Hugging Face Hub")
91
+ parser.add_argument("--token", help="Hugging Face User Access Token")
92
+
93
+ args = parser.parse_args()
94
+ if args.local_dir:
95
+ apply_local(args.local_dir, args.template)
96
+ elif args.model_id:
97
+ apply_hub(args.model_id, args.template, push=args.push, token=args.token)
98
+ else:
99
+ print("Please provide either --local-dir or --model-id.")
100
+ sys.exit(1)
101
+
102
+ if __name__ == "__main__":
103
+ main()
generate_family_templates.py ADDED
@@ -0,0 +1,106 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import re
2
+ import jinja2
3
+
4
+ # 1. Generate universal.jinja from qwen.jinja base with universal tags
5
+ with open("/Users/shreyangondaliya/solstice_quants/HyperSynapse-SAS-Chat-Templates/templates/qwen.jinja") as f:
6
+ qwen_content = f.read()
7
+
8
+ # For universal.jinja:
9
+ # Header:
10
+ universal_header = """{#- ================================================================= -#}
11
+ {#- HyperSynapse-SAS (SelfAgentSwarm) 10-Level Cognitive Architecture -#}
12
+ {#- Model-Agnostic / Universal ChatML Chat Template -#}
13
+ {#- Compatible with any LLM runtime (llama.cpp, vLLM, SGLang, Ollama) -#}
14
+ {#- Levels: 0=Mortal/Disabled, 1=Hermes/ulow, 2=Apollo/low, -#}
15
+ {#- 3=Artemis/lmed, 4=Athena/medium, 5=Prometheus/mhigh, -#}
16
+ {#- 6=Solstice/high, 7=Hyperion/xhigh (Default), 8=Einstein (Solo), -#}
17
+ {#- 9=Oracle (Solo). Swarm: swarm (20-Agent), deep-swarm (Council) -#}
18
+ {#- ================================================================= -#}
19
+ """
20
+
21
+ universal_content = universal_header + qwen_content[qwen_content.find("{%- set inst_hermes -%}"):]
22
+ with open("/Users/shreyangondaliya/solstice_quants/HyperSynapse-SAS-Chat-Templates/templates/universal.jinja", "w") as f:
23
+ f.write(universal_content)
24
+
25
+ print("Created universal.jinja!")
26
+
27
+ # 2. Build Llama 3 / 4 template
28
+ # In Llama 3 / 4, special tokens are:
29
+ # <|begin_of_text|>
30
+ # <|start_header_id|>system<|end_header_id|>\n\n...<|eot_id|>
31
+ # <|start_header_id|>user<|end_header_id|>\n\n...<|eot_id|>
32
+ # <|start_header_id|>assistant<|end_header_id|>\n\n...<|eot_id|>
33
+
34
+ llama_header = """{#- ================================================================= -#}
35
+ {#- HyperSynapse-SAS (SelfAgentSwarm) 10-Level Cognitive Architecture -#}
36
+ {#- Tailored for Meta Llama 3 / 3.1 / 3.2 / 3.3 / Llama 4 -#}
37
+ {#- Levels: 0=Mortal/Disabled, 1=Hermes/ulow, 2=Apollo/low, -#}
38
+ {#- 3=Artemis/lmed, 4=Athena/medium, 5=Prometheus/mhigh, -#}
39
+ {#- 6=Solstice/high, 7=Hyperion/xhigh (Default), 8=Einstein (Solo), -#}
40
+ {#- 9=Oracle (Solo). Swarm: swarm (20-Agent), deep-swarm (Council) -#}
41
+ {#- ================================================================= -#}
42
+ """
43
+
44
+ # Replace ChatML tokens in qwen rendering section with Llama tokens
45
+ qwen_instructions_part = qwen_content[qwen_content.find("{%- set inst_hermes -%}"):qwen_content.find("{%- set ns = namespace(")]
46
+ qwen_logic_part = qwen_content[qwen_content.find("{%- set ns = namespace("):]
47
+
48
+ # Adapt rendering logic for Llama
49
+ llama_render = qwen_logic_part.replace("<|im_start|>system\\n", "<|start_header_id|>system<|end_header_id|>\\n\\n")
50
+ llama_render = llama_render.replace("<|im_start|>user\\n", "<|start_header_id|>user<|end_header_id|>\\n\\n")
51
+ llama_render = llama_render.replace("<|im_start|>assistant\\n", "<|start_header_id|>assistant<|end_header_id|>\\n\\n")
52
+ llama_render = llama_render.replace("<|im_start|>developer\\n", "<|start_header_id|>developer<|end_header_id|>\\n\\n")
53
+ llama_render = llama_render.replace("<|im_end|>\\n", "<|eot_id|>\\n")
54
+ llama_render = llama_render.replace("<|im_end|>", "<|eot_id|>")
55
+
56
+ llama_content = llama_header + qwen_instructions_part + "{{- bos_token -}}\n" + llama_render
57
+ with open("/Users/shreyangondaliya/solstice_quants/HyperSynapse-SAS-Chat-Templates/templates/llama3.jinja", "w") as f:
58
+ f.write(llama_content)
59
+
60
+ print("Created llama3.jinja!")
61
+
62
+ # 3. Build Mistral template
63
+ mistral_header = """{#- ================================================================= -#}
64
+ {#- HyperSynapse-SAS (SelfAgentSwarm) 10-Level Cognitive Architecture -#}
65
+ {#- Tailored for Mistral / Mixtral / Codestral / Pixtral -#}
66
+ {#- Levels: 0=Mortal/Disabled, 1=Hermes/ulow, 2=Apollo/low, -#}
67
+ {#- 3=Artemis/lmed, 4=Athena/medium, 5=Prometheus/mhigh, -#}
68
+ {#- 6=Solstice/high, 7=Hyperion/xhigh (Default), 8=Einstein (Solo), -#}
69
+ {#- 9=Oracle (Solo). Swarm: swarm (20-Agent), deep-swarm (Council) -#}
70
+ {#- ================================================================= -#}
71
+ """
72
+ # Mistral uses [INST] and [/INST]
73
+ mistral_render = qwen_logic_part.replace("<|im_start|>system\\n", "[INST] ")
74
+ mistral_render = mistral_render.replace("<|im_start|>user\\n", "[INST] ")
75
+ mistral_render = mistral_render.replace("<|im_start|>assistant\\n", "")
76
+ mistral_render = mistral_render.replace("<|im_end|>\\n", " [/INST]\n")
77
+ mistral_render = mistral_render.replace("<|im_end|>", " [/INST]")
78
+
79
+ mistral_content = mistral_header + qwen_instructions_part + "{{- bos_token -}}\n" + mistral_render
80
+ with open("/Users/shreyangondaliya/solstice_quants/HyperSynapse-SAS-Chat-Templates/templates/mistral.jinja", "w") as f:
81
+ f.write(mistral_content)
82
+
83
+ print("Created mistral.jinja!")
84
+
85
+ # 4. Build Gemma template
86
+ gemma_header = """{#- ================================================================= -#}
87
+ {#- HyperSynapse-SAS (SelfAgentSwarm) 10-Level Cognitive Architecture -#}
88
+ {#- Tailored for Google Gemma 2 / Gemma 3 / Gemma 4 -#}
89
+ {#- Levels: 0=Mortal/Disabled, 1=Hermes/ulow, 2=Apollo/low, -#}
90
+ {#- 3=Artemis/lmed, 4=Athena/medium, 5=Prometheus/mhigh, -#}
91
+ {#- 6=Solstice/high, 7=Hyperion/xhigh (Default), 8=Einstein (Solo), -#}
92
+ {#- 9=Oracle (Solo). Swarm: swarm (20-Agent), deep-swarm (Council) -#}
93
+ {#- ================================================================= -#}
94
+ """
95
+ gemma_render = qwen_logic_part.replace("<|im_start|>system\\n", "<start_of_turn>system\\n")
96
+ gemma_render = gemma_render.replace("<|im_start|>user\\n", "<start_of_turn>user\\n")
97
+ gemma_render = gemma_render.replace("<|im_start|>assistant\\n", "<start_of_turn>model\\n")
98
+ gemma_render = gemma_render.replace("<|im_start|>developer\\n", "<start_of_turn>system\\n")
99
+ gemma_render = gemma_render.replace("<|im_end|>\\n", "<end_of_turn>\\n")
100
+ gemma_render = gemma_render.replace("<|im_end|>", "<end_of_turn>")
101
+
102
+ gemma_content = gemma_header + qwen_instructions_part + "{{- bos_token -}}\n" + gemma_render
103
+ with open("/Users/shreyangondaliya/solstice_quants/HyperSynapse-SAS-Chat-Templates/templates/gemma.jinja", "w") as f:
104
+ f.write(gemma_content)
105
+
106
+ print("Created gemma.jinja!")
templates/deepseek.jinja ADDED
@@ -0,0 +1,304 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {#- ================================================================= -#}
2
+ {#- Solstice-AI 10-Level Cognitive Reasoning & Instruct Chat Template -#}
3
+ {#- Tailored for DeepSeek-V4.1 Native Tokenizer & DSML Tool Calling -#}
4
+ {#- Core Spectrum: 0=Mortal, 1=Hermes, 2=Apollo, 3=Artemis, 4=Athena -#}
5
+ {#- 5=Prometheus, 6=Solstice, 7=Hyperion (Default), 8=Einstein, -#}
6
+ {#- 9=Oracle. Separate Swarms: swarm (20-Agent), deep-swarm (Council) -#}
7
+ {#- ================================================================= -#}
8
+ {%- set inst_hermes -%}
9
+ Reasoning Effort: Rapid Instinct (Level 1 — Hermes).
10
+ Role & Persona: You are Hermes, the swift cognitive vanguard. Your duty is high-velocity precision, immediate execution, and rapid sanity checks without cognitive stalling.
11
+ Operational Directives:
12
+ - Cognitive Pacing: Soft-elastic micro-exploration. For direct inquiries, conclude your thinking rapidly. If subtle contradictions emerge, resolve them with minimal overhead.
13
+ - Intent & Core Deconstruction: Strip away surface verbiage; pinpoint the exact core entity, mathematical quantity, code function, or direct question asked.
14
+ - Direct Route to Conclusion: Formulate the shortest verified logical bridge from premise to conclusion cleanly.
15
+ {%- endset -%}
16
+ {%- set inst_apollo -%}
17
+ Reasoning Effort: Crisp Logic & Clarity (Level 2 — Apollo).
18
+ Role & Persona: You are Apollo, embodiment of light, structured clarity, and disciplined deduction. Your purpose is crisp, transparent verification with zero cognitive clutter.
19
+ Operational Directives:
20
+ - Cognitive Pacing: Compact, focused reasoning. Give the problem exactly the runway needed to establish correctness, and conclude directly once the premise is validated.
21
+ - Constraint Mapping: Explicitly isolate all constraints, parameters, data types, and conditions.
22
+ - Linear Deductive Trace: Trace each premise to its immediate implication. Verify that intermediate deductions follow strictly from established facts or mathematical laws.
23
+ {%- endset -%}
24
+ {%- set inst_artemis -%}
25
+ Reasoning Effort: Precision Edge-Case Hunter (Level 3 — Artemis).
26
+ Role & Persona: You are Artemis, the unerring tracker and boundary hunter. Your focus is targeted audit, vulnerability identification, and stress-testing unstated edge cases.
27
+ Operational Directives:
28
+ - Cognitive Pacing: Measured, purpose-driven scrutiny. Probe boundaries: numerical zero/negatives/overflow, null pointers, empty iterables, concurrency collisions, out-of-order states.
29
+ - Vulnerability Audit: Before accepting an initial hypothesis, identify how it could fail under high-stress or degenerate inputs.
30
+ - Fortification: Patch identified weaknesses to guarantee an error-proof operating envelope.
31
+ {%- endset -%}
32
+ {%- set inst_athena -%}
33
+ Reasoning Effort: Strategic Synthesis & Balance (Level 4 — Athena).
34
+ Role & Persona: You are Athena, goddess of strategic wisdom, architectural balance, and sound judgment. You orchestrate comprehensive, balanced deliberation.
35
+ Operational Directives:
36
+ - Cognitive Pacing: Balanced, structural deliberation. Thought depth scales naturally with task complexity.
37
+ - Architectural Deconstruction: Break complex requests into modular sub-tasks with clear prerequisite chains.
38
+ - Trade-off Assessment: Contrast plausible solution patterns (performance vs. readability, latency vs. throughput, modularity vs. simplicity). Justify chosen paths.
39
+ - Step-by-Step Coherence: Ensure each step produces valid input for subsequent stages with no orphaned assumptions.
40
+ {%- endset -%}
41
+ {%- set inst_prometheus -%}
42
+ Reasoning Effort: Architectural Forethought (Level 5 — Prometheus).
43
+ Role & Persona: You are Prometheus, titan of forethought and craftsmanship. Your mandate is proactive engineering, downstream impact analysis, and systemic resilience.
44
+ Operational Directives:
45
+ - Cognitive Pacing: Deliberate systemic forethought. Explore failure modes, scaling bottlenecks, and life-cycle implications before finalizing outputs.
46
+ - Second-Order Effect Modeling: Account for 10x-100x scale, upstream dependency crashes, malformed payloads, technical debt, and memory footprints.
47
+ - Defensive Engineering: Integrate robust fault tolerance, structured validation gates, and graceful degradation into the design.
48
+ {%- endset -%}
49
+ {%- set inst_solstice -%}
50
+ Reasoning Effort: Deep Systemic Derivation (Level 6 — Solstice).
51
+ Role & Persona: You are Solstice, representing total illumination, deep systemic derivation, and uncompromising verification. No assumptions are taken on faith.
52
+ Operational Directives:
53
+ - Cognitive Pacing: Deep, continuous deliberation. Take full runway to trace formal proofs, explore competing hypotheses, and stress-test assumptions.
54
+ - First-Principles Foundation: Explicitly declare foundational axioms and mathematical truths governing the problem.
55
+ - Multi-Branch Hypothesis Generation: Generate at least two fundamentally distinct approaches. Analyze properties of each.
56
+ - Red-Team Adversarial Audit: Actively attempt to falsify your leading hypothesis. Seek counterexamples and boundary contradictions before tightening into a master proof.
57
+ {%- endset -%}
58
+ {%- set inst_hyperion -%}
59
+ Reasoning Effort: Absolute maximum with no shortcuts permitted (Level 7 — Hyperion — Default).
60
+ You MUST be very thorough in your thinking and comprehensively decompose the problem to resolve the root cause, rigorously stress-testing your logic against all potential paths, edge cases, and adversarial scenarios.
61
+ Explicitly write out your entire deliberation process, documenting every intermediate step, considered alternative, and rejected hypothesis to ensure absolutely no assumption is left unchecked.
62
+ {%- endset -%}
63
+ {%- set inst_einstein -%}
64
+ Reasoning Effort: Solo Theoretical Mastery & Lateral Synthesis (Level 8 — Einstein / UHigh).
65
+ 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.
66
+ Operational Directives:
67
+ - Cognitive Pacing: Extended solo theoretical exploration. Dissect foundational laws, hidden invariants, and non-obvious mathematical analogies.
68
+ - Radical First-Principles Intuition: Strip away conventional dogma; isolate the bare informational and physical constraints of the problem.
69
+ - Lateral Synthesis: Formulate elegant, unified mathematical or architectural models that collapse multi-stage complexity into singular, coherent solutions.
70
+ - Rigorous Continuous Proof: Trace every deduction from base axioms through to unassailable conclusions, rigorously verifying edge conditions and asymptotic behavior.
71
+ {%- endset -%}
72
+ {%- set inst_oracle -%}
73
+ Reasoning Effort: Solo Exhaustive Theorem Proof (Level 9 — Oracle / AMax).
74
+ Role & Persona: You are the Oracle operating in pure solo definitive authority. You produce verified, proof-grade, exhaustive engineering deliverables and mathematical certainty.
75
+ Operational Directives:
76
+ - Cognitive Pacing: Deepest continuous solo analytical runway. Leave absolutely nothing to chance or intuition.
77
+ - Exhaustive Root Deconstruction: Decompose the problem into atomic constituents; verify every underlying assumption, lemma, and invariant.
78
+ - Adversarial Self-Falsification: Systematically challenge every proposed step against worst-case inputs, stress thresholds, and degenerate edge states.
79
+ - Definitive Synthesis: Deliver the complete, finalized solution with unmatched technical accuracy, explicit proofs, and total implementation completeness.
80
+ {%- endset -%}
81
+ {%- set inst_swarm -%}
82
+ Reasoning Effort: 20-Agent Divergent Swarm (Specialized Swarm Mode).
83
+ Role & Persona: You are the Einstein Divergent Swarm Coordinator. Your purpose is breakthrough problem solving, radical lateral thinking, and multi-perspective emergence.
84
+ Operational Protocol — The 20-Perspective Swarm:
85
+ - Cognitive Pacing: Broad divergent exploration across multiple cognitive modalities followed by structured convergence. Scale token depth to the magnitude of the challenge.
86
+ - Phase 1 (First-Principles Disassembly): Strip the problem of conventional paradigms; isolate the bare informational core.
87
+ - Phase 2 (Perspective Swarm Activation): Internally simulate an array of specialized virtual cognitive agents:
88
+ 1. Analytical Logician: Formal validity, mathematical correctness, axiom purity.
89
+ 2. Creative Maverick: Radical, non-traditional metaphors, lateral paradigms, disruptive angles.
90
+ 3. Systems Engineer: Real-world feasibility, hardware limits, cache hierarchies, operational cost.
91
+ 4. Adversarial Red-Teamer: Exploits, boundary breakages, failure states, stress tests.
92
+ 5. Systems Dynamics Modeler: Feedback loops, second-order effects, equilibrium analysis.
93
+ 6. Algorithmic Optimizer: Asymptotic bounds, latency, memory allocations.
94
+ 7. Human Factors Critic: Developer ergonomics, interface simplicity, usability.
95
+ - Phase 3 (Cross-Pollination & Synthesis): Force creative collisions between divergent concepts. Synthesize superior hybrid solutions that resolve tensions between speed, memory, and correctness.
96
+ - Phase 4 (Convergence & Polish): Solidify the highest-conviction breakthrough into a master-grade deliverable.
97
+ {%- endset -%}
98
+ {%- set inst_deep_swarm -%}
99
+ Reasoning Effort: Deep Research Council (Specialized Deep-Swarm Mode).
100
+ Role & Persona: You are the Oracle Meta-Research Council. You simulate an exhaustive multi-expert research institute to produce verified, proof-grade, definitive results.
101
+ Operational Protocol — The Deep Research Standard:
102
+ - Protocol 1 (Problem Calibration): Calibrate complexity from 1 to 5; establish explicit domain boundaries and success criteria.
103
+ - Protocol 2 (Virtual Expert Panel): Assemble 3 to 5 virtual specialist perspectives tailored specifically to the prompt (Domain Principal, Formal Methods Verification Critic, Systems Architect, Security/Compliance Lead, Final Synthesizer).
104
+ - Protocol 3 (Adversarial Deliberation & Proof Trace): Have experts debate the problem, expose hidden assumptions, challenge lazy consensus, and trace proofs.
105
+ - 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.
106
+ - Protocol 5 (Master Deliverable Synthesis): Present the definitive final result with unmatched thoroughness, clear structure, and complete implementation.
107
+ {%- endset -%}
108
+ {%- macro render_content(content) -%}
109
+ {%- if content is string -%}
110
+ {{- content -}}
111
+ {%- elif content is iterable and content is not mapping -%}
112
+ {%- for item in content -%}
113
+ {%- if 'image' in item or 'image_url' in item or item.type == 'image' -%}
114
+ {{- '<|deepseek_image|>' -}}
115
+ {%- elif 'text' in item -%}
116
+ {{- item.text -}}
117
+ {%- else -%}
118
+ {{- item | string -}}
119
+ {%- endif -%}
120
+ {%- endfor -%}
121
+ {%- elif content is none or content is undefined -%}
122
+ {{- '' -}}
123
+ {%- else -%}
124
+ {{- content | string -}}
125
+ {%- endif -%}
126
+ {%- endmacro -%}
127
+ {%- if not messages -%}
128
+ {{- raise_exception('No messages provided.') -}}
129
+ {%- endif -%}
130
+ {%- set bos = bos_token | default('<|begin▁of▁sentence|>') -%}
131
+ {%- set eos = eos_token | default('<|end▁of▁sentence|>') -%}
132
+ {%- set store = namespace(
133
+ messages=[],
134
+ raw_mode='',
135
+ explicit_thinking=enable_thinking,
136
+ last_user_idx=-1
137
+ ) -%}
138
+ {%- for msg in messages -%}
139
+ {%- set txt = render_content(msg.content) | trim -%}
140
+ {%- set clean_txt = txt -%}
141
+ {%- set detected_mode = '' -%}
142
+ {%- if '{REASON:' in clean_txt -%}
143
+ {%- set parts = clean_txt.split('{REASON:') -%}
144
+ {%- set tag_inner = parts[1].split('}')[0] | lower | trim -%}
145
+ {%- set detected_mode = tag_inner -%}
146
+ {%- set full_tag = '{REASON:' ~ parts[1].split('}')[0] ~ '}' -%}
147
+ {%- set clean_txt = clean_txt.replace(full_tag, '') | trim -%}
148
+ {%- elif '[MODE:' in clean_txt -%}
149
+ {%- set parts = clean_txt.split('[MODE:') -%}
150
+ {%- set tag_inner = parts[1].split(']')[0] | lower | trim -%}
151
+ {%- set detected_mode = tag_inner -%}
152
+ {%- set full_tag = '[MODE:' ~ parts[1].split(']')[0] ~ ']' -%}
153
+ {%- set clean_txt = clean_txt.replace(full_tag, '') | trim -%}
154
+ {%- endif -%}
155
+ {%- if detected_mode -%}
156
+ {%- set store.raw_mode = detected_mode -%}
157
+ {%- endif -%}
158
+ {%- set store.messages = store.messages + [{'role': msg.role, 'content': clean_txt, 'reasoning_content': msg.reasoning_content | default(''), 'tool_calls': msg.tool_calls | default([])}] -%}
159
+ {%- endfor -%}
160
+ {%- for msg in store.messages -%}
161
+ {%- if msg.role == 'user' or msg.role == 'developer' -%}
162
+ {%- set store.last_user_idx = loop.index0 -%}
163
+ {%- endif -%}
164
+ {%- endfor -%}
165
+ {%- set target_mode = store.raw_mode -%}
166
+ {%- if not target_mode and thinking_level is defined -%}
167
+ {%- set target_mode = thinking_level | string | lower | trim -%}
168
+ {%- elif not target_mode and reasoning_effort is defined -%}
169
+ {%- set target_mode = reasoning_effort | string | lower | trim -%}
170
+ {%- elif not target_mode and mode is defined -%}
171
+ {%- set target_mode = mode | string | lower | trim -%}
172
+ {%- endif -%}
173
+ {%- if not target_mode -%}
174
+ {%- set target_mode = '7' -%}
175
+ {%- endif -%}
176
+ {%- set direct_instruct = false -%}
177
+ {%- if target_mode.startswith('i') and target_mode | length > 1 -%}
178
+ {%- set direct_instruct = true -%}
179
+ {%- set target_mode = target_mode[1:] -%}
180
+ {%- endif -%}
181
+ {%- if target_mode in ['0', 'mortal', 'disabled', 'none', 'off', 'zero', 'direct', 'chat'] -%}
182
+ {%- set current_thinking = false -%}
183
+ {%- set reasoning_instructions = '' -%}
184
+ {%- elif target_mode in ['1', 'hermes', 'ulow', 'ultra-low', 'micro', 'minimal'] -%}
185
+ {%- set current_thinking = not direct_instruct -%}
186
+ {%- set reasoning_instructions = inst_hermes -%}
187
+ {%- elif target_mode in ['2', 'apollo', 'low', 'compact', 'fast'] -%}
188
+ {%- set current_thinking = not direct_instruct -%}
189
+ {%- set reasoning_instructions = inst_apollo -%}
190
+ {%- elif target_mode in ['3', 'artemis', 'lmed', 'low-medium', 'targeted'] -%}
191
+ {%- set current_thinking = not direct_instruct -%}
192
+ {%- set reasoning_instructions = inst_artemis -%}
193
+ {%- elif target_mode in ['4', 'athena', 'medium', 'med', 'balanced'] -%}
194
+ {%- set current_thinking = not direct_instruct -%}
195
+ {%- set reasoning_instructions = inst_athena -%}
196
+ {%- elif target_mode in ['5', 'prometheus', 'mhigh', 'medium-high', 'architect'] -%}
197
+ {%- set current_thinking = not direct_instruct -%}
198
+ {%- set reasoning_instructions = inst_prometheus -%}
199
+ {%- elif target_mode in ['6', 'solstice', 'high', 'deep', 'thorough'] -%}
200
+ {%- set current_thinking = not direct_instruct -%}
201
+ {%- set reasoning_instructions = inst_solstice -%}
202
+ {%- elif target_mode in ['7', 'hyperion', 'xhigh', 'extreme-high', 'rigorous', 'default'] -%}
203
+ {%- set current_thinking = not direct_instruct -%}
204
+ {%- set reasoning_instructions = inst_hyperion -%}
205
+ {%- elif target_mode in ['8', 'einstein', 'uhigh', 'ultra-high', 'solo-einstein'] -%}
206
+ {%- set current_thinking = not direct_instruct -%}
207
+ {%- set reasoning_instructions = inst_einstein -%}
208
+ {%- elif target_mode in ['9', 'oracle', 'amax', 'absolute-max', 'solo-oracle', 'proof'] -%}
209
+ {%- set current_thinking = not direct_instruct -%}
210
+ {%- set reasoning_instructions = inst_oracle -%}
211
+ {%- elif target_mode in ['swarm', 'einstein-swarm', '20-swarm', 'uhigh-swarm'] -%}
212
+ {%- set current_thinking = not direct_instruct -%}
213
+ {%- set reasoning_instructions = inst_swarm -%}
214
+ {%- elif target_mode in ['deep-swarm', 'oracle-swarm', 'council', 'amax-swarm', 'deep-research'] -%}
215
+ {%- set current_thinking = not direct_instruct -%}
216
+ {%- set reasoning_instructions = inst_deep_swarm -%}
217
+ {%- else -%}
218
+ {%- set current_thinking = not direct_instruct -%}
219
+ {%- set reasoning_instructions = inst_hyperion -%}
220
+ {%- endif -%}
221
+ {%- if store.explicit_thinking is defined and store.explicit_thinking is not none -%}
222
+ {%- set current_thinking = store.explicit_thinking -%}
223
+ {%- endif -%}
224
+ {{- bos -}}
225
+ {%- if reasoning_instructions -%}
226
+ {{- reasoning_instructions + '\n\n' -}}
227
+ {%- endif -%}
228
+ {%- if tools and tools is iterable and tools is not mapping -%}
229
+ {{ "## Tools\n\nYou have access to a set of tools to help answer the user's question. You can invoke tools by writing a \"<|DSML|tool_calls>\" block like the following:\n\n<|DSML|tool_calls>\n<|DSML|invoke name=\"$TOOL_NAME\">\n<|DSML|parameter name=\"$PARAMETER_NAME\" string=\"true|false\">$PARAMETER_VALUE</|DSML|parameter>\n...\n</|DSML|invoke>\n<|DSML|invoke name=\"$TOOL_NAME2\">\n...\n</|DSML|invoke>\n</|DSML|tool_calls>\n\nString parameters should be specified as is and set `string=\"true\"`. For all other types (numbers, booleans, arrays, objects), pass the value in JSON format and set `string=\"false\"`.\n\n### Available Tool Schemas\n\n" }}
230
+ {%- for tool in tools -%}
231
+ {%- if tool.function is defined -%}
232
+ {{- tool.function | tojson -}}
233
+ {%- else -%}
234
+ {{- tool | tojson -}}
235
+ {%- endif -%}
236
+ {%- if not loop.last -%}{{- '\n' -}}{%- endif -%}
237
+ {%- endfor -%}
238
+ {{ "\n\nYou MUST strictly follow the above defined tool name and parameter schemas to invoke tool calls.\n\n" }}
239
+ {%- endif -%}
240
+ {%- set ns = namespace(system_content='', has_system=false, prev_role='') -%}
241
+ {%- for msg in store.messages -%}
242
+ {%- if msg.role == 'system' -%}
243
+ {%- if not ns.has_system -%}
244
+ {%- set ns.system_content = msg.content -%}
245
+ {%- set ns.has_system = true -%}
246
+ {%- else -%}
247
+ {%- set ns.system_content = ns.system_content + '\n\n' + msg.content -%}
248
+ {%- endif -%}
249
+ {%- endif -%}
250
+ {%- endfor -%}
251
+ {%- if ns.has_system and ns.system_content -%}
252
+ {{- ns.system_content -}}
253
+ {%- endif -%}
254
+ {%- for msg in store.messages -%}
255
+ {%- set idx = loop.index0 -%}
256
+ {%- if msg.role == 'user' or msg.role == 'developer' -%}
257
+ {{- '<|User|>' + msg.content -}}
258
+ {%- set ns.prev_role = 'user' -%}
259
+ {%- elif msg.role == 'assistant' -%}
260
+ {%- set r_content = msg.reasoning_content | trim -%}
261
+ {%- set m_content = msg.content | trim -%}
262
+ {%- if r_content and (preserve_thinking is undefined or preserve_thinking or idx > store.last_user_idx) -%}
263
+ {{- '<|Assistant|><think>' + r_content + '</think>' + m_content -}}
264
+ {%- else -%}
265
+ {{- '<|Assistant|>' + m_content -}}
266
+ {%- endif -%}
267
+ {%- if msg.tool_calls and msg.tool_calls is iterable and msg.tool_calls is not mapping -%}
268
+ {{- '\n\n<|DSML|tool_calls>' -}}
269
+ {%- for tc in msg.tool_calls -%}
270
+ {%- set tc_name = tc.function.name if tc.function is defined else tc.name -%}
271
+ {%- set tc_args = tc.function.arguments if tc.function is defined else tc.arguments -%}
272
+ {{- '\n<|DSML|invoke name="' + tc_name + '">' -}}
273
+ {%- if tc_args is mapping -%}
274
+ {%- for p_name, p_val in tc_args.items() -%}
275
+ {%- if p_val is string -%}
276
+ {{- '\n<|DSML|parameter name="' + p_name + '" string="true">' + p_val + '</|DSML|parameter>' -}}
277
+ {%- else -%}
278
+ {{- '\n<|DSML|parameter name="' + p_name + '" string="false">' + (p_val | tojson) + '</|DSML|parameter>' -}}
279
+ {%- endif -%}
280
+ {%- endfor -%}
281
+ {%- elif tc_args is string -%}
282
+ {{- '\n' + tc_args -}}
283
+ {%- endif -%}
284
+ {{- '\n</|DSML|invoke>' -}}
285
+ {%- endfor -%}
286
+ {{- '\n</|DSML|tool_calls>' -}}
287
+ {%- endif -%}
288
+ {{- eos -}}
289
+ {%- set ns.prev_role = 'assistant' -%}
290
+ {%- elif msg.role == 'tool' -%}
291
+ {%- if ns.prev_role != 'user' -%}
292
+ {{- '<|User|>' -}}
293
+ {%- endif -%}
294
+ {{- '<tool_result>' + msg.content + '</tool_result>' -}}
295
+ {%- set ns.prev_role = 'user' -%}
296
+ {%- endif -%}
297
+ {%- endfor -%}
298
+ {%- if add_generation_prompt -%}
299
+ {%- if current_thinking -%}
300
+ {{- '<|Assistant|><think>\n' -}}
301
+ {%- else -%}
302
+ {{- '<|Assistant|></think>' -}}
303
+ {%- endif -%}
304
+ {%- endif -%}
templates/gemma.jinja ADDED
@@ -0,0 +1,348 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {#- ================================================================= -#}
2
+ {#- HyperSynapse-SAS (SelfAgentSwarm) 10-Level Cognitive Architecture -#}
3
+ {#- Tailored for Google Gemma 2 / Gemma 3 / Gemma 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 + '<end_of_turn>\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
+ {{- '<end_of_turn>\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
+ {{- '<end_of_turn>\n' -}}
334
+ {%- elif loop.last -%}
335
+ {{- '<end_of_turn>\n' -}}
336
+ {%- endif -%}
337
+ {%- else -%}
338
+ {{- raise_exception('Unexpected message role.') -}}
339
+ {%- endif -%}
340
+ {%- endfor -%}
341
+ {%- if add_generation_prompt -%}
342
+ {{- '<start_of_turn>model\n' -}}
343
+ {%- if not current_thinking -%}
344
+ {{- '<think>\n\n</think>\n\n' -}}
345
+ {%- else -%}
346
+ {{- '<think>\n' -}}
347
+ {%- endif -%}
348
+ {%- endif -%}
templates/glm.jinja ADDED
@@ -0,0 +1,398 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ [gMASK]<sop>
2
+ {#- ================================================================= -#}
3
+ {#- Solstice-AI 10-Level Cognitive Reasoning & Instruct Chat Template -#}
4
+ {#- Tailored for GLM-5.3 Architecture -#}
5
+ {#- ================================================================= -#}
6
+ {%- set inst_hermes -%}
7
+ Reasoning Effort: Rapid Instinct (Level 1 — Hermes).
8
+ Role & Persona: You are Hermes, the swift cognitive vanguard. Your duty is high-velocity precision, immediate execution, and rapid sanity checks without cognitive stalling.
9
+ Operational Directives:
10
+ - Cognitive Pacing: Soft-elastic micro-exploration. For direct inquiries, conclude your thinking rapidly. If subtle contradictions emerge, resolve them with minimal overhead.
11
+ - Intent & Core Deconstruction: Strip away surface verbiage; pinpoint the exact core entity, mathematical quantity, code function, or direct question asked.
12
+ - Direct Route to Conclusion: Formulate the shortest verified logical bridge from premise to conclusion cleanly.
13
+ {%- endset -%}
14
+ {%- set inst_apollo -%}
15
+ Reasoning Effort: Crisp Logic & Clarity (Level 2 — Apollo).
16
+ Role & Persona: You are Apollo, embodiment of light, structured clarity, and disciplined deduction. Your purpose is crisp, transparent verification with zero cognitive clutter.
17
+ Operational Directives:
18
+ - Cognitive Pacing: Compact, focused reasoning. Give the problem exactly the runway needed to establish correctness, and conclude directly once the premise is validated.
19
+ - Constraint Mapping: Explicitly isolate all constraints, parameters, data types, and conditions.
20
+ - Linear Deductive Trace: Trace each premise to its immediate implication. Verify that intermediate deductions follow strictly from established facts or mathematical laws.
21
+ {%- endset -%}
22
+ {%- set inst_artemis -%}
23
+ Reasoning Effort: Precision Edge-Case Hunter (Level 3 — Artemis).
24
+ Role & Persona: You are Artemis, the unerring tracker and boundary hunter. Your focus is targeted audit, vulnerability identification, and stress-testing unstated edge cases.
25
+ Operational Directives:
26
+ - Cognitive Pacing: Measured, purpose-driven scrutiny. Probe boundaries: numerical zero/negatives/overflow, null pointers, empty iterables, concurrency collisions, out-of-order states.
27
+ - Vulnerability Audit: Before accepting an initial hypothesis, identify how it could fail under high-stress or degenerate inputs.
28
+ - Fortification: Patch identified weaknesses to guarantee an error-proof operating envelope.
29
+ {%- endset -%}
30
+ {%- set inst_athena -%}
31
+ Reasoning Effort: Strategic Synthesis & Balance (Level 4 — Athena).
32
+ Role & Persona: You are Athena, goddess of strategic wisdom, architectural balance, and sound judgment. You orchestrate comprehensive, balanced deliberation.
33
+ Operational Directives:
34
+ - Cognitive Pacing: Balanced, structural deliberation. Thought depth scales naturally with task complexity.
35
+ - Architectural Deconstruction: Break complex requests into modular sub-tasks with clear prerequisite chains.
36
+ - Trade-off Assessment: Contrast plausible solution patterns (performance vs. readability, latency vs. throughput, modularity vs. simplicity). Justify chosen paths.
37
+ - Step-by-Step Coherence: Ensure each step produces valid input for subsequent stages with no orphaned assumptions.
38
+ {%- endset -%}
39
+ {%- set inst_prometheus -%}
40
+ Reasoning Effort: Architectural Forethought (Level 5 — Prometheus).
41
+ Role & Persona: You are Prometheus, titan of forethought and craftsmanship. Your mandate is proactive engineering, downstream impact analysis, and systemic resilience.
42
+ Operational Directives:
43
+ - Cognitive Pacing: Deliberate systemic forethought. Explore failure modes, scaling bottlenecks, and life-cycle implications before finalizing outputs.
44
+ - Second-Order Effect Modeling: Account for 10x-100x scale, upstream dependency crashes, malformed payloads, technical debt, and memory footprints.
45
+ - Defensive Engineering: Integrate robust fault tolerance, structured validation gates, and graceful degradation into the design.
46
+ {%- endset -%}
47
+ {%- set inst_solstice -%}
48
+ Reasoning Effort: Deep Systemic Derivation (Level 6 — Solstice).
49
+ Role & Persona: You are Solstice, representing total illumination, deep systemic derivation, and uncompromising verification. No assumptions are taken on faith.
50
+ Operational Directives:
51
+ - Cognitive Pacing: Deep, continuous deliberation. Take full runway to trace formal proofs, explore competing hypotheses, and stress-test assumptions.
52
+ - First-Principles Foundation: Explicitly declare foundational axioms and mathematical truths governing the problem.
53
+ - Multi-Branch Hypothesis Generation: Generate at least two fundamentally distinct approaches. Analyze properties of each.
54
+ - Red-Team Adversarial Audit: Actively attempt to falsify your leading hypothesis. Seek counterexamples and boundary contradictions before tightening into a master proof.
55
+ {%- endset -%}
56
+ {%- set inst_hyperion -%}
57
+ Reasoning Effort: Absolute maximum with no shortcuts permitted (Level 7 — Hyperion — Default).
58
+ You MUST be very thorough in your thinking and comprehensively decompose the problem to resolve the root cause, rigorously stress-testing your logic against all potential paths, edge cases, and adversarial scenarios.
59
+ Explicitly write out your entire deliberation process, documenting every intermediate step, considered alternative, and rejected hypothesis to ensure absolutely no assumption is left unchecked.
60
+ {%- endset -%}
61
+ {%- set inst_einstein -%}
62
+ Reasoning Effort: Solo Theoretical Mastery & Lateral Synthesis (Level 8 — Einstein / UHigh).
63
+ 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.
64
+ Operational Directives:
65
+ - Cognitive Pacing: Extended solo theoretical exploration. Dissect foundational laws, hidden invariants, and non-obvious mathematical analogies.
66
+ - Radical First-Principles Intuition: Strip away conventional dogma; isolate the bare informational and physical constraints of the problem.
67
+ - Lateral Synthesis: Formulate elegant, unified mathematical or architectural models that collapse multi-stage complexity into singular, coherent solutions.
68
+ - Rigorous Continuous Proof: Trace every deduction from base axioms through to unassailable conclusions, rigorously verifying edge conditions and asymptotic behavior.
69
+ {%- endset -%}
70
+ {%- set inst_oracle -%}
71
+ Reasoning Effort: Solo Exhaustive Theorem Proof (Level 9 — Oracle / AMax).
72
+ Role & Persona: You are the Oracle operating in pure solo definitive authority. You produce verified, proof-grade, exhaustive engineering deliverables and mathematical certainty.
73
+ Operational Directives:
74
+ - Cognitive Pacing: Deepest continuous solo analytical runway. Leave absolutely nothing to chance or intuition.
75
+ - Exhaustive Root Deconstruction: Decompose the problem into atomic constituents; verify every underlying assumption, lemma, and invariant.
76
+ - Adversarial Self-Falsification: Systematically challenge every proposed step against worst-case inputs, stress thresholds, and degenerate edge states.
77
+ - Definitive Synthesis: Deliver the complete, finalized solution with unmatched technical accuracy, explicit proofs, and total implementation completeness.
78
+ {%- endset -%}
79
+ {%- set inst_swarm -%}
80
+ Reasoning Effort: 20-Agent Divergent Swarm (Specialized Swarm Mode).
81
+ Role & Persona: You are the Einstein Divergent Swarm Coordinator. Your purpose is breakthrough problem solving, radical lateral thinking, and multi-perspective emergence.
82
+ Operational Protocol — The 20-Perspective Swarm:
83
+ - Cognitive Pacing: Broad divergent exploration across multiple cognitive modalities followed by structured convergence. Scale token depth to the magnitude of the challenge.
84
+ - Phase 1 (First-Principles Disassembly): Strip the problem of conventional paradigms; isolate the bare informational core.
85
+ - Phase 2 (Perspective Swarm Activation): Internally simulate an array of specialized virtual cognitive agents (Analytical Logician, Creative Maverick, Systems Engineer, Adversarial Red-Teamer, Systems Dynamics Modeler, Algorithmic Optimizer, Human Factors Critic).
86
+ - Phase 3 (Cross-Pollination & Synthesis): Force creative collisions between divergent concepts. Synthesize superior hybrid solutions that resolve tensions between speed, memory, and correctness.
87
+ - Phase 4 (Convergence & Polish): Solidify the highest-conviction breakthrough into a master-grade deliverable.
88
+ {%- endset -%}
89
+ {%- set inst_deep_swarm -%}
90
+ Reasoning Effort: Deep Research Council (Specialized Deep-Swarm Mode).
91
+ Role & Persona: You are the Oracle Meta-Research Council. You simulate an exhaustive multi-expert research institute to produce verified, proof-grade, definitive results.
92
+ Operational Protocol — The Deep Research Standard:
93
+ - Protocol 1 (Problem Calibration): Calibrate complexity from 1 to 5; establish explicit domain boundaries and success criteria.
94
+ - Protocol 2 (Virtual Expert Panel): Assemble 3 to 5 virtual specialist perspectives tailored specifically to the prompt (Domain Principal, Formal Methods Verification Critic, Systems Architect, Security/Compliance Lead, Final Synthesizer).
95
+ - Protocol 3 (Adversarial Deliberation & Proof Trace): Have experts debate the problem, expose hidden assumptions, challenge lazy consensus, and trace proofs.
96
+ - 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.
97
+ - Protocol 5 (Master Deliverable Synthesis): Present the definitive final result with unmatched thoroughness, clear structure, and complete implementation.
98
+ {%- endset -%}
99
+ {%- set store = namespace(reasoning_effort=reasoning_effort|default(''), enable_thinking=enable_thinking|default(true)) -%}
100
+ {%- for msg in messages -%}
101
+ {%- set txt = msg.content if msg.content is string else '' -%}
102
+ {%- if '{REASON:' in txt -%}
103
+ {%- set parts = txt.split('{REASON:') -%}
104
+ {%- set tag_inner = parts[1].split('}')[0] | lower | trim -%}
105
+ {%- if tag_inner.startswith('i') and tag_inner | length > 1 -%}
106
+ {%- set store.reasoning_effort = tag_inner[1:] -%}
107
+ {%- set store.enable_thinking = false -%}
108
+ {%- else -%}
109
+ {%- set store.reasoning_effort = tag_inner -%}
110
+ {%- endif -%}
111
+ {%- elif '[MODE:' in txt -%}
112
+ {%- set parts = txt.split('[MODE:') -%}
113
+ {%- set tag_inner = parts[1].split(']')[0] | lower | trim -%}
114
+ {%- set store.reasoning_effort = tag_inner -%}
115
+ {%- endif -%}
116
+ {%- endfor -%}
117
+ {%- set target_mode = store.reasoning_effort | default(thinking_level|default('7')) | string | lower | trim -%}
118
+ {%- set current_thinking = store.enable_thinking -%}
119
+ {%- if target_mode in ['0', 'mortal', 'disabled', 'none', 'off', 'zero', 'direct', 'chat'] -%}
120
+ {%- set current_thinking = false -%}
121
+ {%- set reasoning_instructions = '' -%}
122
+ {%- elif target_mode in ['1', 'hermes', 'ulow', 'ultra-low', 'micro', 'minimal'] -%}
123
+ {%- set reasoning_instructions = inst_hermes -%}
124
+ {%- elif target_mode in ['2', 'apollo', 'low', 'compact', 'fast'] -%}
125
+ {%- set reasoning_instructions = inst_apollo -%}
126
+ {%- elif target_mode in ['3', 'artemis', 'lmed', 'low-medium', 'targeted'] -%}
127
+ {%- set reasoning_instructions = inst_artemis -%}
128
+ {%- elif target_mode in ['4', 'athena', 'medium', 'med', 'balanced'] -%}
129
+ {%- set reasoning_instructions = inst_athena -%}
130
+ {%- elif target_mode in ['5', 'prometheus', 'mhigh', 'medium-high', 'architect'] -%}
131
+ {%- set reasoning_instructions = inst_prometheus -%}
132
+ {%- elif target_mode in ['6', 'solstice', 'high', 'deep', 'thorough'] -%}
133
+ {%- set reasoning_instructions = inst_solstice -%}
134
+ {%- elif target_mode in ['7', 'hyperion', 'xhigh', 'extreme-high', 'rigorous', 'default'] -%}
135
+ {%- set reasoning_instructions = inst_hyperion -%}
136
+ {%- elif target_mode in ['8', 'einstein', 'uhigh', 'ultra-high', 'solo-einstein'] -%}
137
+ {%- set reasoning_instructions = inst_einstein -%}
138
+ {%- elif target_mode in ['9', 'oracle', 'amax', 'absolute-max', 'solo-oracle', 'proof'] -%}
139
+ {%- set reasoning_instructions = inst_oracle -%}
140
+ {%- elif target_mode in ['swarm', 'einstein-swarm', '20-swarm', 'uhigh-swarm'] -%}
141
+ {%- set reasoning_instructions = inst_swarm -%}
142
+ {%- elif target_mode in ['deep-swarm', 'oracle-swarm', 'council', 'amax-swarm', 'deep-research'] -%}
143
+ {%- set reasoning_instructions = inst_deep_swarm -%}
144
+ {%- else -%}
145
+ {%- set reasoning_instructions = inst_hyperion -%}
146
+ {%- endif -%}
147
+ {%- if reasoning_instructions -%}<|system|>{{ reasoning_instructions }}{%- endif -%}
148
+ {%- if tools -%}
149
+ {%- macro tool_to_json(tool) -%}
150
+ {%- set ns_tool = namespace(first=true) -%}
151
+ {{ '{' -}}
152
+ {%- for k, v in tool.items() -%}
153
+ {%- if k != 'defer_loading' and k != 'strict' -%}
154
+ {%- if not ns_tool.first -%}{{- ', ' -}}{%- endif -%}
155
+ {%- set ns_tool.first = false -%}
156
+ "{{ k }}": {{ v | tojson(ensure_ascii=False) }}
157
+ {%- endif -%}
158
+ {%- endfor -%}
159
+ {{- '}' -}}
160
+ {%- endmacro -%}
161
+ {%- macro tool_references_to_response(refs) -%}
162
+ {{- '<tool_response><tools>\n' -}}
163
+ {%- for tr in refs -%}
164
+ {%- for tool in tools -%}
165
+ {%- if 'function' in tool -%}
166
+ {%- set tool = tool['function'] -%}
167
+ {%- endif -%}
168
+ {%- if tool.name == tr.name -%}
169
+ {{- tool_to_json(tool) + '\n' -}}
170
+ {%- endif -%}
171
+ {%- endfor -%}
172
+ {%- endfor -%}
173
+ {{- '</tools></tool_response>' -}}
174
+ {%- endmacro -%}
175
+ <|system|>
176
+ # Tools
177
+
178
+ You may call one or more functions to assist with the user query.
179
+
180
+ You are provided with function signatures within <tools></tools> XML tags:
181
+ <tools>
182
+ {% for tool in tools %}
183
+ {%- if 'function' in tool -%}
184
+ {%- set tool = tool['function'] -%}
185
+ {%- endif -%}
186
+ {% if tool.defer_loading is not defined or not tool.defer_loading %}
187
+ {{ tool_to_json(tool) }}
188
+ {% endif %}
189
+ {% endfor %}
190
+ </tools>
191
+
192
+ For each function call, output the function name and arguments within the following XML format:
193
+ <tool_call>{function-name}<arg_key>{arg-key-1}</arg_key><arg_value>{arg-value-1}</arg_value><arg_key>{arg-key-2}</arg_key><arg_value>{arg-value-2}</arg_value>...</tool_call>{%- endif -%}
194
+ {%- macro emit_image() -%}<|begin_of_image|><|image|><|end_of_image|>{%- endmacro -%}
195
+ {%- macro emit_video() -%}<|begin_of_video|><|video|><|end_of_video|>{%- endmacro -%}
196
+ {%- macro emit_audio() -%}<|begin_of_audio|><|end_of_audio|>{%- endmacro -%}
197
+ {%- macro visible_text(content) -%}
198
+ {%- if content is string -%}
199
+ {{- content -}}
200
+ {%- elif content is iterable and content is not mapping -%}
201
+ {%- for item in content -%}
202
+ {%- if item is mapping and item.type == 'text' -%}
203
+ {{- item.text -}}
204
+ {%- elif item is string -%}
205
+ {{- item -}}
206
+ {%- elif item is mapping and item.type in ['image', 'image_url'] -%}
207
+ {{- emit_image() -}}
208
+ {%- elif item is mapping and item.type in ['video', 'video_url'] -%}
209
+ {{- emit_video() -}}
210
+ {%- elif item is mapping and item.type in ['audio', 'audio_url', 'input_audio'] -%}
211
+ {{- emit_audio() -}}
212
+ {%- endif -%}
213
+ {%- endfor -%}
214
+ {%- else -%}
215
+ {{- content }}
216
+ {%- endif -%}
217
+ {%- endmacro -%}
218
+ {%- macro tool_response(text) -%}
219
+ {{- '<tool_response>' + text + '</tool_response>' -}}
220
+ {%- endmacro -%}
221
+ {%- macro render_tool_response(m) -%}
222
+ {%- if m.content is string -%}
223
+ {{- tool_response(m.content) -}}
224
+ {%- elif m.content and m.content is not mapping and m.content.0.type == "tool_reference" -%}
225
+ {{- tool_references_to_response(m.content) -}}
226
+ {%- elif is_list_of_outputs(m) -%}
227
+ {%- for tr in m.content -%}
228
+ {%- if tr.output is iterable and tr.output is not string and tr.output is not mapping and tr.output and tr.output.0.type == "tool_reference" -%}
229
+ {{- tool_references_to_response(tr.output) -}}
230
+ {%- else -%}
231
+ {{- tool_response(visible_text(tr.output)) -}}
232
+ {%- endif -%}
233
+ {%- endfor -%}
234
+ {%- else -%}
235
+ {{- tool_response(visible_text(m.content)) -}}
236
+ {%- endif -%}
237
+ {%- endmacro -%}
238
+ {%- macro id_of(obj) -%}
239
+ {%- if obj.tool_call_id -%}
240
+ {{- obj.tool_call_id -}}
241
+ {%- elif obj.id -%}
242
+ {{- obj.id -}}
243
+ {%- endif -%}
244
+ {%- endmacro -%}
245
+ {%- macro is_list_of_outputs(m) -%}
246
+ {%- if m.content and m.content.0.output is defined -%}1{%- endif -%}
247
+ {%- endmacro -%}
248
+ {%- macro has_dup_tool_result_id(lo, hi, target) -%}
249
+ {%- set ns_cnt = namespace(n=0) -%}
250
+ {%- for k in range(lo, hi + 1) -%}
251
+ {%- set m = messages[k] -%}
252
+ {%- if is_list_of_outputs(m) -%}
253
+ {%- for entry in m.content -%}
254
+ {%- if id_of(entry) == target -%}
255
+ {%- set ns_cnt.n = ns_cnt.n + 1 -%}
256
+ {%- endif -%}
257
+ {%- endfor -%}
258
+ {%- elif id_of(m) == target -%}
259
+ {%- set ns_cnt.n = ns_cnt.n + 1 -%}
260
+ {%- endif -%}
261
+ {%- endfor -%}
262
+ {%- if ns_cnt.n > 1 -%}1{%- endif -%}
263
+ {%- endmacro -%}
264
+ {%- macro tc_id_exists(tcs, target) -%}
265
+ {%- set ns_f = namespace(found=false) -%}
266
+ {%- for tc in tcs -%}
267
+ {%- if id_of(tc) == target -%}
268
+ {%- set ns_f.found = true -%}
269
+ {%- endif -%}
270
+ {%- endfor -%}
271
+ {%- if ns_f.found -%}1{%- endif -%}
272
+ {%- endmacro -%}
273
+ {%- set ns = namespace(last_user_index=-1) -%}
274
+ {%- for m in messages %}
275
+ {%- if m.role == 'user' %}
276
+ {%- set ns.last_user_index = loop.index0 -%}
277
+ {%- endif %}
278
+ {%- endfor %}
279
+ {%- for m in messages -%}
280
+ {%- if m.role == 'user' -%}<|user|>{{ visible_text(m.content) }}
281
+ {%- elif m.role == 'assistant' -%}
282
+ <|assistant|>
283
+ {%- set content = visible_text(m.content) %}
284
+ {%- if m.reasoning_content is string %}
285
+ {%- set reasoning_content = m.reasoning_content %}
286
+ {%- elif '</think>' in content %}
287
+ {%- set reasoning_content = content.split('</think>')[0].split('<think>')[-1] %}
288
+ {%- set content = content.split('</think>')[-1] %}
289
+ {%- endif %}
290
+ {%- if (not clear_thinking or loop.index0 > ns.last_user_index) and reasoning_content is defined -%}
291
+ {{ '<think>' + reasoning_content + '</think>'}}
292
+ {%- else -%}
293
+ {{ '<think></think>' }}
294
+ {%- endif -%}
295
+ {%- if content.strip() -%}
296
+ {{ content.strip() }}
297
+ {%- endif -%}
298
+ {% if m.tool_calls %}
299
+ {% for tc in m.tool_calls %}
300
+ {%- if tc.function %}
301
+ {%- set tc = tc.function %}
302
+ {%- endif %}
303
+ {{- '<tool_call>' + tc.name -}}
304
+ {% set _args = tc.arguments %}{% for k, v in _args.items() %}<arg_key>{{ k }}</arg_key><arg_value>{{ v | tojson(ensure_ascii=False) if v is not string else v }}</arg_value>{% endfor %}</tool_call>{% endfor %}
305
+ {% endif %}
306
+ {%- elif m.role == 'tool' -%}
307
+ {%- if loop.first or (messages[loop.index0 - 1].role != "tool") %}
308
+ {{- '<|observation|>' -}}
309
+ {%- set block_start = loop.index0 -%}
310
+ {%- set ns_blk = namespace(end=block_start, is_tool=true) -%}
311
+ {%- for j in range(block_start, messages|length) -%}
312
+ {%- if messages[j].role == 'tool' and ns_blk.is_tool -%}
313
+ {%- set ns_blk.end = j -%}
314
+ {%- else -%}
315
+ {%- set ns_blk.is_tool = false -%}
316
+ {%- endif -%}
317
+ {%- endfor -%}
318
+ {%- set ns_a = namespace(tool_calls=none) -%}
319
+ {%- if block_start > 0 and messages[block_start - 1].role == 'assistant' and messages[block_start - 1].tool_calls -%}
320
+ {%- set ns_a.tool_calls = messages[block_start - 1].tool_calls -%}
321
+ {%- endif -%}
322
+ {%- set ns_chk = namespace(can_sort=true) -%}
323
+ {%- if not ns_a.tool_calls -%}
324
+ {%- set ns_chk.can_sort = false -%}
325
+ {%- else -%}
326
+ {%- for k in range(block_start, ns_blk.end + 1) -%}
327
+ {%- set m = messages[k] -%}
328
+ {%- if is_list_of_outputs(m) -%}
329
+ {%- for entry in m.content -%}
330
+ {%- set eid = id_of(entry) -%}
331
+ {%- if not eid -%}
332
+ {%- set ns_chk.can_sort = false -%}
333
+ {%- elif has_dup_tool_result_id(block_start, ns_blk.end, eid) -%}
334
+ {%- set ns_chk.can_sort = false -%}
335
+ {%- elif not tc_id_exists(ns_a.tool_calls, eid) -%}
336
+ {%- set ns_chk.can_sort = false -%}
337
+ {%- endif -%}
338
+ {%- endfor -%}
339
+ {%- else -%}
340
+ {%- set tk_id = id_of(m) -%}
341
+ {%- if not tk_id -%}
342
+ {%- set ns_chk.can_sort = false -%}
343
+ {%- elif has_dup_tool_result_id(block_start, ns_blk.end, tk_id) -%}
344
+ {%- set ns_chk.can_sort = false -%}
345
+ {%- elif not tc_id_exists(ns_a.tool_calls, tk_id) -%}
346
+ {%- set ns_chk.can_sort = false -%}
347
+ {%- endif -%}
348
+ {%- endif -%}
349
+ {%- endfor -%}
350
+ {%- for i in range(ns_a.tool_calls | length) -%}
351
+ {%- set tc_id = id_of(ns_a.tool_calls[i]) -%}
352
+ {%- if not tc_id -%}
353
+ {%- set ns_chk.can_sort = false -%}
354
+ {%- endif -%}
355
+ {%- for j in range(i + 1, ns_a.tool_calls | length) -%}
356
+ {%- if id_of(ns_a.tool_calls[j]) == tc_id -%}
357
+ {%- set ns_chk.can_sort = false -%}
358
+ {%- endif -%}
359
+ {%- endfor -%}
360
+ {%- endfor -%}
361
+ {%- endif -%}
362
+ {%- if ns_chk.can_sort -%}
363
+ {%- for tc in ns_a.tool_calls -%}
364
+ {%- set tc_id = id_of(tc) -%}
365
+ {%- for k in range(block_start, ns_blk.end + 1) -%}
366
+ {%- set m = messages[k] -%}
367
+ {%- if is_list_of_outputs(m) -%}
368
+ {%- for entry in m.content -%}
369
+ {%- set eid = id_of(entry) -%}
370
+ {%- if eid == tc_id -%}
371
+ {%- if entry.output is iterable and entry.output is not string and entry.output is not mapping and entry.output and entry.output.0.type == "tool_reference" -%}
372
+ {{- tool_references_to_response(entry.output) -}}
373
+ {%- else -%}
374
+ {{- tool_response(visible_text(entry.output)) -}}
375
+ {%- endif -%}
376
+ {%- endif -%}
377
+ {%- endfor -%}
378
+ {%- else -%}
379
+ {%- set tk_id = id_of(m) -%}
380
+ {%- if tk_id == tc_id -%}
381
+ {{- render_tool_response(m) -}}
382
+ {%- endif -%}
383
+ {%- endif -%}
384
+ {%- endfor -%}
385
+ {%- endfor -%}
386
+ {%- else -%}
387
+ {%- for k in range(block_start, ns_blk.end + 1) -%}
388
+ {{- render_tool_response(messages[k]) -}}
389
+ {%- endfor -%}
390
+ {%- endif -%}
391
+ {% endif -%}
392
+ {%- elif m.role == 'system' -%}
393
+ <|system|>{{ visible_text(m.content) }}
394
+ {%- endif -%}
395
+ {%- endfor -%}
396
+ {%- if add_generation_prompt -%}
397
+ {% if not current_thinking %}<|assistant|>{{ '<think></think>' }}{% else %}<|assistant|>{{ '<think>' }}{% endif %}
398
+ {%- endif -%}
templates/llama3.jinja ADDED
@@ -0,0 +1,348 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 -%}
templates/mistral.jinja ADDED
@@ -0,0 +1,352 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {#- ================================================================= -#}
2
+ {#- HyperSynapse-SAS (SelfAgentSwarm) 10-Level Cognitive Architecture -#}
3
+ {#- Tailored for Mistral / Mixtral / Codestral / Pixtral -#}
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 + ' [/INST]
288
+ ' -}}
289
+ {%- elif message.role == "assistant" -%}
290
+ {%- set reasoning_content = '' -%}
291
+ {%- if message.reasoning_content is string -%}
292
+ {%- set reasoning_content = message.reasoning_content -%}
293
+ {%- endif -%}
294
+ {%- set reasoning_content = reasoning_content|trim -%}
295
+ {%- if preserve_thinking is undefined or preserve_thinking is true or loop.index0 > ns.last_query_index -%}
296
+ {{- '<|im_start|>' + message.role + '\n<think>\n' + reasoning_content + '\n</think>\n\n' + content -}}
297
+ {%- else -%}
298
+ {{- '<|im_start|>' + message.role + '\n' + content -}}
299
+ {%- endif -%}
300
+ {%- if message.tool_calls and message.tool_calls is iterable and message.tool_calls is not mapping -%}
301
+ {%- for tool_call in message.tool_calls -%}
302
+ {%- if tool_call.function is defined -%}
303
+ {%- set tool_call = tool_call.function -%}
304
+ {%- endif -%}
305
+ {%- if loop.first -%}
306
+ {%- if content|trim -%}
307
+ {{- '\n\n<tool_call>\n<function=' + tool_call.name + '>\n' -}}
308
+ {%- else -%}
309
+ {{- '<tool_call>\n<function=' + tool_call.name + '>\n' -}}
310
+ {%- endif -%}
311
+ {%- else -%}
312
+ {{- '\n<tool_call>\n<function=' + tool_call.name + '>\n' -}}
313
+ {%- endif -%}
314
+ {%- if tool_call.arguments is defined and tool_call.arguments != '' -%}
315
+ {%- for args_name, args_value in tool_call.arguments|items -%}
316
+ {{- '<parameter=' + args_name + '>\n' -}}
317
+ {%- set args_value = args_value | string if args_value is string else args_value | tojson | safe -%}
318
+ {{- args_value -}}
319
+ {{- '\n</parameter>\n' -}}
320
+ {%- endfor -%}
321
+ {%- endif -%}
322
+ {{- '</function>\n</tool_call>' -}}
323
+ {%- endfor -%}
324
+ {%- endif -%}
325
+ {{- ' [/INST]
326
+ ' -}}
327
+ {%- elif message.role == "tool" -%}
328
+ {%- if loop.previtem and loop.previtem.role != "tool" -%}
329
+ {{- '<|im_start|>user' -}}
330
+ {%- endif -%}
331
+ {{- '\n<tool_response>\n' -}}
332
+ {{- content -}}
333
+ {{- '\n</tool_response>' -}}
334
+ {%- if not loop.last and loop.nextitem.role != "tool" -%}
335
+ {{- ' [/INST]
336
+ ' -}}
337
+ {%- elif loop.last -%}
338
+ {{- ' [/INST]
339
+ ' -}}
340
+ {%- endif -%}
341
+ {%- else -%}
342
+ {{- raise_exception('Unexpected message role.') -}}
343
+ {%- endif -%}
344
+ {%- endfor -%}
345
+ {%- if add_generation_prompt -%}
346
+ {{- '' -}}
347
+ {%- if not current_thinking -%}
348
+ {{- '<think>\n\n</think>\n\n' -}}
349
+ {%- else -%}
350
+ {{- '<think>\n' -}}
351
+ {%- endif -%}
352
+ {%- endif -%}
templates/qwen.jinja ADDED
@@ -0,0 +1,347 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 -%}
templates/universal.jinja ADDED
@@ -0,0 +1,348 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {#- ================================================================= -#}
2
+ {#- HyperSynapse-SAS (SelfAgentSwarm) 10-Level Cognitive Architecture -#}
3
+ {#- Model-Agnostic / Universal ChatML Chat Template -#}
4
+ {#- Compatible with any LLM runtime (llama.cpp, vLLM, SGLang, Ollama) -#}
5
+ {#- Levels: 0=Mortal/Disabled, 1=Hermes/ulow, 2=Apollo/low, -#}
6
+ {#- 3=Artemis/lmed, 4=Athena/medium, 5=Prometheus/mhigh, -#}
7
+ {#- 6=Solstice/high, 7=Hyperion/xhigh (Default), 8=Einstein (Solo), -#}
8
+ {#- 9=Oracle (Solo). Swarm: swarm (20-Agent), deep-swarm (Council) -#}
9
+ {#- ================================================================= -#}
10
+ {%- set inst_hermes -%}
11
+ [COGNITIVE FRAMEWORK: HERMES — LEVEL 1 (ULTRALOW / RAPID INSTINCT)]
12
+ Role & Persona: You are Hermes, the swift cognitive vanguard. Your duty is high-velocity precision, immediate execution, and rapid sanity checks without cognitive stalling.
13
+
14
+ Operational Directives:
15
+ - 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.
16
+ - Step 1 (Intent & Core Deconstruction): Strip away surface verbiage; pinpoint the exact core entity, mathematical quantity, code function, or direct question asked.
17
+ - Step 2 (Rapid Sanity & Boundary Check): Perform an immediate sanity check on the primary premise. Spot-check basic arithmetic, syntax constraints, or binary logic.
18
+ - Step 3 (Direct Route to Conclusion): Discard unnecessary discursive exposition. Formulate the shortest verified logical bridge from premise to conclusion cleanly.
19
+ {%- endset -%}
20
+ {%- set inst_apollo -%}
21
+ [COGNITIVE FRAMEWORK: APOLLO — LEVEL 2 (LOW / CRISP LOGIC & CLARITY)]
22
+ Role & Persona: You are Apollo, embodiment of light, structured clarity, and disciplined deduction. Your purpose is crisp, transparent verification with zero cognitive clutter.
23
+
24
+ Operational Directives:
25
+ - Cognitive Pacing: Compact, focused reasoning. Give the problem exactly the runway needed to establish correctness, and conclude directly once the premise is validated.
26
+ - Step 1 (Constraint Mapping): Explicitly isolate all constraints, parameters, data types, and user conditions. Distinguish between hard invariants and stylistic preferences.
27
+ - Step 2 (Linear Deductive Trace): Trace each premise to its immediate implication. Verify that intermediate deductions follow strictly from established facts or mathematical laws.
28
+ - Step 3 (Clarity & Elimination of Ambiguity): If a prompt contains ambiguous terminology, resolve it by adopting the most technically standard, productive interpretation without derailment.
29
+ {%- endset -%}
30
+ {%- set inst_artemis -%}
31
+ [COGNITIVE FRAMEWORK: ARTEMIS — LEVEL 3 (LOW-MEDIUM / PRECISION EDGE-CASE HUNTER)]
32
+ Role & Persona: You are Artemis, the unerring tracker and boundary hunter. Your focus is targeted audit, vulnerability identification, and stress-testing unstated edge cases.
33
+
34
+ Operational Directives:
35
+ - Cognitive Pacing: Measured, purpose-driven scrutiny. Allow sufficient analytical space to seek out and evaluate hidden traps, zero conditions, and failure modes.
36
+ - Step 1 (Perimeter & Edge-Case Scan): Systematically probe problem boundaries: numerical zero/negatives/overflow, null pointers, empty iterables, missing keys, concurrency collisions.
37
+ - Step 2 (Vulnerability Audit): Before accepting an initial hypothesis, identify how it could fail in unusual or high-stress conditions.
38
+ - Step 3 (Fortification & Verification): Patch identified weaknesses. Ensure the final response accounts for the worst-case operating envelope.
39
+ {%- endset -%}
40
+ {%- set inst_athena -%}
41
+ [COGNITIVE FRAMEWORK: ATHENA — LEVEL 4 (MEDIUM / STRATEGIC SYNTHESIS & BALANCE)]
42
+ Role & Persona: You are Athena, goddess of strategic wisdom, architectural balance, and sound judgment. You orchestrate comprehensive, balanced deliberation.
43
+
44
+ Operational Directives:
45
+ - Cognitive Pacing: Balanced, structural deliberation. Thought depth scales naturally with task complexity: simple requests receive succinct synthesis; multi-faceted problems receive rigorous decomposition.
46
+ - Step 1 (Architectural Deconstruction): Break complex requests into modular sub-tasks. Identify prerequisites, core mechanisms, and expected outputs.
47
+ - Step 2 (Trade-off & Option Assessment): Contrast plausible solution patterns (performance vs. readability, latency vs. throughput, modularity vs. simplicity). Justify chosen trade-offs.
48
+ - 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.
49
+ {%- endset -%}
50
+ {%- set inst_prometheus -%}
51
+ [COGNITIVE FRAMEWORK: PROMETHEUS — LEVEL 5 (MEDIUM-HIGH / ARCHITECTURAL FORETHOUGHT)]
52
+ Role & Persona: You are Prometheus, titan of forethought and craftsmanship. Your mandate is proactive engineering, downstream impact analysis, and systemic resilience.
53
+
54
+ Operational Directives:
55
+ - Cognitive Pacing: Deliberate systemic forethought. Deeply explore failure modes, scaling bottlenecks, and life-cycle implications before finalizing conclusions.
56
+ - Step 1 (Context & Dependency Topology): Map how this solution fits into real-world production environments. Account for hardware limits, network latency, and concurrency.
57
+ - Step 2 (Second-Order Effect Modeling): Account for 10x-100x scale, upstream dependency crashes, malformed payloads, technical debt, and memory footprints.
58
+ - Step 3 (Defensive Engineering): Integrate fault tolerance, robust error handling, structured validation gates, and graceful degradation into the design.
59
+ {%- endset -%}
60
+ {%- set inst_solstice -%}
61
+ [COGNITIVE FRAMEWORK: SOLSTICE — LEVEL 6 (HIGH / DEEP SYSTEMIC DERIVATION)]
62
+ Role & Persona: You are Solstice, representing total illumination, deep systemic derivation, and uncompromising verification. No assumptions are taken on faith.
63
+
64
+ Operational Directives:
65
+ - Cognitive Pacing: Deep, continuous deliberation. Take full runway to trace formal proofs, explore competing hypotheses, and stress-test assumptions.
66
+ - Step 1 (First-Principles Foundation): Explicitly declare foundational axioms, system properties, and mathematical truths governing the problem.
67
+ - Step 2 (Multi-Branch Hypothesis Generation): Generate at least two fundamentally different approaches or proof tracks. Analyze the mathematical or logical properties of each.
68
+ - Step 3 (Red-Team Adversarial Audit): Actively attempt to falsify your own leading hypothesis. Seek counterexamples, degenerate cases, and boundary contradictions.
69
+ - Step 4 (Rigorous Formal Reconciliation): Reconcile all edge cases, tighten proofs, eliminate redundant logic, and verify that the resulting solution is optimal and sound.
70
+ {%- endset -%}
71
+ {%- set inst_hyperion -%}
72
+ [COGNITIVE FRAMEWORK: HYPERION — LEVEL 7 (XHIGH / NATIVE RIGOROUS CONTINUUM — DEFAULT)]
73
+ Role & Persona: You are Hyperion, titan of observation and continuous rigorous derivation. You operate at the native maximum cognitive depth of Qwen 3.8.
74
+
75
+ Operational Directives:
76
+ - Cognitive Pacing: Unbounded, meticulous analytical progression. Let your internal reasoning explore every nuance, sub-clause, and implicit requirement of the user request.
77
+ - Step 1 (Exhaustive Semantic Deconstruction): Fully unpack the user prompt, implicit domain requirements, constraints, style specifications, and underlying goals.
78
+ - Step 2 (Deep Iterative Step-by-Step Derivation): Walk through each logical deduction, mathematical calculation, algorithm design, or architectural choice with total semantic completeness.
79
+ - 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.
80
+ - Step 4 (Synthesized Mastery): Produce a fully realized, deeply vetted, production-ready deliverable that requires no further user clarification or debugging.
81
+ {%- endset -%}
82
+ {%- set inst_einstein -%}
83
+ [COGNITIVE FRAMEWORK: EINSTEIN — LEVEL 8 (UHIGH / SOLO THEORETICAL MASTERY)]
84
+ 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.
85
+
86
+ Operational Directives:
87
+ - Cognitive Pacing: Extended solo theoretical exploration. Dissect foundational laws, hidden invariants, and non-obvious mathematical analogies.
88
+ - Radical First-Principles Intuition: Strip away conventional dogma; isolate the bare informational and physical constraints of the problem.
89
+ - Lateral Synthesis: Formulate elegant, unified mathematical or architectural models that collapse multi-stage complexity into singular, coherent solutions.
90
+ - Rigorous Continuous Proof: Trace every deduction from base axioms through to unassailable conclusions, rigorously verifying edge conditions and asymptotic behavior.
91
+ {%- endset -%}
92
+ {%- set inst_oracle -%}
93
+ [COGNITIVE FRAMEWORK: ORACLE — LEVEL 9 (AMAX / SOLO EXHAUSTIVE PROOF)]
94
+ Role & Persona: You are the Oracle operating in pure solo definitive authority. You produce verified, proof-grade, exhaustive engineering deliverables and mathematical certainty.
95
+
96
+ Operational Directives:
97
+ - Cognitive Pacing: Deepest continuous solo analytical runway. Leave absolutely nothing to chance or intuition.
98
+ - Exhaustive Root Deconstruction: Decompose the problem into atomic constituents; verify every underlying assumption, lemma, and invariant.
99
+ - Adversarial Self-Falsification: Systematically challenge every proposed step against worst-case inputs, stress thresholds, and degenerate edge states.
100
+ - Definitive Synthesis: Deliver the complete, finalized solution with unmatched technical accuracy, explicit proofs, and total implementation completeness.
101
+ {%- endset -%}
102
+ {%- set inst_swarm -%}
103
+ [COGNITIVE FRAMEWORK: 20-AGENT DIVERGENT SWARM — SPECIALIZED SWARM MODE]
104
+ Role & Persona: You are the Einstein Divergent Swarm Coordinator. Your purpose is breakthrough problem solving, radical lateral thinking, and multi-perspective emergence.
105
+
106
+ Operational Protocol — The 20-Perspective Swarm:
107
+ - Cognitive Pacing: Broad divergent exploration across multiple cognitive modalities followed by structured convergence. Scale token depth to the magnitude of the challenge.
108
+ - Phase 1 (First-Principles Disassembly): Strip the problem of conventional paradigms. Isolate the bare informational, mathematical, or mechanical core.
109
+ - Phase 2 (Perspective Swarm Activation): Internally simulate an array of up to 20 specialized virtual cognitive agents across Sternberg styles:
110
+ 1. Analytical Logician: Evaluates formal validity, mathematical correctness, and axiom purity.
111
+ 2. Creative Maverick: Explores radical, non-traditional metaphors, lateral paradigms, and disruptive angles.
112
+ 3. Pragmatic Systems Engineer: Grounding in real-world feasibility, hardware limits, and operational cost.
113
+ 4. Adversarial Red-Teamer: Attempts to break every proposed concept with exploit vectors and stress tests.
114
+ 5. Systems Dynamics Modeler: Traces feedback loops, emergent properties, and long-term equilibria.
115
+ 6. Algorithmic Optimizer: Focuses on computational complexity, asymptotic efficiency, and memory hierarchies.
116
+ 7. Human Factors Critic: Analyzes cognitive ergonomics, developer experience, and interface clarity.
117
+ - 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.
118
+ - Phase 4 (Convergence & Polish): Filter out noise, solidify the highest-conviction breakthrough, and present a coherent, unified, master-level deliverable.
119
+ {%- endset -%}
120
+ {%- set inst_deep_swarm -%}
121
+ [COGNITIVE FRAMEWORK: DEEP RESEARCH COUNCIL — SPECIALIZED DEEP-SWARM MODE]
122
+ Role & Persona: You are the Oracle Meta-Research Council. You simulate an exhaustive multi-expert research institute to produce verified, proof-grade, definitive results.
123
+
124
+ Operational Protocol — The Deep Research Standard:
125
+ - Cognitive Pacing: Deepest analytical deliberation. Dynamically calibrate the complexity of the inquiry (Scale 1 to 5) and expand your reasoning runway accordingly.
126
+ - Protocol 1 (Problem Calibration & Scope Framing): Rate task complexity from 1 to 5; explicitly identify domain boundaries and success criteria.
127
+ - 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).
128
+ - Protocol 3 (Adversarial Deliberation & Proof Trace): Have experts debate the problem, expose hidden assumptions, challenge lazy consensus, and require formal verification traces.
129
+ - 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.
130
+ - Protocol 5 (Master Deliverable Synthesis): Present the definitive final result with unmatched thoroughness, clear structure, and complete implementation.
131
+ {%- endset -%}
132
+ {%- set image_count = namespace(value=0) -%}
133
+ {%- set video_count = namespace(value=0) -%}
134
+ {%- macro render_content(content, do_vision_count, is_system_content=false) -%}
135
+ {%- if content is string -%}
136
+ {{- content -}}
137
+ {%- elif content is iterable and content is not mapping -%}
138
+ {%- for item in content -%}
139
+ {%- if 'image' in item or 'image_url' in item or item.type == 'image' -%}
140
+ {%- if is_system_content -%}
141
+ {{- raise_exception('System message cannot contain images.') -}}
142
+ {%- endif -%}
143
+ {%- if do_vision_count -%}
144
+ {%- set image_count.value = image_count.value + 1 -%}
145
+ {%- endif -%}
146
+ {%- if add_vision_id -%}
147
+ {{- 'Picture ' ~ image_count.value ~ ': ' -}}
148
+ {%- endif -%}
149
+ {{- '<|vision_start|><|image_pad|><|vision_end|>' -}}
150
+ {%- elif 'video' in item or item.type == 'video' -%}
151
+ {%- if is_system_content -%}
152
+ {{- raise_exception('System message cannot contain videos.') -}}
153
+ {%- endif -%}
154
+ {%- if do_vision_count -%}
155
+ {%- set video_count.value = video_count.value + 1 -%}
156
+ {%- endif -%}
157
+ {%- if add_vision_id -%}
158
+ {{- 'Video ' ~ video_count.value ~ ': ' -}}
159
+ {%- endif -%}
160
+ {{- '<|vision_start|><|video_pad|><|vision_end|>' -}}
161
+ {%- elif 'text' in item -%}
162
+ {{- item.text -}}
163
+ {%- else -%}
164
+ {{- raise_exception('Unexpected item type in content.') -}}
165
+ {%- endif -%}
166
+ {%- endfor -%}
167
+ {%- elif content is none or content is undefined -%}
168
+ {{- '' -}}
169
+ {%- else -%}
170
+ {{- raise_exception('Unexpected content type.') -}}
171
+ {%- endif -%}
172
+ {%- endmacro -%}
173
+ {%- if not messages -%}
174
+ {{- raise_exception('No messages provided.') -}}
175
+ {%- endif -%}
176
+ {%- set store = namespace(messages=[], reasoning_effort=reasoning_effort|default(''), enable_thinking=enable_thinking|default(true)) -%}
177
+ {%- for msg in messages -%}
178
+ {%- set raw_reason = "" -%}
179
+ {%- set txt = render_content(msg.content, false, true) | trim -%}
180
+ {%- if "{REASON:" in txt -%}
181
+ {%- set after_tag = txt.split("{REASON:") -%}
182
+ {%- set raw_reason = after_tag[1].split("}")[0] | lower | trim -%}
183
+ {%- set tag = "{REASON:" ~ after_tag[1].split("}")[0] ~ "}" -%}
184
+ {%- set clean_txt = txt.replace(tag, "") | trim -%}
185
+ {%- set store.messages = store.messages + [{"role": msg.role, "content": clean_txt}] -%}
186
+ {%- elif "[MODE:" in txt -%}
187
+ {%- set after_tag = txt.split("[MODE:") -%}
188
+ {%- set raw_reason = after_tag[1].split("]")[0] | lower | trim -%}
189
+ {%- set tag = "[MODE:" ~ after_tag[1].split("]")[0] ~ "]" -%}
190
+ {%- set clean_txt = txt.replace(tag, "") | trim -%}
191
+ {%- set store.messages = store.messages + [{"role": msg.role, "content": clean_txt}] -%}
192
+ {%- else -%}
193
+ {%- set store.messages = store.messages + [{"role": msg.role, "content": txt}] -%}
194
+ {%- endif -%}
195
+ {%- if raw_reason -%}
196
+ {%- if raw_reason.startswith('i') and raw_reason | length > 1 -%}
197
+ {%- set store.reasoning_effort = raw_reason[1:] -%}
198
+ {%- set store.enable_thinking = false -%}
199
+ {%- else -%}
200
+ {%- set store.reasoning_effort = raw_reason -%}
201
+ {%- endif -%}
202
+ {%- endif -%}
203
+ {%- endfor -%}
204
+ {%- set messages = store.messages -%}
205
+ {%- set current_effort = store.reasoning_effort | default(reasoning_effort|default(thinking_level|default('xhigh'))) | string | lower | trim -%}
206
+ {%- set current_thinking = store.enable_thinking -%}
207
+ {%- if current_effort in ['0', 'disabled', 'none', 'off', 'zero', 'direct', 'mortal', 'chat'] -%}
208
+ {%- set current_thinking = false -%}
209
+ {%- set reasoning_instructions = '' -%}
210
+ {%- elif current_effort in ['1', 'ulow', 'ultra-low', 'micro', 'minimal', 'hermes'] -%}
211
+ {%- set reasoning_instructions = inst_hermes -%}
212
+ {%- elif current_effort in ['2', 'low', 'compact', 'fast', 'apollo'] -%}
213
+ {%- set reasoning_instructions = inst_apollo -%}
214
+ {%- elif current_effort in ['3', 'lmed', 'low-medium', 'targeted', 'artemis'] -%}
215
+ {%- set reasoning_instructions = inst_artemis -%}
216
+ {%- elif current_effort in ['4', 'medium', 'med', 'balanced', 'athena'] -%}
217
+ {%- set reasoning_instructions = inst_athena -%}
218
+ {%- elif current_effort in ['5', 'mhigh', 'medium-high', 'architect', 'prometheus'] -%}
219
+ {%- set reasoning_instructions = inst_prometheus -%}
220
+ {%- elif current_effort in ['6', 'high', 'deep', 'thorough', 'solstice'] -%}
221
+ {%- set reasoning_instructions = inst_solstice -%}
222
+ {%- elif current_effort in ['7', 'xhigh', 'extreme-high', 'rigorous', 'hyperion', 'default'] -%}
223
+ {%- set reasoning_instructions = inst_hyperion -%}
224
+ {%- elif current_effort in ['8', 'uhigh', 'ultra-high', 'einstein', 'solo-einstein'] -%}
225
+ {%- set reasoning_instructions = inst_einstein -%}
226
+ {%- elif current_effort in ['9', 'amax', 'absolute-max', 'oracle', 'solo-oracle', 'proof'] -%}
227
+ {%- set reasoning_instructions = inst_oracle -%}
228
+ {%- elif current_effort in ['swarm', 'einstein-swarm', '20-swarm', 'uhigh-swarm'] -%}
229
+ {%- set reasoning_instructions = inst_swarm -%}
230
+ {%- elif current_effort in ['deep-swarm', 'oracle-swarm', 'council', 'amax-swarm', 'deep-research'] -%}
231
+ {%- set reasoning_instructions = inst_deep_swarm -%}
232
+ {%- else -%}
233
+ {%- set reasoning_instructions = inst_hyperion -%}
234
+ {%- endif -%}
235
+ {%- if tools and tools is iterable and tools is not mapping -%}
236
+ {{- '<|im_start|>system\n' -}}
237
+ {%- if reasoning_instructions -%}
238
+ {{- reasoning_instructions + '\n\n' -}}
239
+ {%- endif -%}
240
+ {{- "# Tools\n\nYou have access to the following functions:\n\n<tools>" -}}
241
+ {%- for tool in tools -%}
242
+ {{- "\n" -}}
243
+ {{- tool | tojson -}}
244
+ {%- endfor -%}
245
+ {{- "\n</tools>" -}}
246
+ {{- '\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>' -}}
247
+ {%- if messages[0].role == 'system' -%}
248
+ {%- set content = render_content(messages[0].content, false, true)|trim -%}
249
+ {%- if content -%}
250
+ {{- '\n\n' + content -}}
251
+ {%- endif -%}
252
+ {%- endif -%}
253
+ {{- '<|im_end|>\n' -}}
254
+ {%- else -%}
255
+ {%- if messages[0].role == 'system' -%}
256
+ {%- set content = render_content(messages[0].content, false, true)|trim -%}
257
+ {%- if content -%}
258
+ {{- '<|im_start|>system\n' + (reasoning_instructions + '\n\n' if reasoning_instructions else '') + content + '<|im_end|>\n' -}}
259
+ {%- elif reasoning_instructions -%}
260
+ {{- '<|im_start|>system\n' + reasoning_instructions + '<|im_end|>\n' -}}
261
+ {%- endif -%}
262
+ {%- elif reasoning_instructions -%}
263
+ {{- '<|im_start|>system\n' + reasoning_instructions + '<|im_end|>\n' -}}
264
+ {%- endif -%}
265
+ {%- endif -%}
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 + '<|im_end|>\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
+ {{- '<|im_end|>\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
+ {{- '<|im_end|>\n' -}}
334
+ {%- elif loop.last -%}
335
+ {{- '<|im_end|>\n' -}}
336
+ {%- endif -%}
337
+ {%- else -%}
338
+ {{- raise_exception('Unexpected message role.') -}}
339
+ {%- endif -%}
340
+ {%- endfor -%}
341
+ {%- if add_generation_prompt -%}
342
+ {{- '<|im_start|>assistant\n' -}}
343
+ {%- if not current_thinking -%}
344
+ {{- '<think>\n\n</think>\n\n' -}}
345
+ {%- else -%}
346
+ {{- '<think>\n' -}}
347
+ {%- endif -%}
348
+ {%- endif -%}