{{- bos_token -}} {%- if reasoning_effort == 'max' and messages|length > 0 -%} {{- "Reasoning Effort: Absolute maximum with no shortcuts permitted.\nYou 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.\nExplicitly write out your entire deliberation process, documenting every intermediate step, considered alternative, and rejected hypothesis to ensure absolutely no assumption is left unchecked.\n\n" -}} {%- endif -%} {#- System Prompt -#} {%- if messages|length > 0 and messages[0]['role'] == 'system' -%} {{- messages[0]['content'] -}} {%- endif -%} {#- Tools Template -#} {%- if tools -%} {{- "\n\n## 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\n...\n\n<|DSML|invoke name=\"$TOOL_NAME2\">\n...\n\n\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\nIf thinking_mode is enabled (triggered by ), you MUST output your complete reasoning inside ... BEFORE any tool calls or final response.\n\nOtherwise, output directly after with tool calls or final response.\n\n### Available Tool Schemas\n\n" -}} {%- for tool in tools -%} {{- tool | tojson -}}{{- "\n" -}} {%- endfor -%} {{- "\nYou MUST strictly follow the above defined tool name and parameter schemas to invoke tool calls." -}} {%- endif -%} {%- for message in messages -%} {%- if message['role'] == 'user' or message['role'] == 'developer' -%} {{- "<|User|>" -}} {#- 2a. Handle content blocks if preprocessed (for tool results merged into user) -#} {%- if message['content_blocks'] -%} {%- for block in message['content_blocks'] -%} {%- if block['type'] == 'text' -%} {{- block['text'] -}} {%- elif block['type'] == 'tool_result' -%} {{- "" ~ block['content'] ~ "" -}} {%- endif -%} {%- if not loop.last -%}{{- "\n\n" -}}{%- endif -%} {%- endfor -%} {%- else -%} {{- message['content'] -}} {%- endif -%} {#- Fallback for raw OpenAI-style tool messages not pre-processed into user blocks -#} {%- elif message['role'] == 'tool' -%} {{- "<|User|>" ~ message['content'] ~ "" -}} {%- elif message['role'] == 'assistant' -%} {{- "<|Assistant|>" -}} {%- if message['reasoning_content'] -%} {{- "" -}}{{- message['reasoning_content'] -}}{{- "" -}} {%- else -%} {{- "" -}} {%- endif -%} {%- if message['content'] -%} {{- message['content'] -}} {%- endif -%} {#- 3. Handle Assistant Tool Calls using DSML tags -#} {%- if message['tool_calls'] -%} {{- "\n\n<|DSML|tool_calls>\n" -}} {%- for tool_call in message['tool_calls'] -%} {{- "<|DSML|invoke name=\"" ~ tool_call['function']['name'] ~ "\">\n" -}} {#- Hugging Face automatically parses JSON string arguments into dictionaries. -#} {%- set args = tool_call['function']['arguments'] -%} {%- for key, value in args.items() -%} {%- if value is string -%} {{- "<|DSML|parameter name=\"" ~ key ~ "\" string=\"true\">" ~ value ~ "\n" -}} {%- else -%} {{- "<|DSML|parameter name=\"" ~ key ~ "\" string=\"false\">" ~ (value | tojson) ~ "\n" -}} {%- endif -%} {%- endfor -%} {{- "\n" -}} {%- endfor -%} {{- "" -}} {%- endif -%} {%- if not loop.last -%} {{- eos_token -}} {%- endif -%} {%- endif -%} {%- endfor -%} {%- if add_generation_prompt -%} {{- "<|Assistant|>" -}} {%- if reasoning_effort in ['thinking', 'max'] -%} {{- "" -}} {%- else -%} {{- "" -}} {%- endif -%} {%- endif -%}