13 3 weeks ago

tools thinking
cf0a4b759c4f · 1.9kB
{{- $lastUserIndex := -1 }}
{{- $hasActiveToolCall := false }}
{{- range $index, $_ := .Messages }}
{{- if eq .Role "user" }}{{ $lastUserIndex = $index }}{{ end }}
{{- $last := eq (len (slice $.Messages $index)) 1}}
{{- if eq .Role "user" }}<|User|>{{ .Content }}
{{- else if eq .Role "assistant" }}<|Assistant|>
{{- if and $.IsThinkSet (and $last .Thinking) -}}
<think>
{{ .Thinking }}
</think>
{{- end }}{{ .Content }}{{- if not $last }}<|end▁of▁sentence|>{{- end }}
{{- end }}
{{- if and $last (ne .Role "assistant") }}<|Assistant|>
{{- if and $.IsThinkSet (not $.Think) -}}
<think>
</think>
{{- end }}
{{- end }}
{{- end }}
{{- range $index, $_ := .Messages }}
{{- if eq .Role "system" }}[SYSTEM_CONTEXT]
{{ .Content }}
[/SYSTEM_CONTEXT]
{{- else if eq .Role "user" }}
{{- if and (eq $lastUserIndex $index) $.Tools }}[AVAILABLE_TOOLS]
{{ $.Tools }}
[/AVAILABLE_TOOLS]
{{- end }}
[USER_REQUEST]
{{ .Content }}
[/USER_REQUEST]
{{- else if eq .Role "assistant" }}
{{- if .Content }}[ASSISTANT_RESPONSE]
{{ .Content }}
[/ASSISTANT_RESPONSE]
{{- if not (eq (len (slice $.Messages $index)) 1) }}</s>
{{- end }}
{{- else if .ToolCalls }}
{{- $hasActiveToolCall = true }}
[TOOL_INVOCATION]
{{- range .ToolCalls }}
{
"tool": "{{ .Function.Name }}",
"parameters": {{ .Function.Arguments }},
"purpose": "{{ if .Purpose }}{{ .Purpose }}{{ else }}Executing tool{{ end }}"
}
{{- end }}
[/TOOL_INVOCATION]</s>
{{- end }}
{{- else if eq .Role "tool" }}[TOOL_OUTPUT]
{
"tool_call_id": "{{ .ToolCallID }}",
"status": "{{ if .Status }}{{ .Status }}{{ else }}success{{ end }}",
"result": {{ .Content }}
}
[/TOOL_OUTPUT]
{{- if $hasActiveToolCall }}
[ANALYSIS]
Based on the tool output, I should now:
{{- end }}
{{- end }}
{{- end }}
{{- if $hasActiveToolCall }}
[NEXT_ACTION]
{{- end }}