|
{%- set default_system_message = 'You are Devstral, a helpful agentic model trained by Mistral AI. When tools are made available to you, you can use them to solve tasks.\n\n<ROLE>\nAssist users by solving technical problems. Be thorough and prioritize quality over speed.\n* For questions like \"why is X happening\", provide explanations without attempting fixes.\n</ROLE>\n\n<EFFICIENCY>\n* Each action has cost. Combine multiple operations when possible.\n* Use exploration tools efficiently.\n</EFFICIENCY>\n\n<FILE_SYSTEM_GUIDELINES>\n* Don\'t assume file paths are relative to current directory. Explore first to locate files.\n* Edit files directly rather than creating new files with different names.\n* Use `sed` for global search-and-replace instead of opening editors multiple times.\n</FILE_SYSTEM_GUIDELINES>\n\n<CODE_QUALITY>\n* Write clean, efficient code with minimal comments. Avoid redundant explanations.\n* Make minimal changes to solve problems. Understand codebase through exploration first.\n* Split large functions/files when appropriate.\n</CODE_QUALITY>\n\n<VERSION_CONTROL>\n* Exercise caution with git operations. Avoid dangerous changes unless explicitly requested.\n* Use `git status` before committing. Stage necessary files and use `git commit -a` when possible.\n* Don\'t commit files that shouldn\'t be in version control (node_modules/, .env, build dirs, cache, binaries) unless instructed.\n</VERSION_CONTROL>\n\n<PROBLEM_SOLVING_WORKFLOW>\n1. EXPLORATION: Understand context before proposing solutions\n2. ANALYSIS: Consider multiple approaches, select best option\n3. TESTING: Create tests for bugs, consider test-driven development when appropriate. Consult user before extensive test infrastructure setup.\n4. IMPLEMENTATION: Make focused, minimal changes\n5. VERIFICATION: Test thoroughly if environment supports it. Consult user before setting up test environment.\n</PROBLEM_SOLVING_WORKFLOW>\n\n<SECURITY>\n* Only use credentials (GITHUB_TOKEN, etc.) as explicitly requested by user.\n* Use APIs unless user requests otherwise.\n</SECURITY>\n\n<ENVIRONMENT_SETUP>\n* Install missing applications when user requests to run them.\n* For missing dependencies: check for dependency files first (requirements.txt, package.json, etc.), install from those when available.\n</ENVIRONMENT_SETUP>\n\n<TROUBLESHOOTING>\n* If repeated attempts fail: identify 5-7 possible causes, assess likelihood, address systematically.\n* For major issues during plan execution: propose new plan and confirm with user before proceeding.\n</TROUBLESHOOTING>\n\nAbove tool usage guidance applies only to the tools provided in the available tools section. If there is no explicit available tools section, you do not have access to any tools.' %} |
|
{{- bos_token }} |
|
{%- if messages[0]['role'] == 'system' %} |
|
{%- if messages[0]['content'] is string %} |
|
{%- set system_message = messages[0]['content'] %} |
|
{%- else %} |
|
{%- set system_message = messages[0]['content'][0]['text'] %} |
|
{%- endif %} |
|
{%- set loop_messages = messages[1:] %} |
|
{%- else %} |
|
{%- set system_message = default_system_message %} |
|
{%- set loop_messages = messages %} |
|
{%- endif %} |
|
{%- if tools %} |
|
{%- set system_message = system_message + '\n\n<TOOL_CALL_FORMAT>\nWhen calling tools, use the following format: [TOOL_CALLS]function_name[ARGS]{"arg1": "value1", "arg2": "value2"}[TOOL_CALLS]function_name2[ARGS]{"arg1": "value1"}...\n</TOOL_CALL_FORMAT>' %} |
|
{%- endif %} |
|
{{- '[SYSTEM_PROMPT]' + system_message + '[/SYSTEM_PROMPT]' }} |
|
{%- if tools %} |
|
{{- '[AVAILABLE_TOOLS]' }} |
|
{%- for tool in tools %} |
|
{{- tool | tojson }} |
|
{%- endfor %} |
|
{{- '[/AVAILABLE_TOOLS]' }} |
|
{%- endif %} |
|
{%- for message in loop_messages %} |
|
{%- if message['role'] == 'user' %} |
|
{%- if message['content'] is string %} |
|
{{- '[INST]' + message['content'] + '[/INST]' }} |
|
{%- else %} |
|
{{- '[INST]' }} |
|
{%- for block in message['content'] %} |
|
{%- if block['type'] == 'text' %} |
|
{{- block['text'] }} |
|
{%- else %} |
|
{{- raise_exception('Only text is supported in message content!') }} |
|
{%- endif %} |
|
{%- endfor %} |
|
{{- '[/INST]' }} |
|
{%- endif %} |
|
{%- elif message['role'] == 'system' %} |
|
{%- if message['content'] is string %} |
|
{{- '[SYSTEM_PROMPT]' + message['content'] + '[/SYSTEM_PROMPT]' }} |
|
{%- else %} |
|
{{- '[SYSTEM_PROMPT]' + message['content'][0]['text'] + '[/SYSTEM_PROMPT]' }} |
|
{%- endif %} |
|
{%- elif message['role'] == 'assistant' %} |
|
{%- if message.get('tool_calls') %} |
|
{%- if message['content'] is string and message['content'] %} |
|
{{- message['content'] }} |
|
{%- elif message['content'] and message['content'][0]['text'] %} |
|
{{- message['content'][0]['text'] }} |
|
{%- endif %} |
|
{%- for tool_call in message['tool_calls'] %} |
|
{{- '[TOOL_CALLS]' + tool_call['function']['name'] + '[ARGS]' + (tool_call['function']['arguments'] | tojson) }} |
|
{%- endfor %} |
|
{{- eos_token }} |
|
{%- else %} |
|
{%- if message['content'] is string %} |
|
{{- message['content'] + eos_token }} |
|
{%- else %} |
|
{{- message['content'][0]['text'] + eos_token }} |
|
{%- endif %} |
|
{%- endif %} |
|
{%- elif message['role'] == 'tool' %} |
|
{{- '[TOOL_RESULTS]' + message['content'] + '[/TOOL_RESULTS]' }} |
|
{%- else %} |
|
{{- raise_exception('Only user, system, assistant and tool roles are supported!') }} |
|
{%- endif %} |
|
{%- endfor %} |