Skip to content

Commit 76e5a3c

Browse files
committed
Update editor with the new tool results schema. Increase step limit to 25
1 parent ac543f9 commit 76e5a3c

File tree

1 file changed

+17
-42
lines changed

1 file changed

+17
-42
lines changed

.agents/base2/editor.ts

Lines changed: 17 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ ${PLACEHOLDER.KNOWLEDGE_FILES_CONTENTS}`,
126126
`,
127127

128128
handleSteps: function* ({ agentState: initialAgentState }) {
129-
const stepLimit = 20
129+
const stepLimit = 25
130130
let stepCount = 0
131131
let agentState = initialAgentState
132132

@@ -147,7 +147,7 @@ ${PLACEHOLDER.KNOWLEDGE_FILES_CONTENTS}`,
147147
input: {
148148
role: 'user',
149149
content:
150-
'You have reached the step limit. Please use the set_output tool now to summarize your progress so far, what you still need to solve, and provide any insights that could help complete the remaining work. Please end your turn after using the set_output tool with the end_turn tool.',
150+
'You have reached the step limit. Please use the set_output tool now to summarize your progress so far including all specific actions you took (note that any file changes will be included automatically in the output), what you still need to solve, and provide any insights that could help complete the remaining work. Please end your turn after using the set_output tool with the end_turn tool.',
151151
},
152152
includeToolCall: false,
153153
}
@@ -161,51 +161,26 @@ ${PLACEHOLDER.KNOWLEDGE_FILES_CONTENTS}`,
161161

162162
// Collect all the edits from the conversation
163163
const { messageHistory, output } = agentState
164-
const editToolResults: string[] = []
165-
for (const message of messageHistory) {
166-
if (
167-
message.role === 'user' &&
168-
typeof message.content === 'string' &&
169-
message.content.includes('<tool_result>')
170-
) {
171-
// Parse out tool results for write_file and str_replace
172-
const writeFileMatches = message.content.match(
173-
/<tool_result>\s*<tool>write_file<\/tool>\s*<result>([\s\S]*?)<\/result>\s*<\/tool_result>/g,
174-
)
175-
const strReplaceMatches = message.content.match(
176-
/<tool_result>\s*<tool>str_replace<\/tool>\s*<result>([\s\S]*?)<\/result>\s*<\/tool_result>/g,
177-
)
178-
179-
// Extract inner <result> content from write_file matches
180-
if (writeFileMatches) {
181-
for (const match of writeFileMatches) {
182-
const resultMatch = match.match(/<result>([\s\S]*?)<\/result>/)
183-
if (resultMatch) {
184-
editToolResults.push(resultMatch[1])
185-
}
186-
}
187-
}
188-
189-
// Extract inner <result> content from str_replace matches
190-
if (strReplaceMatches) {
191-
for (const match of strReplaceMatches) {
192-
const resultMatch = match.match(/<result>([\s\S]*?)<\/result>/)
193-
if (resultMatch) {
194-
editToolResults.push(resultMatch[1])
195-
}
196-
}
197-
}
198-
}
199-
}
200-
const successfulEdits = editToolResults.filter(
201-
(edit) => edit.includes('successfully') && edit.includes('Changes made:'),
202-
)
164+
const editToolResults = messageHistory
165+
.filter((message) => message.role === 'tool')
166+
.filter(
167+
(message) =>
168+
message.content.toolName === 'write_file' ||
169+
message.content.toolName === 'str_replace',
170+
)
171+
.flatMap((message) => message.content.output)
172+
.filter((output) => output.type === 'json')
173+
.map((output) => output.value)
174+
// Only successful edits!
175+
.filter(
176+
(toolResult) => toolResult && !('errorMessage' in (toolResult as any)),
177+
)
203178

204179
yield {
205180
toolName: 'set_output',
206181
input: {
207182
...output,
208-
edits: successfulEdits,
183+
edits: editToolResults,
209184
},
210185
}
211186
},

0 commit comments

Comments
 (0)