MCPcopy Index your code
hub / github.com/CodebuffAI/codebuff / loadLocalAgents

Function loadLocalAgents

sdk/src/agents/load-agents.ts:201–312  ·  view source on GitHub ↗
({
  agentsPath,
  verbose = false,
  validate = false,
}: {
  agentsPath?: string
  verbose?: boolean
  validate?: boolean
})

Source from the content-addressed store, hash-verified

199
200// Implementation
201export async function loadLocalAgents({
202 agentsPath,
203 verbose = false,
204 validate = false,
205}: {
206 agentsPath?: string
207 verbose?: boolean
208 validate?: boolean
209}): Promise<LoadedAgents | LoadLocalAgentsResult> {
210 const agents: LoadedAgents = {}
211
212 const agentDirs = agentsPath ? [agentsPath] : getDefaultAgentDirs()
213 const allAgentFiles = agentDirs.flatMap((dir) => getAllAgentFiles(dir))
214
215 if (allAgentFiles.length === 0) {
216 return validate ? { agents, validationErrors: [] } : agents
217 }
218
219 for (const fullPath of allAgentFiles) {
220 try {
221 const agentModule = await importAgentModule(fullPath)
222 if (!agentModule) {
223 continue
224 }
225 const agentDefinition = agentModule.default ?? agentModule
226
227 if (!agentDefinition?.id || !agentDefinition?.model) {
228 if (verbose) {
229 console.error(
230 `Agent definition missing required attributes (id, model): ${fullPath}`,
231 )
232 }
233 continue
234 }
235
236 const processedAgentDefinition: LoadedAgentDefinition = {
237 ...agentDefinition,
238 _sourceFilePath: fullPath,
239 }
240 if (agentDefinition.handleSteps) {
241 processedAgentDefinition.handleSteps =
242 agentDefinition.handleSteps.toString()
243 }
244
245 // Resolve $env references in MCP server configs
246 try {
247 resolveAgentMcpEnv(processedAgentDefinition)
248 } catch (error) {
249 if (verbose) {
250 console.error(error instanceof Error ? error.message : String(error))
251 }
252 continue
253 }
254
255 agents[processedAgentDefinition.id] = processedAgentDefinition
256 } catch (error) {
257 if (verbose) {
258 console.error(

Callers 10

announceLoadedAgentsFunction · 0.90
getLoadedAgentsMessageFunction · 0.90
getLoadedAgentsDataFunction · 0.90
initialSessionStateFunction · 0.90
mainFunction · 0.90
runBuffBenchFunction · 0.90
mainFunction · 0.90
mainFunction · 0.90

Calls 7

validateAgentsFunction · 0.90
getAllAgentFilesFunction · 0.85
importAgentModuleFunction · 0.85
resolveAgentMcpEnvFunction · 0.85
setMethod · 0.80
getDefaultAgentDirsFunction · 0.70
getMethod · 0.65

Tested by 2

mainFunction · 0.72
mainFunction · 0.72