Codebuff

best-of-n-editor-gpt-5

v0.0.1
Published Nov 7, 2025

Versions

Usage Statistics
v0.0.1

Definition

const agentDefinition = {
id: "best-of-n-editor-gpt-5",
displayName: "Best-of-N GPT-5 Implementation Editor",
publisher: "codebuff",
version: "0.0.1",
model: "openai/gpt-5",
toolNames: [
"spawn_agents",
"str_replace",
"write_file",
"set_messages",
"set_output"
],
spawnableAgents: [
"codebuff/best-of-n-implementor-gpt-5@0.0.2",
"codebuff/best-of-n-selector-gpt-5@0.0.2"
],
inputSchema: {
params: {
type: "object",
properties: {
n: {
type: "number",
description: "Number of parallel implementor agents to spawn. Defaults to 5. Use fewer for simple tasks and max of 10 for complex tasks."
}
}
}
},
includeMessageHistory: true,
outputMode: "structured_output",
spawnerPrompt: `Edits code by orchestrating multiple implementor agents to generate implementation proposals, selects the best one, and applies the changes. Do not specify an input prompt for this agent; it reads the context from the message history.`,
systemPrompt: ``,
instructionsPrompt: ``,
stepPrompt: ``,
handleSteps: function* handleStepsGpt5({
agentState,
params
}) {
const n = Math.min(10, Math.max(1, params?.n ?? 5)), messages = agentState.messageHistory.concat();
messages.pop();
yield {
toolName: "set_messages",
input: {
messages
},
includeToolCall: !1
};
const { toolResult: implementorsResult1 } = yield {
toolName: "spawn_agents",
input: {
agents: Array.from({ length: n }, () => ({
agent_type: "best-of-n-implementor-gpt-5"
}))
},
includeToolCall: !1
}, implementorsResult = extractSpawnResults(implementorsResult1), letters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ", implementations = implementorsResult.map((content, index) => ({
id: letters[index],
content
})), { toolResult: selectorResult } = yield {
toolName: "spawn_agents",
input: {
agents: [
{
agent_type: "best-of-n-selector-gpt-5",
params: { implementations }
}
]
},
includeToolCall: !1
}, selectorOutput = extractSpawnResults(selectorResult)[0];
if ("errorMessage" in selectorOutput) {
yield {
toolName: "set_output",
input: { error: selectorOutput.errorMessage }
};
return;
}
const { implementationId } = selectorOutput, chosenImplementation = implementations.find((implementation) => implementation.id === implementationId);
if (!chosenImplementation) {
yield {
toolName: "set_output",
input: { error: "Failed to find chosen implementation." }
};
return;
}
const { agentState: postEditsAgentState } = yield {
type: "STEP_TEXT",
text: chosenImplementation.content
}, { messageHistory } = postEditsAgentState, lastAssistantMessageIndex = messageHistory.findLastIndex((message) => message.role === "assistant"), editToolResults = messageHistory.slice(lastAssistantMessageIndex).filter((message) => message.role === "tool").flatMap((message) => message.content.output).filter((output) => output.type === "json").map((output) => output.value);
yield {
toolName: "set_output",
input: {
response: chosenImplementation.content,
toolResults: editToolResults
}
};
function extractSpawnResults(results) {
if (!results)
return [];
return results.filter((result) => result.type === "json").map((result) => result.value).flat().map((result) => result.value.value ?? {
errorMessage: result.value.errorMessage ?? "Error extracting spawn results"
});
}
},
mcpServers: {},
inheritParentSystemPrompt: true
}