const agentDefinition = {
id: "thinker-best-of-n",
displayName: "Best-of-N Thinker",
publisher: "codebuff",
version: "0.0.1",
model: "anthropic/claude-sonnet-4.5",
toolNames: [
"spawn_agents",
"set_messages",
"set_output"
],
spawnableAgents: [
"codebuff/thinker@0.0.5",
"codebuff/thinker-selector@0.0.1"
],
inputSchema: {
params: {
type: "object",
properties: {
n: {
type: "number",
description: "Number of parallel thinker agents to spawn. Defaults to 5. Use fewer for simple questions and max of 10 for complex questions."
}
}
},
prompt: {
type: "string",
description: "The problem you are trying to solve"
}
},
includeMessageHistory: true,
outputMode: "structured_output",
spawnerPrompt: `Generates deep thinking by orchestrating multiple thinker agents, selects the best thinking output. Use this to help solve a hard problem. You must first gather all the relevant context *BEFORE* spawning this agent, as it can only think.`,
systemPrompt: ``,
instructionsPrompt: ``,
stepPrompt: ``,
handleSteps: function* handleStepsSonnet({
agentState,
prompt,
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: thinkersResult1 } = yield {
toolName: "spawn_agents",
input: {
agents: Array.from({ length: n }, () => ({
agent_type: "thinker",
prompt
}))
},
includeToolCall: !1
}, thinkersResult = extractSpawnResults(thinkersResult1), letters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ", thoughts = thinkersResult.map((content, index) => ({
id: letters[index],
content
})), { toolResult: selectorResult } = yield {
toolName: "spawn_agents",
input: {
agents: [
{
agent_type: "thinker-selector",
params: { thoughts }
}
]
},
includeToolCall: !1
}, selectorOutput = extractSpawnResults(selectorResult)[0];
if ("errorMessage" in selectorOutput) {
yield {
toolName: "set_output",
input: { error: selectorOutput.errorMessage }
};
return;
}
const { thoughtId } = selectorOutput, chosenThought = thoughts.find((thought) => thought.id === thoughtId);
if (!chosenThought) {
yield {
toolName: "set_output",
input: { error: "Failed to find chosen thinking output." }
};
return;
}
yield {
toolName: "set_output",
input: {
response: chosenThought.content
},
includeToolCall: !1
};
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
}