MCPcopy
hub / github.com/21st-dev/1code / buildAgentsOption

Function buildAgentsOption

src/main/lib/trpc/routers/agent-utils.ts:274–316  ·  view source on GitHub ↗
(
  agentNames: string[],
  cwd?: string
)

Source from the content-addressed store, hash-verified

272 * OPTIMIZATION: Caches loaded agents to avoid re-reading from disk
273 */
274export async function buildAgentsOption(
275 agentNames: string[],
276 cwd?: string
277): Promise<
278 Record<
279 string,
280 { description: string; prompt: string; tools?: string[]; model?: AgentModel }
281 >
282> {
283 if (agentNames.length === 0) return {}
284
285 const agents: Record<
286 string,
287 { description: string; prompt: string; tools?: string[]; model?: AgentModel }
288 > = {}
289
290 for (const name of agentNames) {
291 // Create cache key including cwd to handle project-specific agents
292 const cacheKey = cwd ? `${name}:${cwd}` : name
293
294 // Check cache first
295 let agent = agentCache.get(cacheKey)
296 if (agent === undefined) {
297 // Not in cache, load from disk
298 console.log(`[agents] Cache MISS for ${name} - loading from disk`)
299 agent = await loadAgent(name, cwd)
300 agentCache.set(cacheKey, agent)
301 } else {
302 console.log(`[agents] Cache HIT for ${name}`)
303 }
304
305 if (agent) {
306 agents[name] = {
307 description: agent.description,
308 prompt: agent.prompt,
309 ...(agent.tools && { tools: agent.tools }),
310 ...(agent.model && { model: agent.model }),
311 }
312 }
313 }
314
315 return agents
316}

Callers 1

claude.tsFile · 0.90

Calls 3

loadAgentFunction · 0.85
getMethod · 0.45
setMethod · 0.45

Tested by

no test coverage detected