@@ -6,7 +6,6 @@ import type {
66 StepText ,
77 ToolCall ,
88} from '../../types/agent-definition'
9-
109export function createBestOfNEditor (
1110 model : 'sonnet' | 'gpt-5' ,
1211) : Omit < SecretAgentDefinition , 'id' > {
@@ -132,10 +131,15 @@ function* handleStepsSonnet({
132131 return
133132 }
134133
135- // Apply the chosen implementation using STEP_TEXT
134+ // Apply the chosen implementation using STEP_TEXT (only tool calls, no commentary)
135+ const toolCallsOnly = extractToolCallsOnly (
136+ typeof chosenImplementation . content === 'string'
137+ ? chosenImplementation . content
138+ : '' ,
139+ )
136140 const { agentState : postEditsAgentState } = yield {
137141 type : 'STEP_TEXT' ,
138- text : chosenImplementation . content ,
142+ text : toolCallsOnly ,
139143 } as StepText
140144 const { messageHistory } = postEditsAgentState
141145 const lastAssistantMessageIndex = messageHistory . findLastIndex (
@@ -177,6 +181,19 @@ function* handleStepsSonnet({
177181 } ,
178182 )
179183 }
184+
185+ // Extract only tool calls from text, removing any commentary
186+ function extractToolCallsOnly ( text : string ) : string {
187+ const toolExtractionPattern =
188+ / < c o d e b u f f _ t o o l _ c a l l > \n ( .* ?) \n < \/ c o d e b u f f _ t o o l _ c a l l > / gs
189+ const matches : string [ ] = [ ]
190+
191+ for ( const match of text . matchAll ( toolExtractionPattern ) ) {
192+ matches . push ( match [ 0 ] ) // Include the full tool call with tags
193+ }
194+
195+ return matches . join ( '\n' )
196+ }
180197}
181198
182199function * handleStepsGpt5 ( {
@@ -258,10 +275,15 @@ function* handleStepsGpt5({
258275 return
259276 }
260277
261- // Apply the chosen implementation using STEP_TEXT
278+ // Apply the chosen implementation using STEP_TEXT (only tool calls, no commentary)
279+ const toolCallsOnly = extractToolCallsOnly (
280+ typeof chosenImplementation . content === 'string'
281+ ? chosenImplementation . content
282+ : '' ,
283+ )
262284 const { agentState : postEditsAgentState } = yield {
263285 type : 'STEP_TEXT' ,
264- text : chosenImplementation . content ,
286+ text : toolCallsOnly ,
265287 } as StepText
266288 const { messageHistory } = postEditsAgentState
267289 const lastAssistantMessageIndex = messageHistory . findLastIndex (
@@ -302,6 +324,19 @@ function* handleStepsGpt5({
302324 } ,
303325 )
304326 }
327+
328+ // Extract only tool calls from text, removing any commentary
329+ function extractToolCallsOnly ( text : string ) : string {
330+ const toolExtractionPattern =
331+ / < c o d e b u f f _ t o o l _ c a l l > \n ( .* ?) \n < \/ c o d e b u f f _ t o o l _ c a l l > / gs
332+ const matches : string [ ] = [ ]
333+
334+ for ( const match of text . matchAll ( toolExtractionPattern ) ) {
335+ matches . push ( match [ 0 ] ) // Include the full tool call with tags
336+ }
337+
338+ return matches . join ( '\n' )
339+ }
305340}
306341
307342const definition = {
0 commit comments