import type { AgentDefinition, ToolCall } from '@codebuff/sdk'
const fileExplorerAgent: AgentDefinition = {
id: 'advanced-file-explorer',
displayName: 'Parallel File Explorer',
model: 'openai/gpt-5.1',
toolNames: ['spawn_agents', 'set_output'],
spawnableAgents: ['codebuff/[email protected]'],
includeMessageHistory: false,
spawnerPrompt: 'Spawns multiple file picker agents in parallel to explore the codebase',
inputSchema: {
prompt: {
description: 'What you need to accomplish by exploring the codebase',
type: 'string',
},
params: {
type: 'object',
properties: {
prompts: {
description: 'List of 1-4 different parts of the codebase to explore',
type: 'array',
items: { type: 'string' },
},
},
required: ['prompts'],
},
},
outputMode: 'structured_output',
outputSchema: {
type: 'object',
properties: {
results: {
type: 'string',
description: 'The results of the file exploration',
},
},
required: ['results'],
},
handleSteps: function* ({ prompt, params }) {
const prompts: string[] = params?.prompts ?? []
// Map prompts to file picker tasks
const filePickerPrompts = prompts.map(
(focusPrompt) =>
`Based on the overall goal "${prompt}", find files related to: ${focusPrompt}`,
)
// Spawn multiple agents in parallel
const { toolResult: spawnResult } = yield {
toolName: 'spawn_agents',
input: {
agents: filePickerPrompts.map((promptText) => ({
agent_type: 'codebuff/[email protected]',
prompt: promptText,
})),
},
} satisfies ToolCall
// Set the structured output
yield {
toolName: 'set_output',
input: {
results: spawnResult,
},
} satisfies ToolCall
},
}
// Usage
const client = new CodebuffClient({
apiKey: process.env.CODEBUFF_API_KEY,
cwd: process.cwd(),
})
const result = await client.run({
agent: 'advanced-file-explorer',
agentDefinitions: [fileExplorerAgent],
prompt: 'Find all authentication-related code',
params: {
prompts: [
'authentication logic',
'user session management',
'API token handling',
'password hashing',
],
},
handleEvent: (event) => {
console.log('Progress:', event)
},
})