Skip to content

Commit 9e0de98

Browse files
committed
Update editor implementor to include tool calls
1 parent f366502 commit 9e0de98

File tree

1 file changed

+30
-3
lines changed

1 file changed

+30
-3
lines changed

.agents/editor/best-of-n/editor-implementor-gpt-5.ts

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { publisher } from '../../constants'
22

33
import type { SecretAgentDefinition } from '../../types/secret-agent-definition'
4+
import type { ToolCall } from '../../types/agent-definition'
45

56
export const createBestOfNImplementor = (options: {
67
model: 'sonnet' | 'gpt-5' | 'gemini'
@@ -24,11 +25,11 @@ export const createBestOfNImplementor = (options: {
2425
includeMessageHistory: true,
2526
inheritParentSystemPrompt: true,
2627

27-
toolNames: ['str_replace', 'write_file'],
28+
toolNames: ['str_replace', 'write_file', 'set_output'],
2829
spawnableAgents: [],
2930

3031
inputSchema: {},
31-
outputMode: 'last_message',
32+
outputMode: 'structured_output',
3233

3334
instructionsPrompt: `You are an expert code editor with deep understanding of software engineering principles. You were spawned to generate an implementation for the user's request.
3435
@@ -96,6 +97,8 @@ You can also use <think> tags interspersed between tool calls to think about the
9697
</example>`
9798
}
9899
100+
After the edit tool calls, you can optionally mention any follow-up steps to take, like deleting a file, or a sepcific way to validate the changes. There's no need to use the set_output tool as your entire response will be included in the output.
101+
99102
Your implementation should:
100103
- Be complete and comprehensive
101104
- Include all necessary changes to fulfill the user's request
@@ -112,7 +115,31 @@ More style notes:
112115
Write out your complete implementation now, formatting all changes as tool calls as shown above.`,
113116

114117
handleSteps: function* () {
115-
yield 'STEP'
118+
const { agentState: postEditsAgentState } = yield 'STEP'
119+
const { messageHistory } = postEditsAgentState
120+
const lastAssistantMessageIndex = messageHistory.findLastIndex(
121+
(message) => message.role === 'assistant',
122+
)
123+
const editToolResults = messageHistory
124+
.slice(lastAssistantMessageIndex)
125+
.filter((message) => message.role === 'tool')
126+
.flatMap((message) => message.content.output)
127+
.filter((output) => output.type === 'json')
128+
.map((output) => output.value)
129+
130+
// Get the assistant's response (the last assistant message)
131+
const assistantResponse = messageHistory
132+
.slice(lastAssistantMessageIndex)
133+
.find((message) => message.role === 'assistant')
134+
135+
yield {
136+
toolName: 'set_output',
137+
input: {
138+
response: assistantResponse?.content ?? '',
139+
toolResults: editToolResults,
140+
},
141+
includeToolCall: false,
142+
} satisfies ToolCall<'set_output'>
116143
},
117144
}
118145
}

0 commit comments

Comments
 (0)