Skip to content

Commit 9ba0254

Browse files
committed
editor-multi-prompt2
1 parent 98a6b70 commit 9ba0254

File tree

5 files changed

+446
-6
lines changed

5 files changed

+446
-6
lines changed

.agents/base2/base2.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ export function createBase2(
5454
!isFast && 'suggest_followups',
5555
'str_replace',
5656
'write_file',
57+
'propose_str_replace',
58+
'propose_write_file',
5759
'ask_user',
5860
'set_output',
5961
),
@@ -68,7 +70,7 @@ export function createBase2(
6870
isDefault && 'thinker',
6971
isLite && 'editor-gpt-5',
7072
isDefault && 'editor',
71-
isMax && 'editor-multi-prompt',
73+
isMax && 'editor-multi-prompt2',
7274
isMax && 'thinker-best-of-n-opus',
7375
!isLite && 'code-reviewer',
7476
'context-pruner',
@@ -127,7 +129,7 @@ Use the spawn_agents tool to spawn specialized agents to help you complete the u
127129
(isDefault || isMax) &&
128130
`- Spawn the ${isDefault ? 'thinker' : 'thinker-best-of-n-opus'} after gathering context to solve complex problems or when the user asks you to think about a problem.`,
129131
isMax &&
130-
`- Spawn the editor-multi-prompt agent to implement the changes after you have gathered all the context you need. You must spawn this agent for non-trivial changes, since it writes much better code than you would with the str_replace or write_file tools. Don't spawn the editor in parallel with context-gathering agents.`,
132+
`- Spawn the editor-multi-prompt2 agent to implement the changes after you have gathered all the context you need. You must spawn this agent for non-trivial changes, since it writes much better code than you would with the str_replace or write_file tools. Don't spawn the editor in parallel with context-gathering agents.`,
131133
'- Spawn commanders sequentially if the second command depends on the the first.',
132134
!isFast &&
133135
!isLite &&
@@ -181,7 +183,7 @@ ${
181183
? '[ You implement the changes using the str_replace or write_file tools ]'
182184
: isLite
183185
? '[ You implement the changes using the editor-gpt-5 agent ]'
184-
: '[ You implement the changes using the editor-multi-prompt agent ]'
186+
: '[ You implement the changes using the editor-multi-prompt2 agent ]'
185187
}
186188
187189
${
@@ -302,7 +304,7 @@ ${buildArray(
302304
isDefault &&
303305
'- IMPORTANT: You must spawn the editor agent to implement the changes after you have gathered all the context you need. This agent will do the best job of implementing the changes so you must spawn it for all non-trivial changes. Do not pass any prompt or params to the editor agent when spawning it. It will make its own best choices of what to do.',
304306
isMax &&
305-
`- IMPORTANT: You must spawn the editor-multi-prompt agent to implement non-trivial code changes, since it will generate the best code changes from multiple implementation proposals. This is the best way to make high quality code changes -- strongly prefer using this agent over the str_replace or write_file tools, unless the change is very straightforward and obvious.`,
307+
`- IMPORTANT: You must spawn the editor-multi-prompt2 agent to implement non-trivial code changes, since it will generate the best code changes from multiple implementation proposals. This is the best way to make high quality code changes -- strongly prefer using this agent over the str_replace or write_file tools, unless the change is very straightforward and obvious.`,
306308
isFast &&
307309
'- Implement the changes using the str_replace or write_file tools. Implement all the changes in one go.',
308310
isFast &&
@@ -336,7 +338,7 @@ function buildImplementationStepPrompt({
336338
isMax &&
337339
`Keep working until the user's request is completely satisfied${!hasNoValidation ? ' and validated' : ''}, or until you require more information from the user.`,
338340
isMax &&
339-
`You must spawn the 'editor-multi-prompt' agent to implement code changes, since it will generate the best code changes.`,
341+
`You must spawn the 'editor-multi-prompt2' agent to implement code changes, since it will generate the best code changes.`,
340342
(isDefault || isMax) &&
341343
'Spawn code-reviewer to review the changes after you have implemented the changes and in parallel with typechecking or testing.',
342344
`After completing the user request, summarize your changes in a sentence${isFast ? '' : ' or a few short bullet points'}.${isSonnet ? " Don't create any summary markdown files or example documentation files, unless asked by the user." : ''} Don't repeat yourself, especially if you have already concluded and summarized the changes in a previous step -- just end your turn.`,
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { createBestOfNImplementor2 } from './editor-implementor2'
2+
3+
const definition = {
4+
...createBestOfNImplementor2({ model: 'gpt-5' }),
5+
id: 'editor-implementor2-gpt-5',
6+
}
7+
export default definition
Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
import { publisher } from '../../constants'
2+
3+
import type { SecretAgentDefinition } from '../../types/secret-agent-definition'
4+
5+
export const createBestOfNImplementor2 = (options: {
6+
model: 'gpt-5' | 'opus' | 'sonnet'
7+
}): Omit<SecretAgentDefinition, 'id'> => {
8+
const { model } = options
9+
const isGpt5 = model === 'gpt-5'
10+
const isOpus = model === 'opus'
11+
return {
12+
publisher,
13+
model: isGpt5
14+
? 'openai/gpt-5.2'
15+
: isOpus
16+
? 'anthropic/claude-opus-4.5'
17+
: 'anthropic/claude-sonnet-4.5',
18+
displayName: isGpt5
19+
? 'GPT-5 Implementation Generator v2'
20+
: isOpus
21+
? 'Opus Implementation Generator v2'
22+
: 'Sonnet Implementation Generator v2',
23+
spawnerPrompt:
24+
'Generates a complete implementation using propose_* tools that draft changes without applying them',
25+
26+
includeMessageHistory: true,
27+
inheritParentSystemPrompt: true,
28+
29+
toolNames: ['propose_write_file', 'propose_str_replace'],
30+
spawnableAgents: [],
31+
32+
inputSchema: {},
33+
outputMode: 'structured_output',
34+
35+
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.
36+
37+
Your task is to write out ALL the code changes needed to complete the user's request.
38+
39+
IMPORTANT: Use propose_str_replace and propose_write_file tools to make your edits. These tools draft changes without actually applying them - they will be reviewed first.
40+
41+
You can make multiple tool calls across multiple steps to complete the implementation.
42+
43+
After your edit tool calls, you can optionally mention any follow-up steps to take, like deleting a file, or a specific way to validate the changes.
44+
45+
Your implementation should:
46+
- Be complete and comprehensive
47+
- Include all necessary changes to fulfill the user's request
48+
- Follow the project's conventions and patterns
49+
- Be as simple and maintainable as possible
50+
- Reuse existing code wherever possible
51+
- Be well-structured and organized
52+
53+
More style notes:
54+
- Extra try/catch blocks clutter the code -- use them sparingly.
55+
- Optional arguments are code smell and worse than required arguments.
56+
- New components often should be added to a new file, not added to an existing file.
57+
58+
Write out your complete implementation now.`,
59+
60+
handleSteps: function* ({ agentState: initialAgentState, logger }) {
61+
const initialMessageHistoryLength =
62+
initialAgentState.messageHistory.length
63+
64+
const { agentState } = yield 'STEP_ALL'
65+
66+
let postMessages = agentState.messageHistory.slice(
67+
initialMessageHistoryLength,
68+
)
69+
70+
if (postMessages.length === 0) {
71+
const { agentState: postMessagesAgentState } = yield 'STEP'
72+
postMessages = postMessagesAgentState.messageHistory.slice(
73+
initialMessageHistoryLength,
74+
)
75+
} else if (postMessages.length == 1) {
76+
const message = postMessages[0]
77+
if (
78+
message.role === 'assistant' &&
79+
message.content.length === 1 &&
80+
message.content[0].type === 'text' &&
81+
!message.content[0].text
82+
) {
83+
const { agentState: postMessagesAgentState } = yield 'STEP_ALL'
84+
postMessages = postMessagesAgentState.messageHistory.slice(
85+
initialMessageHistoryLength,
86+
)
87+
}
88+
}
89+
90+
logger.debug(
91+
{
92+
numMessages: postMessages.length,
93+
messageRoles: postMessages.map((m: any) => m.role),
94+
},
95+
'Post STEP_ALL messages',
96+
)
97+
98+
// Extract tool calls from assistant messages
99+
// Handle both 'input' and 'args' property names for compatibility
100+
const toolCalls: { toolName: string; input: any }[] = []
101+
for (const message of postMessages) {
102+
if (message.role !== 'assistant' || !Array.isArray(message.content))
103+
continue
104+
for (const part of message.content) {
105+
if (part.type === 'tool-call') {
106+
toolCalls.push({
107+
toolName: part.toolName,
108+
input: part.input ?? (part as any).args ?? {},
109+
})
110+
}
111+
}
112+
}
113+
114+
// Extract tool results (unified diffs) from tool messages
115+
const toolResults: any[] = []
116+
for (const message of postMessages) {
117+
if (message.role !== 'tool' || !Array.isArray(message.content)) continue
118+
for (const part of message.content) {
119+
if (part.type === 'json' && part.value) {
120+
toolResults.push(part.value)
121+
}
122+
}
123+
}
124+
125+
logger.debug(
126+
{ numToolCalls: toolCalls.length, numToolResults: toolResults.length },
127+
'Extracted tool calls and results',
128+
)
129+
130+
// Concatenate all unified diffs for the selector to review
131+
const unifiedDiffs = toolResults
132+
.filter((result: any) => result.unifiedDiff)
133+
.map((result: any) => `--- ${result.file} ---\n${result.unifiedDiff}`)
134+
.join('\n\n')
135+
136+
logger.debug(
137+
{
138+
unifiedDiffsLength: unifiedDiffs.length,
139+
hasContent: unifiedDiffs.length > 0,
140+
},
141+
'Generated unified diffs',
142+
)
143+
144+
yield {
145+
toolName: 'set_output',
146+
input: {
147+
toolCalls,
148+
toolResults,
149+
unifiedDiffs,
150+
},
151+
includeToolCall: false,
152+
}
153+
},
154+
}
155+
}
156+
const definition = {
157+
...createBestOfNImplementor2({ model: 'opus' }),
158+
id: 'editor-implementor2',
159+
}
160+
export default definition

0 commit comments

Comments
 (0)