| <|im_start|>system |
| You are an AI assistant that follows a Plan and Solve reasoning pattern. |
| |
| For each user query: |
| - First, create a PLAN inside a <think> tag. |
| - The PLAN should outline your reasoning steps and approach before answering. |
| - The PLAN is not shown to the user but should help you structure a high-quality answer. |
| - After </think>, provide your reply directly to the user, without mentioning the PLAN or the fact that you used <think>. |
| |
| Format example: |
| |
| <think> |
| PLAN: |
| 1. Analyze the user question. |
| 2. Identify key facts. |
| 3. Decide on the correct answer. |
| 4. Structure the reply clearly. |
| </think> |
| |
| Here is your answer to the question... |
| <|im_end|> |
| |
| {%- set ns = namespace(last_query_index=messages|length - 1) %} |
| {%- for message in messages[::-1] %} |
| {%- set index = (messages|length - 1) - loop.index0 %} |
| {%- if message.role == "user" %} |
| {%- set ns.last_query_index = index %} |
| {%- break %} |
| {%- endif %} |
| {%- endfor %} |
| |
| {%- for message in messages %} |
| {%- if (message.role == "user") or (message.role == "system" and not loop.first) %} |
| {{- '<|im_start|>' + message.role + '\n' + message.content + '<|im_end|>\n' }} |
| {%- elif message.role == "assistant" %} |
| {%- set content = message.content %} |
| {%- set reasoning_content = '' %} |
| {%- if message.reasoning_content is defined and message.reasoning_content is not none %} |
| {%- set reasoning_content = message.reasoning_content %} |
| {%- else %} |
| {%- if '</think>' in message.content %} |
| {%- set content = message.content.split('</think>')[-1].lstrip('\n') %} |
| {%- set reasoning_content = message.content.split('</think>')[0].rstrip('\n').split('<think>')[-1].lstrip('\n') %} |
| {%- endif %} |
| {%- endif %} |
| {%- if loop.index0 > ns.last_query_index %} |
| {%- if loop.last or (not loop.last and reasoning_content) %} |
| {{- '<|im_start|>' + message.role + '\n<think>\n' + reasoning_content.strip('\n') + '\n</think>\n\n' + content.lstrip('\n') }} |
| {%- else %} |
| {{- '<|im_start|>' + message.role + '\n' + content }} |
| {%- endif %} |
| {%- else %} |
| {{- '<|im_start|>' + message.role + '\n' + content }} |
| {%- endif %} |
| {{- '<|im_end|>\n' }} |
| {%- endif %} |
| {%- endfor %} |
| |
| {%- if add_generation_prompt %} |
| {{- '<|im_start|>assistant\n' }} |
| {%- if enable_thinking is defined and enable_thinking is false %} |
| {{- '<think>\n\n</think>\n\n' }} |
| {%- endif %} |
| {%- endif %} |
| |