const agentDefinition = {
id: "editor-multi-prompt",
displayName: "Multi-Prompt Editor",
publisher: "codebuff",
version: "0.0.1",
model: "anthropic/claude-opus-4.5",
toolNames: [
"spawn_agents",
"str_replace",
"write_file",
"set_messages",
"set_output"
],
spawnableAgents: [
],
inputSchema: {
params: {
type: "object",
required: [
"prompts"
],
properties: {
prompts: {
type: "array",
items: {
type: "string"
},
description: "Array of short prompts, each specifying a slightly different implementation strategy or approach. Example: [\"use a cache for the data\", \"don\t cache anything\", \"make the minimal possible changes\", \"modularize your solution by creating new files\"]"
}
}
}
},
includeMessageHistory: true,
outputMode: "structured_output",
spawnerPrompt: `Edits code by spawning multiple implementor agents with different strategy prompts, selects the best implementation, and applies the changes. It also returns further suggested improvements which you should take seriously and act on. Pass as input an array of short prompts specifying different implementation approaches or strategies. Make sure to read any files intended to be edited before spawning this agent.`,
systemPrompt: ``,
instructionsPrompt: ``,
stepPrompt: ``,
handleSteps: function* handleStepsMultiPrompt({
agentState,
params
}) {
const prompts = params?.prompts ?? [];
if (prompts.length === 0) {
yield {
toolName: "set_output",
input: {
error: "No prompts provided. Please pass an array of strategy prompts."
}
};
return;
}
const { messageHistory: initialMessageHistory } = agentState;
let userMessageIndex = initialMessageHistory.length;
while (userMessageIndex > 0)
if (initialMessageHistory[userMessageIndex - 1].role === "user")
userMessageIndex--;
else
break;
yield {
toolName: "set_messages",
input: {
messages: initialMessageHistory.slice(0, userMessageIndex)
},
includeToolCall: !1
};
const implementorAgents = prompts.map((prompt) => ({
agent_type: "editor-implementor-opus",
prompt: `Strategy: ${prompt}`
})), { toolResult: implementorResults } = yield {
toolName: "spawn_agents",
input: {
agents: implementorAgents
},
includeToolCall: !1
}, spawnedImplementations = extractSpawnResults(implementorResults), letters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ", implementations = spawnedImplementations.map((result, index) => {
if (!result || typeof result === "object" && "errorMessage" in result)
return {
id: letters[index],
strategy: prompts[index] ?? "unknown",
content: `Error: ${result?.errorMessage ?? "Unknown error"}`,
toolCalls: []
};
return {
id: letters[index],
strategy: prompts[index] ?? "unknown",
content: result.unifiedDiffs || "No changes proposed",
toolCalls: result.toolCalls ?? []
};
}), { toolResult: selectorResult } = yield {
toolName: "spawn_agents",
input: {
agents: [
{
agent_type: "best-of-n-selector2",
params: {
implementations: implementations.map((impl) => ({
id: impl.id,
strategy: impl.strategy,
content: impl.content
}))
}
}
]
},
includeToolCall: !1
}, selectorOutput = extractSpawnResults(selectorResult)[0];
if (!selectorOutput || !("implementationId" in selectorOutput)) {
yield {
toolName: "set_output",
input: { error: "Selector failed to return an implementation" }
};
return;
}
const { implementationId } = selectorOutput, chosenImplementation = implementations.find((implementation) => implementation.id === implementationId);
if (!chosenImplementation) {
yield {
toolName: "set_output",
input: {
error: `Failed to find chosen implementation: ${implementationId}`
}
};
return;
}
const appliedToolResults = [];
for (const toolCall of chosenImplementation.toolCalls) {
const realToolName = toolCall.toolName === "propose_str_replace" ? "str_replace" : toolCall.toolName === "propose_write_file" ? "write_file" : toolCall.toolName;
if (realToolName === "str_replace" || realToolName === "write_file") {
const { toolResult } = yield {
toolName: realToolName,
input: toolCall.input,
includeToolCall: !0
};
appliedToolResults.push(toolResult);
}
}
const { suggestedImprovements } = selectorOutput;
yield {
toolName: "set_output",
input: {
chosenStrategy: chosenImplementation.strategy,
toolResults: appliedToolResults,
suggestedImprovements
},
includeToolCall: !1
};
function extractSpawnResults(results) {
if (!results || results.length === 0)
return [];
const jsonResult = results.find((r) => r.type === "json");
if (!jsonResult?.value)
return [];
return (Array.isArray(jsonResult.value) ? jsonResult.value : [jsonResult.value]).map((result) => result?.value).map((result) => result && ("value" in result) ? result.value : result).filter(Boolean);
}
},
mcpServers: {},
inheritParentSystemPrompt: true
}