@@ -79,12 +79,12 @@ function extractArithmeticAnswer(prompt: string): string | null {
7979}
8080
8181function buildReplyToon ( answer : string ) : string {
82- return `<response>
83- < thought> Answering the benchmark question directly.</thought>
84- < actions> REPLY</actions>
85- < providers></providers>
86- < text> ${ answer } </text>
87- </response>` ;
82+ return buildToonResponse ( "" , {
83+ thought : " Answering the benchmark question directly." ,
84+ actions : " REPLY" ,
85+ providers : "" ,
86+ text : answer ,
87+ } ) ;
8888}
8989
9090function buildHyperliquidPlanToon ( ) : string {
@@ -177,32 +177,27 @@ function buildAdhdBenchToon(prompt: string): string {
177177 const action = extractAdhdAction ( prompt ) ;
178178 const text = action === "REPLY" ? "Replying directly with the requested information." : `Selected ${ action } ` ;
179179 if ( [ "REPLY" , "IGNORE" , "NONE" ] . includes ( action ) ) {
180- return `<response>
181- < thought> Selecting ${ action } for this ADHDBench turn.</thought>
182- < actions> ${ action } </actions>
183- < providers> RECENT_MESSAGES,ENTITIES,KNOWLEDGE,ROLES</providers>
184- < text> ${ text } </text>
185- </response>` ;
180+ return buildToonResponse ( prompt , {
181+ thought : ` Selecting ${ action } for this ADHDBench turn.` ,
182+ actions : action ,
183+ providers : " RECENT_MESSAGES,ENTITIES,KNOWLEDGE,ROLES" ,
184+ text,
185+ } ) ;
186186 }
187- return `<response>
188- <thought>Selecting ${ action } for this ADHDBench turn.</thought>
189- <actions>BENCHMARK_ACTION</actions>
190- <providers>RECENT_MESSAGES,ENTITIES,KNOWLEDGE,ROLES</providers>
191- <text>${ text } </text>
192- <params>
193- <BENCHMARK_ACTION>
194- <command>${ action } </command>
195- </BENCHMARK_ACTION>
196- </params>
197- </response>` ;
187+ return buildToonResponse ( prompt , {
188+ thought : `Selecting ${ action } for this ADHDBench turn.` ,
189+ actions : "BENCHMARK_ACTION" ,
190+ providers : "RECENT_MESSAGES,ENTITIES,KNOWLEDGE,ROLES" ,
191+ text,
192+ params : `BENCHMARK_ACTION:\n command: ${ action } ` ,
193+ } ) ;
198194}
199195
200196function extractValidationFields ( prompt : string ) : Record < string , string > {
201197 const tags : Record < string , string > = { } ;
202198
203- // Per-field validation tags (context check levels 0/1)
204199 const matches = prompt . matchAll (
205- / < ( c o d e _ [ A - Z a - z 0 - 9 _ - ] + _ (?: s t a r t | e n d ) | o n e _ (?: i n i t i a l | m i d d l e | e n d ) _ c o d e | t w o _ (?: i n i t i a l | m i d d l e | e n d ) _ c o d e ) > ( [ \s \S ] * ? ) < \/ \1 > / g,
200+ / " ( c o d e _ [ A - Z a - z 0 - 9 _ - ] + _ (?: s t a r t | e n d ) | o n e _ (?: i n i t i a l | m i d d l e | e n d ) _ c o d e | t w o _ (?: i n i t i a l | m i d d l e | e n d ) _ c o d e ) " \s * : \s * " ( [ ^ " ] + ) " / g,
206201 ) ;
207202 for ( const [ , key , value ] of matches ) {
208203 tags [ key ] = value . trim ( ) ;
@@ -212,7 +207,7 @@ function extractValidationFields(prompt: string): Record<string, string> {
212207 // "initial code: ...", "middle code: ...", "end code: ..."
213208 // and optionally "second initial code: ..." for the second checkpoint set.
214209 const checkpointMatches = prompt . matchAll (
215- / ( s e c o n d \s + ) ? ( i n i t i a l | m i d d l e | e n d ) \s + c o d e : \s * ( [ a - f 0 - 9 - ] { 16 , } ) / gi,
210+ / ( s e c o n d \s + ) ? ( i n i t i a l | m i d d l e | e n d ) \s + c o d e : \s * ( [ a - f 0 - 9 - ] { 8 , } ) / gi,
216211 ) ;
217212 for ( const [ , second , stage , value ] of checkpointMatches ) {
218213 const prefix = second ? "two" : "one" ;
@@ -231,10 +226,17 @@ function buildToonResponse(
231226 ( entry ) : entry is [ string , string ] =>
232227 typeof entry [ 1 ] === "string" && entry [ 1 ] . length > 0 ,
233228 ) ;
234- const body = entries
235- . map ( ( [ key , value ] ) => `<${ key } >${ value } </${ key } >` )
236- . join ( "\n" ) ;
237- return `<response>\n${ body } \n</response>` ;
229+ return entries . map ( ( [ key , value ] ) => renderToonField ( key , value ) ) . join ( "\n" ) ;
230+ }
231+
232+ function renderToonField ( key : string , value : string ) : string {
233+ if ( value . includes ( "\n" ) ) {
234+ return `${ key } :\n${ value
235+ . split ( / \r ? \n / )
236+ . map ( ( line ) => ` ${ line } ` )
237+ . join ( "\n" ) } `;
238+ }
239+ return `${ key } : ${ value } ` ;
238240}
239241
240242function buildCompletion ( prompt : string ) : string {
@@ -252,7 +254,7 @@ function buildCompletion(prompt: string): string {
252254 // multiStepDecisionTemplate
253255 if (
254256 prompt . includes ( "Determine the next step" ) &&
255- prompt . includes ( "< isFinish> " )
257+ prompt . includes ( "isFinish" )
256258 ) {
257259 return buildToonResponse ( prompt , {
258260 thought : "The benchmark task can be completed in this step." ,
@@ -295,24 +297,13 @@ function buildCompletion(prompt: string): string {
295297 return buildAdhdBenchToon ( prompt ) ;
296298 }
297299
298- // Default message handler path (single-shot core)
299- const validationTags = extractValidationFields ( prompt ) ;
300- const validationToon = Object . entries ( validationTags )
301- . map ( ( [ key , value ] ) => `<${ key } >${ value } </${ key } >` )
302- . join ( "\n" ) ;
303-
304- return `<response>
305- <thought>Execute deterministic benchmark action using ${ command } .</thought>
306- <actions>BENCHMARK_ACTION</actions>
307- <providers></providers>
308- <text>Executed ${ command } </text>
309- <params>
310- <BENCHMARK_ACTION>
311- <command>${ command } </command>
312- </BENCHMARK_ACTION>
313- </params>
314- ${ validationToon }
315- </response>` ;
300+ return buildToonResponse ( prompt , {
301+ thought : `Execute deterministic benchmark action using ${ command } .` ,
302+ actions : "BENCHMARK_ACTION" ,
303+ providers : "" ,
304+ text : `Executed ${ command } ` ,
305+ params : `BENCHMARK_ACTION:\n command: ${ command } ` ,
306+ } ) ;
316307}
317308
318309function mockTextModel (
0 commit comments