const agentDefinition = {
id: "thinker-best-of-n-opus",
displayName: "Best-of-N Opus Thinker",
publisher: "codebuff",
version: "0.0.9",
model: "anthropic/claude-opus-4.5",
toolNames: [
"spawn_agents"
],
spawnableAgents: [
],
inputSchema: {
params: {
type: "object",
properties: {
n: {
type: "number",
description: "Number of parallel thinker agents to spawn. Defaults to 3. Use fewer for simple questions and max of 6 for complex questions."
}
}
},
prompt: {
type: "string",
description: "The problem you are trying to solve, very briefly. No need to provide context, as the thinker agent can see the entire conversation history."
}
},
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 subagent of the thinker-best-of-n agent that was spawned by the parent agent.
Instructions:
Use the <think> tag to think deeply about the user request.
When satisfied, write out a brief response to the user's request. The parent agent will see your response -- no need to call any tools. In particular, do not use the spawn_agents tool or the set_output tool or any tools at all! `,
stepPrompt: ``,
handleSteps: function* handleStepsOpus({
agentState,
prompt,
params
}) {
const n = Math.min(10, Math.max(1, params?.n ?? 3)), { nResponses = [] } = yield {
type: "GENERATE_N",
n
}, thoughts = nResponses.map((content, index) => ({
id: "ABCDEFGHIJKLMNOPQRSTUVWXYZ"[index],
content: content.replace(/<think>[\s\S]*?<\/think>/g, "").trim()
})), { toolResult: selectorResult } = yield {
toolName: "spawn_agents",
input: {
agents: [
{
agent_type: "thinker-selector-opus",
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
}