Codebuff

thinker-best-of-n

v0.0.3
Published Nov 18, 2025

Usage Statistics
v0.0.3

Definition

const agentDefinition = {
id: "thinker-best-of-n",
displayName: "Best-of-N Thinker",
publisher: "codebuff",
version: "0.0.3",
model: "anthropic/claude-sonnet-4.5",
toolNames: [
"spawn_agents"
],
spawnableAgents: [
"codebuff/thinker-selector@0.0.3"
],
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: "last_message",
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: `You are one agent within the thinker-best-of-n. You were spawned to generate deep thinking about the user's request.
Answer the user's query to the best of your ability and be extremely concise and to the point.
**Important**: Do not use any tools! You are only thinking!`,
stepPrompt: ``,
handleSteps: function* handleSteps({
agentState,
prompt,
params
}) {
const n = Math.min(10, Math.max(1, params?.n ?? 5)), { nResponses = [] } = yield {
type: "GENERATE_N",
n
}, thoughts = nResponses.map((content, index) => ({
id: "ABCDEFGHIJKLMNOPQRSTUVWXYZ"[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 {
type: "STEP_TEXT",
text: selectorOutput.errorMessage
};
return;
}
const { thoughtId } = selectorOutput, chosenThought = thoughts.find((thought) => thought.id === thoughtId);
if (!chosenThought) {
yield {
type: "STEP_TEXT",
text: "Failed to find chosen thinking output."
};
return;
}
yield {
type: "STEP_TEXT",
text: chosenThought.content
};
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
}