{ "add_bos_token": false, "add_prefix_space": false, "added_tokens_decoder": { "248044": { "content": "<|endoftext|>", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": true }, "248045": { "content": "<|im_start|>", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": true }, "248046": { "content": "<|im_end|>", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": true }, "248047": { "content": "<|object_ref_start|>", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": true }, "248048": { "content": "<|object_ref_end|>", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": true }, "248049": { "content": "<|box_start|>", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": true }, "248050": { "content": "<|box_end|>", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": true }, "248051": { "content": "<|quad_start|>", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": true }, "248052": { "content": "<|quad_end|>", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": true }, "248053": { "content": "<|vision_start|>", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": true }, "248054": { "content": "<|vision_end|>", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": true }, "248055": { "content": "<|vision_pad|>", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": true }, "248056": { "content": "<|image_pad|>", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": true }, "248057": { "content": "<|video_pad|>", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": true }, "248058": { "content": "", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": false }, "248059": { "content": "", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": false }, "248060": { "content": "<|fim_prefix|>", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": false }, "248061": { "content": "<|fim_middle|>", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": false }, "248062": { "content": "<|fim_suffix|>", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": false }, "248063": { "content": "<|fim_pad|>", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": false }, "248064": { "content": "<|repo_name|>", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": false }, "248065": { "content": "<|file_sep|>", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": false }, "248066": { "content": "", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": false }, "248067": { "content": "", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": false }, "248068": { "content": "", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": false }, "248069": { "content": "", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": false }, "248070": { "content": "<|audio_start|>", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": true }, "248071": { "content": "<|audio_end|>", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": true }, "248072": { "content": "", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": true }, "248073": { "content": "", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": true }, "248074": { "content": "", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": true }, "248075": { "content": "", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": true }, "248076": { "content": "<|audio_pad|>", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": true } }, "additional_special_tokens": [ "<|im_start|>", "<|im_end|>" ], "bos_token": null, "chat_template": "{%- set template_version = \"qwen3.5-3.6-kat-qwopus-agentworld-ornith-merged-v3-agentic\" %}\n{#- =========================================================================================\n QWEN HYBRID AGENTIC CHAT TEMPLATE (KAT-Coder + Qwopus + AgentWorld + Ornith)\n Supported tool formats:\n - 'qwen3_coder' (default): Official XML syntax ()\n - 'json': Official Qwen / Qwopus JSON syntax ({\"name\":...,\"arguments\":...})\n Agentic Features:\n - Runtime protocol collision suppression (_suppress_tools / [TOOL_REQUEST])\n - 3-tier consecutive failure warning escalation (anti-loop circuit breaker)\n - MCP / ToolCall argument normalization (.arguments, .parameters, .input)\n - Non-destructive JSON response truncation protection\n - Dynamic thinking pruning on multi-turn trajectories\n ========================================================================================= -#}\n\n{%- set _tool_format = tool_call_format if tool_call_format is defined else 'qwen3_coder' %}\n{%- set enable_thinking = (enable_thinking not in (false, 'false', 'False', 0, '0', 'off', 'none')) if enable_thinking is defined else true %}\n{%- set auto_disable_thinking_with_tools = (auto_disable_thinking_with_tools in (true, 'true', 'True', 1, '1', 'on')) if auto_disable_thinking_with_tools is defined else false %}\n\n{%- if preserve_reasoning is defined and preserve_reasoning is not none %}\n {%- set _preserve_thinking = (preserve_reasoning not in (false, 'false', 'False', 0, '0', 'off', 'none')) %}\n{%- elif preserve_thinking is defined and preserve_thinking is not none %}\n {%- set _preserve_thinking = (preserve_thinking not in (false, 'false', 'False', 0, '0', 'off', 'none')) %}\n{%- else %}\n {%- set _preserve_thinking = true %}\n{%- endif %}\n\n{%- set max_tool_arg_chars = (max_tool_arg_chars | int) if (max_tool_arg_chars is defined and max_tool_arg_chars is not none) else 0 %}\n{%- set max_tool_response_chars = (max_tool_response_chars | int) if (max_tool_response_chars is defined and max_tool_response_chars is not none) else 0 %}\n{%- set _has_tools = (tools is defined and tools and tools is iterable and tools is not mapping) %}\n\n{# --- Dynamic Reasoning Effort Mapping --- #}\n{%- set _effort_raw = (reasoning_effort | string | lower) if reasoning_effort is defined and reasoning_effort is not none else 'medium' %}\n{%- set _initial_thinking = enable_thinking %}\n{%- set _initial_effort = 'medium' %}\n{%- if _effort_raw in ('none', 'off') %}\n {%- set _initial_thinking = false %}\n {%- set _initial_effort = 'medium' %}\n{%- elif _effort_raw in ('minimal', 'low') %}\n {%- set _initial_effort = 'low' %}\n{%- elif _effort_raw in ('high', 'xhigh', 'max', 'ultracode', 'extreme', 'deep', 'long') %}\n {%- set _initial_thinking = true %}\n {%- set _initial_effort = 'xhigh' %}\n{%- else %}\n {%- set _initial_effort = 'medium' %}\n{%- endif %}\n\n{%- set ns_state = namespace(thinking=_initial_thinking, effort=_initial_effort) %}\n{%- if auto_disable_thinking_with_tools and _has_tools %}\n {%- set ns_state.thinking = false %}\n{%- endif %}\n\n{# --- In-Prompt Thinking Directive Scanning --- #}\n{%- for msg in messages %}\n {%- if msg.role == 'system' or msg.role == 'developer' or msg.role == 'user' %}\n {%- if msg.content is string %}\n {%- if '<|think_off|>' in msg.content %}\n {%- set ns_state.thinking = false %}\n {%- elif '<|think_on|>' in msg.content %}\n {%- set ns_state.thinking = true %}\n {%- elif '<|think_xhigh|>' in msg.content or '<|think_high|>' in msg.content or '<|think_ultracode|>' in msg.content or '<|think_extreme|>' in msg.content or '<|think_max|>' in msg.content or '<|think_deep|>' in msg.content or '<|think_long|>' in msg.content %}\n {%- set ns_state.thinking = true %}\n {%- set ns_state.effort = 'xhigh' %}\n {%- elif '<|think_low|>' in msg.content or '<|think_minimal|>' in msg.content %}\n {%- set ns_state.thinking = true %}\n {%- set ns_state.effort = 'low' %}\n {%- elif '<|think_medium|>' in msg.content %}\n {%- set ns_state.thinking = true %}\n {%- set ns_state.effort = 'medium' %}\n {%- endif %}\n {%- elif msg.content is iterable and msg.content is not mapping %}\n {%- for item in msg.content %}\n {%- if item is string %}\n {%- set _item_text = item %}\n {%- elif item is mapping and 'text' in item and item.text is string %}\n {%- set _item_text = item.text %}\n {%- elif item is mapping and 'content' in item and item.content is string %}\n {%- set _item_text = item.content %}\n {%- else %}\n {%- set _item_text = '' %}\n {%- endif %}\n {%- if _item_text %}\n {%- if '<|think_off|>' in _item_text %}\n {%- set ns_state.thinking = false %}\n {%- elif '<|think_on|>' in _item_text %}\n {%- set ns_state.thinking = true %}\n {%- elif '<|think_xhigh|>' in _item_text or '<|think_high|>' in _item_text or '<|think_ultracode|>' in _item_text or '<|think_extreme|>' in _item_text or '<|think_max|>' in _item_text or '<|think_deep|>' in _item_text or '<|think_long|>' in _item_text %}\n {%- set ns_state.thinking = true %}\n {%- set ns_state.effort = 'xhigh' %}\n {%- elif '<|think_low|>' in _item_text or '<|think_minimal|>' in _item_text %}\n {%- set ns_state.thinking = true %}\n {%- set ns_state.effort = 'low' %}\n {%- elif '<|think_medium|>' in _item_text %}\n {%- set ns_state.thinking = true %}\n {%- set ns_state.effort = 'medium' %}\n {%- endif %}\n {%- endif %}\n {%- endfor %}\n {%- endif %}\n {%- endif %}\n{%- endfor %}\n\n{%- set reasoning_instructions = '' %}\n{%- if ns_state.thinking %}\n {%- if ns_state.effort == 'xhigh' %}\n {%- set reasoning_instructions = 'Reasoning effort is set to xhigh. Please think rigorously through the task, explore alternative hypotheses, validate edge cases, and prioritize architectural soundness, consistency, and correctness in the final answer.' %}\n {%- elif ns_state.effort == 'low' %}\n {%- set reasoning_instructions = 'Reasoning effort is set to low. Keep your thinking concise, focused, and move directly to execution or tool calls without unnecessary elaboration.' %}\n {%- endif %}\n{%- endif %}\n\n{# --- Content Render Macro (Enforces Pure-Text CausalLM) --- #}\n{%- macro render_content(content, is_system_content=false) %}\n {%- if content is string %}\n {{- content }}\n {%- elif content is iterable and content is not mapping %}\n {%- for item in content %}\n {%- if item is mapping %}\n {%- if item.type == 'image' or 'image' in item or 'image_url' in item %}\n {{- raise_exception('This model is a pure text CausalLM (vision tower removed). Image inputs are not supported.') }}\n {%- elif item.type == 'video' or 'video' in item %}\n {{- raise_exception('This model is a pure text CausalLM (vision tower removed). Video inputs are not supported.') }}\n {%- elif 'text' in item %}\n {{- (item.text | string) if item.text is not none else '' }}\n {%- elif 'content' in item and item.content is string %}\n {{- item.content }}\n {%- else %}\n {{- item | tojson }}\n {%- endif %}\n {%- else %}\n {{- item | string }}\n {%- endif %}\n {%- endfor %}\n {%- elif content is none or content is undefined %}\n {{- '' }}\n {%- else %}\n {{- raise_exception('Unexpected content type.') }}\n {%- endif %}\n{%- endmacro %}\n\n{%- if not messages %}\n {{- raise_exception('No messages provided.') }}\n{%- endif %}\n\n{# --- Head Extraction (System/Developer Messages) --- #}\n{%- set head = namespace(count=0, seen_non_system=false) %}\n{%- for message in messages %}\n {%- set _is_sys = (message.role == 'system' or message.role == 'developer') %}\n {%- if _is_sys and not head.seen_non_system %}\n {%- set head.count = head.count + 1 %}\n {%- else %}\n {%- set head.seen_non_system = true %}\n {%- endif %}\n{%- endfor %}\n\n{%- set sys_state = namespace(content='') %}\n{%- for message in messages[:head.count] %}\n {%- set _part = render_content(message.content, true) | trim %}\n {%- if '<|think_off|>' in _part %}{%- set _part = _part.split('<|think_off|>') | join('') | trim %}{%- endif %}\n {%- if '<|think_on|>' in _part %}{%- set _part = _part.split('<|think_on|>') | join('') | trim %}{%- endif %}\n {%- if '<|think_xhigh|>' in _part %}{%- set _part = _part.split('<|think_xhigh|>') | join('') | trim %}{%- endif %}\n {%- if '<|think_high|>' in _part %}{%- set _part = _part.split('<|think_high|>') | join('') | trim %}{%- endif %}\n {%- if '<|think_ultracode|>' in _part %}{%- set _part = _part.split('<|think_ultracode|>') | join('') | trim %}{%- endif %}\n {%- if '<|think_extreme|>' in _part %}{%- set _part = _part.split('<|think_extreme|>') | join('') | trim %}{%- endif %}\n {%- if '<|think_max|>' in _part %}{%- set _part = _part.split('<|think_max|>') | join('') | trim %}{%- endif %}\n {%- if '<|think_deep|>' in _part %}{%- set _part = _part.split('<|think_deep|>') | join('') | trim %}{%- endif %}\n {%- if '<|think_long|>' in _part %}{%- set _part = _part.split('<|think_long|>') | join('') | trim %}{%- endif %}\n {%- if '<|think_medium|>' in _part %}{%- set _part = _part.split('<|think_medium|>') | join('') | trim %}{%- endif %}\n {%- if '<|think_low|>' in _part %}{%- set _part = _part.split('<|think_low|>') | join('') | trim %}{%- endif %}\n {%- if '<|think_minimal|>' in _part %}{%- set _part = _part.split('<|think_minimal|>') | join('') | trim %}{%- endif %}\n {%- if _part %}\n {%- if sys_state.content %}\n {%- set sys_state.content = sys_state.content ~ '\\n\\n' ~ _part %}\n {%- else %}\n {%- set sys_state.content = _part %}\n {%- endif %}\n {%- endif %}\n{%- endfor %}\n\n{%- set _sc = sys_state.content %}\n{%- set _msgs = messages[head.count:] %}\n\n{# --- Optional Terse Directive --- #}\n{%- set _terse_on = (terse in (true, 'true', 'True', 1, '1', 'on')) if terse is defined else false %}\n{%- if _terse_on %}\n {%- if ns_state.thinking %}\n {%- set _terse_lead = 'Answer directly, after thinking. Lead with the answer, then only what it needs to be correct and usable.' %}\n {%- else %}\n {%- set _terse_lead = 'Answer directly and concisely. Give the answer with only what it needs to be correct and usable.' %}\n {%- endif %}\n {%- set _terse_core %}\nNever: open with preamble or pleasantries; restate the question; add filler transitions; hedge with niceties; or repeat a point you have already made.\nAlways: keep essential steps, caveats, uncertainties, and specifics \u2014 never drop correctness or a needed warning for brevity. Keep the final answer lean. Use the least structure that conveys it (plain prose when short; lists or code only when they earn their place). If genuinely uncertain, say so and explain why \u2014 never omit uncertainty for the sake of brevity.\nIf a user request is genuinely ambiguous, ask a sharp question, do not guess.\n {%- endset %}\n {%- set _terse = _terse_lead ~ '\\n' ~ (_terse_core | trim) %}\n {%- if not _sc %}\n {%- set _sc = _terse | trim %}\n {%- else %}\n {%- set _sc = (_sc | trim) ~ '\\n\\n' ~ (_terse | trim) %}\n {%- endif %}\n{%- endif %}\n\n{# --- Frontend Runtime Protocol Collision Detection (Borrowed from Donor 1) --- #}\n{%- set _runtime_tool_protocol = (_sc is defined and _sc and ('[TOOL_REQUEST]' in _sc or '[AVAILABLE_TOOLS]' in _sc or '' in _sc)) %}\n{%- set _suppress_tools = (suppress_tool_instructions in (true, 'true', 'True', 1, '1', 'on')) if suppress_tool_instructions is defined else _runtime_tool_protocol %}\n\n{# --- Tool System Prompt Injection --- #}\n{%- if _has_tools and not _suppress_tools %}\n {{- '<|im_start|>system\\n' }}\n {%- if reasoning_instructions %}\n {{- reasoning_instructions + '\\n\\n' }}\n {%- endif %}\n {{- '# Tools\\n\\nYou have access to the following functions:\\n\\n' }}\n {%- for tool in tools %}\n {{- '\\n' }}\n {{- tool | tojson }}\n {%- endfor %}\n {{- '\\n' }}\n {%- if _tool_format == 'json' %}\n {#- Canonical Qwen / Qwopus JSON invocation format (Borrowed from Donor 2) -#}\n {{- '\\n\\nFor each function call, return a json object with function name and arguments within XML tags:\\n' }}\n {%- if ns_state.thinking %}\n {{- '\\nBrief explanation of next step or parameter rationale\\n\\n' }}\n {%- endif %}\n {{- '\\n{\"name\": \"example_function_name\", \"arguments\": {\"example_parameter_1\": \"value_1\", \"example_parameter_2\": \"value_2\"}}\\n\\n\\n\\n' }}\n {%- if ns_state.thinking %}\n {{- '- All planning, hypothesis testing, and error reflection MUST be placed strictly inside the block.\\n' }}\n {{- '- Output the block IMMEDIATELY after thinking with NO conversational text before it.\\n' }}\n {%- else %}\n {{- '- Output the block IMMEDIATELY with NO conversational text before it.\\n' }}\n {%- endif %}\n {{- '- The tag MUST be at the very beginning of a new line, with NO indentation.\\n' }}\n {{- '- For multiple calls in parallel, output a separate block for EACH function. Do NOT nest calls.\\n' }}\n {{- '- Keep tool calls purposeful: issue only the calls required for the immediate next step.\\n' }}\n {{- '- Once all necessary data is gathered, provide your final answer directly without calling further tools.\\n' }}\n {%- else %}\n {#- Official Qwen3-Coder XML syntax () -#}\n {{- '\\n\\nIf you choose to call a function ONLY reply in the following format with NO suffix:\\n\\n' }}\n {%- if ns_state.thinking %}\n {{- '\\nBrief explanation of next step or parameter rationale\\n\\n' }}\n {%- endif %}\n {{- '\\n\\n\\nvalue_1\\n\\n\\nvalue_2\\n\\n\\n\\n\\n\\n' }}\n {%- if ns_state.thinking %}\n {{- '- All planning, hypothesis testing, and error reflection MUST be placed strictly inside the block.\\n' }}\n {{- '- Output the block IMMEDIATELY after thinking with NO conversational text before it.\\n' }}\n {%- else %}\n {{- '- Output the block IMMEDIATELY with NO conversational text before it.\\n' }}\n {%- endif %}\n {{- '- Function calls MUST follow the specified format: an inner block nested within tags.\\n' }}\n {{- '- The and tags MUST be at the very beginning of a new line, with NO spaces or indentation before them.\\n' }}\n {{- '- For multiple calls, output a separate, completely closed block for EACH function. Do NOT nest blocks.\\n' }}\n {{- '- Keep tool calls purposeful: issue only the calls required for the immediate next step.\\n' }}\n {{- '- Once all necessary data is gathered, provide your final answer directly without calling further tools.\\n' }}\n {%- endif %}\n {%- if _sc %}\n {{- '\\n\\n' + _sc }}\n {%- endif %}\n {{- '<|im_end|>\\n' }}\n{%- else %}\n {%- if _sc %}\n {{- '<|im_start|>system\\n' + (reasoning_instructions + '\\n\\n' if reasoning_instructions else '') + _sc + '<|im_end|>\\n' }}\n {%- elif reasoning_instructions %}\n {{- '<|im_start|>system\\n' + reasoning_instructions + '<|im_end|>\\n' }}\n {%- endif %}\n{%- endif %}\n\n{# --- Multi-Turn Trajectory Analysis (Scanning for Root User Query) --- #}\n{%- set ns = namespace(found_query=false, last_query_index=0) %}\n{%- for message in _msgs[::-1] %}\n {%- set index = (_msgs | length - 1) - loop.index0 %}\n {%- if not ns.found_query and message.role == 'user' %}\n {%- set _rc = render_content(message.content) | trim %}\n {%- if not (_rc.startswith('') and _rc.endswith('')) %}\n {%- set ns.found_query = true %}\n {%- set ns.last_query_index = index %}\n {%- endif %}\n {%- endif %}\n{%- endfor %}\n\n{# Fallback when entire context consists of autonomous tool loops (Borrowed from Donor 1) #}\n{%- if not ns.found_query and _msgs | length > 0 %}\n {%- set ns.last_query_index = (_msgs | length - 1) %}\n{%- endif %}\n\n{# --- Conversation Render Loop --- #}\n{%- set ns2 = namespace(prev_role='', consecutive_failures=0) %}\n{%- for message in _msgs %}\n {%- set is_system = (message.role == \"system\" or message.role == \"developer\") %}\n {%- set content = render_content(message.content, is_system) | trim %}\n {%- if is_system or message.role == 'user' %}\n {%- if '<|think_off|>' in content %}{%- set content = content.split('<|think_off|>') | join('') | trim %}{%- endif %}\n {%- if '<|think_on|>' in content %}{%- set content = content.split('<|think_on|>') | join('') | trim %}{%- endif %}\n {%- if '<|think_xhigh|>' in content %}{%- set content = content.split('<|think_xhigh|>') | join('') | trim %}{%- endif %}\n {%- if '<|think_high|>' in content %}{%- set content = content.split('<|think_high|>') | join('') | trim %}{%- endif %}\n {%- if '<|think_ultracode|>' in content %}{%- set content = content.split('<|think_ultracode|>') | join('') | trim %}{%- endif %}\n {%- if '<|think_extreme|>' in content %}{%- set content = content.split('<|think_extreme|>') | join('') | trim %}{%- endif %}\n {%- if '<|think_max|>' in content %}{%- set content = content.split('<|think_max|>') | join('') | trim %}{%- endif %}\n {%- if '<|think_deep|>' in content %}{%- set content = content.split('<|think_deep|>') | join('') | trim %}{%- endif %}\n {%- if '<|think_long|>' in content %}{%- set content = content.split('<|think_long|>') | join('') | trim %}{%- endif %}\n {%- if '<|think_medium|>' in content %}{%- set content = content.split('<|think_medium|>') | join('') | trim %}{%- endif %}\n {%- if '<|think_low|>' in content %}{%- set content = content.split('<|think_low|>') | join('') | trim %}{%- endif %}\n {%- if '<|think_minimal|>' in content %}{%- set content = content.split('<|think_minimal|>') | join('') | trim %}{%- endif %}\n {%- endif %}\n {%- if is_system %}\n {{- '<|im_start|>system\\n' + content + '<|im_end|>\\n' }}\n {%- elif message.role == 'user' %}\n {%- set ns2.consecutive_failures = 0 %}\n {{- '<|im_start|>user\\n' + content + '<|im_end|>\\n' }}\n {%- elif message.role == 'assistant' %}\n {%- set reasoning_content = '' %}\n {%- set _explicit_reasoning = '' %}\n {%- if message.reasoning_content is defined and message.reasoning_content is not none %}\n {%- if message.reasoning_content is string %}\n {%- set _explicit_reasoning = message.reasoning_content %}\n {%- elif message.reasoning_content is mapping and 'text' in message.reasoning_content %}\n {%- set _explicit_reasoning = message.reasoning_content.text | string %}\n {%- else %}\n {%- set _explicit_reasoning = message.reasoning_content | string %}\n {%- endif %}\n {%- elif message.thinking is defined and message.thinking is not none %}\n {%- if message.thinking is string %}\n {%- set _explicit_reasoning = message.thinking %}\n {%- elif message.thinking is mapping and 'text' in message.thinking %}\n {%- set _explicit_reasoning = message.thinking.text | string %}\n {%- else %}\n {%- set _explicit_reasoning = message.thinking | string %}\n {%- endif %}\n {%- elif message.reasoning is defined and message.reasoning is not none %}\n {%- if message.reasoning is string %}\n {%- set _explicit_reasoning = message.reasoning %}\n {%- elif message.reasoning is mapping and 'text' in message.reasoning %}\n {%- set _explicit_reasoning = message.reasoning.text | string %}\n {%- else %}\n {%- set _explicit_reasoning = message.reasoning | string %}\n {%- endif %}\n {%- endif %}\n {%- if _explicit_reasoning %}\n {%- set _lead_end = '' %}\n {%- if '' in content %}\n {%- set _lead_end = '' %}\n {%- elif '' in content %}\n {%- set _lead_end = '' %}\n {%- endif %}\n {%- if _lead_end %}\n {%- set _parts = content.split(_lead_end) %}\n {%- set content = (_parts[1:] | join(_lead_end)).lstrip('\\n') %}\n {%- endif %}\n {%- set reasoning_content = _explicit_reasoning %}\n {%- else %}\n {%- set _think_end = '' %}\n {%- if '' in content %}\n {%- set _think_end = '' %}\n {%- elif '' in content %}\n {%- set _think_end = '' %}\n {%- endif %}\n {%- if _think_end %}\n {%- set _think_start = '' if 'thinking' in _think_end else '' %}\n {%- set _parts = content.split(_think_end) %}\n {%- set reasoning_content = _parts[0].rstrip('\\n') %}\n {%- if _think_start in reasoning_content %}\n {%- set reasoning_content = reasoning_content.split(_think_start)[-1].lstrip('\\n') %}\n {%- endif %}\n {%- set content = (_parts[1:] | join(_think_end)).lstrip('\\n') %}\n {%- endif %}\n {%- endif %}\n {%- set reasoning_content = reasoning_content | trim %}\n\n {# Emit Assistant Thought and Content #}\n {%- if reasoning_content and (_preserve_thinking or loop.index0 >= ns.last_query_index) %}\n {{- '<|im_start|>assistant\\n\\n' + reasoning_content + '\\n\\n\\n' + content }}\n {%- else %}\n {{- '<|im_start|>assistant\\n' + content }}\n {%- endif %}\n\n {# Emit Tool Calls (Guarded against double emission if is already in content) #}\n {%- if message.tool_calls is defined and message.tool_calls and message.tool_calls is iterable and message.tool_calls is not mapping and '' not in content %}\n {%- for tool_call in message.tool_calls %}\n {%- if tool_call.function is defined and tool_call.function is not none %}\n {%- set tc = tool_call.function %}\n {%- else %}\n {%- set tc = tool_call %}\n {%- endif %}\n {%- set tc_name = tc.name if (tc.name is defined and tc.name is not none) else '' %}\n\n {# Resolve Arguments across OpenAI, Anthropic/Claude, and MCP schemas (.arguments, .parameters, .input) #}\n {%- set tc_args_raw = none %}\n {%- if tc.arguments is defined and tc.arguments is not none %}\n {%- set tc_args_raw = tc.arguments %}\n {%- elif tc.parameters is defined and tc.parameters is not none %}\n {%- set tc_args_raw = tc.parameters %}\n {%- elif tc.input is defined and tc.input is not none %}\n {%- set tc_args_raw = tc.input %}\n {%- endif %}\n\n {%- if _tool_format == 'json' %}\n {%- if loop.first %}\n {%- if content | trim %}\n {{- '\\n\\n' }}\n {%- endif %}\n {%- else %}\n {{- '\\n' }}\n {%- endif %}\n {%- set _args = '{}' %}\n {%- if tc_args_raw is not none %}\n {%- if tc_args_raw is mapping %}\n {%- set _args = tc_args_raw | tojson %}\n {%- elif tc_args_raw is string %}\n {%- set _trimmed_args = tc_args_raw | trim %}\n {%- if _trimmed_args | length > 0 %}\n {%- if _trimmed_args | first == '{' and _trimmed_args | last == '}' %}\n {%- set _args = _trimmed_args %}\n {%- else %}\n {%- set _args = tc_args_raw | tojson %}\n {%- endif %}\n {%- endif %}\n {%- else %}\n {%- set _args = tc_args_raw | tojson %}\n {%- endif %}\n {%- endif %}\n {{- '\\n{\"name\": ' }}{{- tc_name | tojson }}{{- ', \"arguments\": ' }}{{- _args }}{{- '}\\n' }}\n {%- else %}\n {%- if loop.first %}\n {%- if content | trim %}\n {{- '\\n\\n\\n\\n' }}\n {%- else %}\n {{- '\\n\\n' }}\n {%- endif %}\n {%- else %}\n {{- '\\n\\n\\n' }}\n {%- endif %}\n {%- if tc_args_raw is not none %}\n {%- if tc_args_raw is mapping %}\n {%- for args_name, args_value in tc_args_raw.items() %}\n {{- '\\n' }}\n {%- if args_value is string %}\n {%- set _av = args_value %}\n {%- else %}\n {%- set _av = args_value | tojson %}\n {%- endif %}\n {%- if max_tool_arg_chars > 0 and _av | length > max_tool_arg_chars %}\n {{- _av[:max_tool_arg_chars] + '\\n[TRUNCATED - original length ' ~ (_av | length | string) ~ ' chars]' }}\n {%- else %}\n {{- _av }}\n {%- endif %}\n {{- '\\n\\n' }}\n {%- endfor %}\n {%- else %}\n {%- if tc_args_raw is string %}\n {%- set _raw_args = tc_args_raw %}\n {%- else %}\n {%- set _raw_args = tc_args_raw | tojson %}\n {%- endif %}\n {%- if _raw_args %}\n {%- if max_tool_arg_chars > 0 and _raw_args | length > max_tool_arg_chars %}\n {{- _raw_args[:max_tool_arg_chars] + '\\n[TRUNCATED - original length ' ~ (_raw_args | length | string) ~ ' chars]' }}\n {%- else %}\n {{- _raw_args }}\n {%- endif %}\n {%- endif %}\n {%- endif %}\n {%- endif %}\n {{- '\\n' }}\n {%- endif %}\n {%- endfor %}\n {%- endif %}\n {{- '<|im_end|>\\n' }}\n {%- elif message.role == 'tool' %}\n {# --- Multi-Turn Tool Response & Escalating Circuit Breaker --- #}\n {%- set _content_lower = content | lower %}\n {%- set _content_head = _content_lower[:150] %}\n {%- set _is_code_or_grep = ('throw new ' in _content_lower or 'throw error' in _content_lower or 'console.error' in _content_lower or 'logger.error' in _content_lower or 'logging.error' in _content_lower or 'import ' in _content_head or 'def ' in _content_head or 'function ' in _content_head) %}\n {%- set _exit_code_zero = ('exit code: 0' in _content_head or 'process exited with code 0' in _content_head) %}\n {%- set _error_field_ok = ('\"error\": null' in _content_head or '\"error\":null' in _content_head or '\"error\": false' in _content_head or '\"error\":false' in _content_head or '\"error\": \"\"' in _content_head or '\"error\":\"\"' in _content_head) %}\n {%- set _strong_error = (('\"error\":' in _content_head and not _error_field_ok) or '\"status\": \"error\"' in _content_head or '\"status\":\"error\"' in _content_head or '\"success\": false' in _content_head or '\"success\":false' in _content_head or 'traceback (most recent call last):' in _content_head or 'command not found' in _content_head or 'invalid syntax' in _content_head or 'fatal:' in _content_head or 'permission denied' in _content_head or 'no such file or directory' in _content_head or '404 not found' in _content_head or 'rate limit' in _content_head or 'connection refused' in _content_head or 'timed out' in _content_head or (('exit code: ' in _content_head or 'process exited with code' in _content_head) and not _exit_code_zero) or _content_head.startswith('exception:') or _content_head.startswith('failed to ')) %}\n {%- set _weak_error = ('error:' in _content_head or 'err!' in _content_head) %}\n {%- set _weak_suppressed = ('$ ' in _content_head or 'took ' in _content_head or content | length >= 600) %}\n\n {%- if not _is_code_or_grep and (_strong_error or (_weak_error and not _weak_suppressed)) %}\n {%- set ns2.consecutive_failures = ns2.consecutive_failures + 1 %}\n {%- else %}\n {%- set ns2.consecutive_failures = 0 %}\n {%- endif %}\n\n {%- if ns2.prev_role != 'tool' %}\n {{- '<|im_start|>user' }}\n {%- endif %}\n\n {# Truncate non-JSON outputs safely, alert if JSON was clipped (Borrowed from Donor 1) #}\n {%- set _is_json_payload = (content | trim | length > 0 and (content | trim)[:1] in ('{', '[')) %}\n {%- if max_tool_response_chars > 0 and content | length > max_tool_response_chars %}\n {%- if _is_json_payload %}\n {%- set content = content[:max_tool_response_chars] + '\\n[TRUNCATED: Output exceeded ' ~ max_tool_response_chars ~ ' chars. Remaining JSON payload clipped]' %}\n {%- else %}\n {%- set content = content[:max_tool_response_chars] + '\\n[TRUNCATED - original length ' ~ (content | length | string) ~ ' chars]' %}\n {%- endif %}\n {%- endif %}\n\n {{- '\\n\\n' + content }}\n\n {# 3-Tier Failure Escalation (Anti-Loop Circuit Breaker) #}\n {%- if ns2.consecutive_failures >= 3 %}\n {{- '\\n\\n\u26a0\ufe0f SYSTEM WARNING: ' ~ ns2.consecutive_failures ~ ' consecutive tool errors detected. CRITICAL AGENTIC LOOP. Do NOT repeat the failed command or variations of it. If a dependency, tool, or path is missing, immediately PIVOT to an alternative diagnostic tool or report the blocker directly.' }}\n {%- elif ns2.consecutive_failures == 2 %}\n {{- '\\n\\n\u26a0\ufe0f SYSTEM WARNING: 2 consecutive tool errors detected. Your previous technical approach is fundamentally incorrect. You MUST diagnose root cause and use a completely different approach or command.' }}\n {%- elif ns2.consecutive_failures == 1 %}\n {{- '\\n\\n\u26a0\ufe0f SYSTEM WARNING: The previous tool call returned an error. Diagnose the failure and retry with corrected arguments.' }}\n {%- endif %}\n\n {{- '\\n' }}\n\n {%- if loop.last %}\n {{- '<|im_end|>\\n' }}\n {%- else %}\n {%- set _next_role = _msgs[loop.index0 + 1].role %}\n {%- if _next_role != 'tool' %}\n {{- '<|im_end|>\\n' }}\n {%- endif %}\n {%- endif %}\n {%- else %}\n {{- '<|im_start|>user\\n[' + message.role + ']: ' + content + '<|im_end|>\\n' }}\n {%- endif %}\n {%- set ns2.prev_role = message.role %}\n{%- endfor %}\n\n{# --- Generation Prompt --- #}\n{%- set _add_gen = (add_generation_prompt in (true, 'true', 'True', 1, '1', 'on')) if add_generation_prompt is defined else false %}\n{%- if _add_gen %}\n {{- '<|im_start|>assistant\\n' }}\n {%- if not ns_state.thinking %}\n {{- '\\n\\n\\n\\n' }}\n {%- else %}\n {{- '\\n' }}\n {%- endif %}\n{%- endif %}", "clean_up_tokenization_spaces": false, "eos_token": "<|im_end|>", "errors": "replace", "model_max_length": 262144, "padding_side": "left", "pad_token": "<|endoftext|>", "pretokenize_regex": "(?i:'s|'t|'re|'ve|'m|'ll|'d)|[^\\r\\n\\p{L}\\p{N}]?[\\p{L}\\p{M}]+|\\p{N}| ?[^\\s\\p{L}\\p{M}\\p{N}]+[\\r\\n]*|\\s*[\\r\\n]+|\\s+(?!\\S)|\\s+", "split_special_tokens": false, "tokenizer_class": "Qwen2Tokenizer", "unk_token": null }