{ "model": "$model", "stream": true, "input": [ ## 1. System Context { "type": "message", "role": "system", "content": [ { "type": "input_text", "text": #jesc($systemmessage) } ] } ## 2. Conversation History #foreach($message in $recent) #set($entry = $testbench.getData("thought", $message.id)) ## LOGIC: Determine if we should skip this entry #set( $shouldRender = true ) #if( $entry.user == "agent" && (!$entry.message || $entry.message.trim() == "") && $entry.messagetype != "function_call" ) #set( $shouldRender = false ) #end #if( $shouldRender ) ## Comma management: We add a comma for every item after the first System message , #if($entry.messagetype == "function_call" || $entry.messagetype == "tool_calls") ## --- HANDLE TOOL EXECUTION (The "Beer" Fix) --- ## We inject TWO messages here: ## 1. The Assistant saying what it did (Breaks the loop) ## 2. The System providing the result { "type": "message", "role": "assistant", "content": [ { "type": "output_text", ## We reconstruct the intent so the LLM knows it already happened "text": #jesc("I will run the function ${entry.function} with arguments: ${entry.arguments}") } ] }, { "type": "message", "role": "system", "content": [ { "type": "input_text", ## The actual result content "text": #jesc("Function ${entry.function} returned: ${entry.function_response}") } ] } #elseif($entry.user == "agent") ## --- STANDARD ASSISTANT --- { "type": "message", "role": "assistant", "content": [ { "type": "output_text", "text": #jesc($entry.message) } ] } #else ## --- USER --- { "type": "message", "role": "user", "content": [ { "type": "input_text", "text": #jesc($entry.message) } ] } #end #end #end ], "tools": [ #foreach($func in $functions) #if($foreach.count != 1),#end $gpt.loadInputFromTemplate($context, "$apphome/frames/$frameroot/functions/${func}.json") #end ], "tool_choice": "auto" }