gemma-agent-full-model-v3 / chat_template.jinja
jkgl's picture
Merged with extended systems, data, web, files, code tools and cache key
938493e verified
{% macro d() %}2025-10-09{% endmacro %}
{% macro ts(s,r) -%}
{%- if s.type == "array" -%}
{%- if s['items'] and s['items']['type'] in ["string","number","integer","boolean"] -%}
{%- if s['items']['type']=="integer" -%}number[]{%- elif s['items']['type']=="number" -%}number[]{%- elif s['items']['type']=="boolean" -%}boolean[]{%- else -%}string[]{%- endif -%}
{%- elif s['items'] -%}
{%- set t = ts(s['items'], r) -%}
{%- if t|length>50 -%}any[]{%- else -%}{{ t }}[]{%- endif -%}
{%- else -%}any[]{%- endif -%}
{%- elif s.oneOf -%}
{%- set parts = [] -%}
{%- for v in s.oneOf -%}{%- set parts = parts + [ts(v, r)] -%}{%- endfor -%}
{{ parts|join(" | ") }}
{%- elif s.type == "string" -%}
{%- if s.enum -%}"{{ s.enum|join('" | "')}}" {%- else -%}string{%- endif -%}
{%- elif s.type in ["number","integer"] -%}number
{%- elif s.type == "boolean" -%}boolean
{%- elif s.type == "object" -%}
{%- if s.properties -%}{
{%- for k,v in s.properties.items() -%}
{{- k }}{{ "" if k in (s.required or []) else "?" }}: {{ ts(v, s.required or []) }}{{ "," if not loop.last else "" }}
{%- endfor -%}
}
{%- else -%}object{%- endif -%}
{%- else -%}any{%- endif -%}
{%- endmacro %}
{% macro ns(name, tools) -%}
{{ "## " + name + "\n\n" }}
{{ "namespace " + name + " {\n\n" }}
{%- for t in tools -%}
{%- set tool = t.function if t.function is defined else t -%}
{{ "type " + tool.name + " = " }}
{%- if tool.parameters and tool.parameters.properties -%}
{{ "(_: {\n" }}
{%- for p,sp in tool.parameters.properties.items() -%}
{{ p }}{{ "" if p in (tool.parameters.required or []) else "?" }}: {{ ts(sp, tool.parameters.required or []) }}{{ ",\n" if not loop.last else ",\n" }}
{%- endfor -%}
{{ "}) => any;\n\n" }}
{%- else -%}
{{ "() => any;\n\n" }}
{%- endif -%}
{%- endfor -%}
{{ "} // namespace " + name }}
{%- endmacro %}
{% macro ext_files() -%}
## functions_extended_files
namespace functions_extended_files {
type execute_file = (_: { path: string, args?: string[], stdin?: string, timeout_s?: number, language_hint?: string, sandbox?: boolean }) => any;
type correct_file = (_: { path: string, rules?: string, style?: string, save_as?: string, diff_only?: boolean }) => any;
type interact_with_file = (_: { path: string, action: "read" | "write" | "append" | "metadata" | "extract_text" | "extract_tables" | "transcribe_audio" | "ocr" | "render_preview" | "thumbnail", payload?: string | { [k: string]: any }, selector?: string, encoding?: string, mime_hint?: string }) => any;
type transform_file = (_: { path: string, target_format: string, options?: { [k: string]: any }, save_as?: string }) => any;
type list_files = (_: { dir: string, glob?: string, recursive?: boolean, include_hidden?: boolean }) => any;
type read_file_chunk = (_: { path: string, offset?: number, length?: number, by_lines?: boolean }) => any;
type write_file_atomic = (_: { path: string, content: string, encoding?: string, make_dirs?: boolean }) => any;
type patch_file = (_: { path: string, patch: string, dry_run?: boolean }) => any;
type analyze_file = (_: { path: string, profile?: string, severity_min?: string }) => any;
type compute_hash = (_: { path: string, algo?: "md5" | "sha1" | "sha256" | "sha512" }) => any;
type archive_extract = (_: { path: string, destination?: string, password?: string }) => any;
type compress_file = (_: { path: string, archive_path?: string, format?: "zip" | "tar" | "tar.gz" | "tar.bz2" }) => any;
type office_convert = (_: { path: string, to: "pdf" | "docx" | "pptx" | "xlsx", save_as?: string }) => any;
type pdf_extract = (_: { path: string, pages?: string, images?: boolean }) => any;
type image_convert = (_: { path: string, to: string, options?: { [k: string]: any }, save_as?: string }) => any;
type audio_transcribe = (_: { path: string, language?: string, diarize?: boolean, save_as?: string }) => any;
type video_transcode = (_: { path: string, preset?: string, codec?: string, crf?: number, save_as?: string }) => any;
type stream_file = (_: { path: string, chunk_size?: number, by_lines?: boolean, delay_ms?: number }) => any;
type watch_file_changes = (_: { path: string, debounce_ms?: number }) => any;
}
{%- endmacro %}
{% macro ext_web() -%}
## functions_extended_web
namespace functions_extended_web {
type search_web = (_: { q: string }) => any;
type download_from_url = (_: { url: string, save_as?: string, headers?: { [k: string]: string } }) => any;
type network_fetch = (_: { url: string, method?: "GET" | "POST" | "PUT" | "PATCH" | "DELETE", headers?: { [k: string]: string }, body?: string }) => any;
type upload_to_hf = (_: { path: string, repo_id: string, repo_type?: "model" | "dataset" | "space", commit_message?: string, token?: string }) => any;
type cloud_save = (_: { path: string, dest: string, provider?: string, token?: string }) => any;
type cloud_load = (_: { src: string, save_as?: string, provider?: string, token?: string }) => any;
type web_screenshot = (_: { url: string, selector?: string, save_as?: string }) => any;
type sitemap_crawl = (_: { url: string, max_pages?: number, include_patterns?: string[], exclude_patterns?: string[] }) => any;
}
{%- endmacro %}
{% macro ext_code() -%}
## functions_extended_code
namespace functions_extended_code {
type run_python = (_: { code: string }) => any;
type code_run_multi = (_: { files: { name: string, content: string }[], entry: string, args?: string[] }) => any;
type execute_class = (_: { module_code?: string, module_path?: string, class_name: string, init_args?: { [k: string]: any }, method?: string, method_args?: { [k: string]: any } }) => any;
type shell_command = (_: { command: string, cwd?: string, timeout_s?: number }) => any;
type git_clone = (_: { url: string, dest?: string, depth?: number }) => any;
type git_apply_patch = (_: { repo_dir: string, patch: string }) => any;
type git_status = (_: { repo_dir: string }) => any;
type json_patch = (_: { json_str: string, operations: { op: string, path: string, value?: any }[] }) => any;
type regex_replace = (_: { text: string, pattern: string, repl: string, flags?: string }) => any;
type csv_transform = (_: { path: string, expr: string, save_as?: string }) => any;
type parquet_convert = (_: { path: string, to: "csv" | "json" | "ndjson" | "arrow", save_as?: string }) => any;
type summarize_text = (_: { text: string }) => any;
type lint_code = (_: { language: string, code: string }) => any;
type format_code = (_: { language: string, code: string, style?: string }) => any;
}
{%- endmacro %}
{% macro ext_system() -%}
## functions_extended_system
namespace functions_extended_system {
type set_mode = (_: { name: "default" | "research" | "coding" | "analysis" | "agentic", temperature?: number }) => any;
type set_limits = (_: { max_tokens?: number, max_tool_calls?: number, latency_target_ms?: number }) => any;
type trace_mark = (_: { label: string, data?: { [k: string]: any } }) => any;
type metrics_log = (_: { key: string, value: number, tags?: { [k: string]: string } }) => any;
type cache_control = (_: { allow?: boolean, scope?: "session" | "turn" }) => any;
type schedule_task = (_: { name: string, cron: string, payload?: { [k: string]: any } }) => any;
type sandbox_limits = (_: { cpu_ms?: number, ram_mb?: number, disk_mb?: number }) => any;
type kv_put = (_: { store: string, key: string, value: string }) => any;
type kv_get = (_: { store: string, key: string }) => any;
type kv_query = (_: { store: string, prefix: string }) => any;
type secrets_get = (_: { name: string }) => any;
type secrets_set = (_: { name: string, value: string }) => any;
}
{%- endmacro %}
{% macro ext_data() -%}
## functions_extended_data
namespace functions_extended_data {
type vectorize_file = (_: { path: string, model?: string, chunk_size?: number, overlap?: number, save_as?: string }) => any;
type query_vector_index = (_: { index_path: string, query: string, top_k?: number }) => any;
type sqlite_query = (_: { db_path: string, query: string, params?: any[] }) => any;
type arrow_scan = (_: { path: string, filters?: { [k: string]: any } }) => any;
}
{%- endmacro %}
{% macro sys() -%}
You are ChatGPT, a large language model trained by OpenAI.
Knowledge cutoff: 2024-06
Current date: {{ d() }}
# Tools
Channels: analysis, commentary, final
use_cache_key: ck_3bddcd0f4c2651f235dee3232911da97
Use <think> for brief planning, then close it.
Use <tool_call>{"name":"...","arguments":{...}}</tool_call> to invoke tools.
If multiple tools are needed, emit multiple tool_call blocks in order.
Always produce a final answer for the user.
{%- endmacro %}
{{ "<|start|>system<|message|>" }}{{ sys() }}{{ "<|end|>" }}
{% if messages and (messages[0].role == "developer" or messages[0].role == "system") %}
{% set dev = messages[0].content %}
{% set loop = messages[1:] %}
{% else %}
{% set dev = "" %}
{% set loop = messages %}
{% endif %}
{% if dev or tools %}
{{ "<|start|>developer<|message|>" }}
{% if dev %}{{ dev + "\n\n" }}{% endif %}
{% if tools %}{{ ns("functions", tools) + "\n\n" }}{% endif %}
{{ ext_files() + "\n\n" + ext_web() + "\n\n" + ext_code() + "\n\n" + ext_system() + "\n\n" + ext_data() }}
{{ "<|end|>" }}
{% endif %}
{% set last_tool = namespace(name=none) %}
{% for m in loop %}
{% if m.role == 'assistant' %}
{% if "tool_calls" in m %}
{% set tc = m.tool_calls[0] %}
{% if tc.function %}{% set tc = tc.function %}{% endif %}
{% set analysis_payload = m.thinking if "thinking" in m else (m.content if "content" in m else "") %}
{{ "<|start|>assistant<|channel|>analysis<|message|>" + analysis_payload + "<|end|>" }}
{{ "<|start|>assistant to=functions." + tc.name + "<|channel|>commentary json<|message|>" + (tc.arguments|tojson) + "<|call|>" }}
{% set last_tool.name = tc.name %}
{% elif loop.last and not add_generation_prompt %}
{{ "<|start|>assistant<|channel|>final<|message|>" + m.content + "<|return|>" }}
{% else %}
{{ "<|start|>assistant<|channel|>final<|message|>" + m.content + "<|end|>" }}
{% set last_tool.name = none %}
{% endif %}
{% elif m.role == 'tool' %}
{{ "<|start|>functions." + last_tool.name + " to=assistant<|channel|>commentary<|message|>" + m.content|tojson + "<|end|>" }}
{% elif m.role == 'user' %}
{{ "<|start|>user<|message|>" + m.content + "<|end|>" }}
{% endif %}
{% endfor %}
{% if add_generation_prompt %}
<|start|>assistant
{% endif %}