Skip to content

Commit 89841ce

Browse files
committed
cli: Update base agent definitions to include .agents. agent runtime: never modify spawnable agents
1 parent 8d31e36 commit 89841ce

File tree

2 files changed

+25
-10
lines changed

2 files changed

+25
-10
lines changed

cli/src/utils/local-agent-registry.ts

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -264,25 +264,47 @@ export const loadLocalAgents = (currentAgentMode?: AgentMode): LocalAgentInfo[]
264264
* Bundled agents are compiled into the CLI binary at build time.
265265
* User agents from .agents/ are loaded via SDK at startup and cached.
266266
* User agents can override bundled agents with the same ID.
267+
*
268+
* Additionally, all user agent IDs are automatically added to the spawnableAgents
269+
* of any base agent (agents with IDs starting with 'base'), so users can spawn
270+
* their custom agents without needing to modify the base agent definition.
267271
*/
268272
export const loadAgentDefinitions = (): AgentDefinition[] => {
269273
// Start with bundled agents - these are the default Codebuff agents
270274
const bundledAgents = getBundledAgents()
271-
const definitions: AgentDefinition[] = Object.values(bundledAgents)
275+
const definitions: AgentDefinition[] = Object.values(bundledAgents).map(def => ({ ...def }))
272276
const bundledIds = new Set(Object.keys(bundledAgents))
273277

274278
// Get user agents from the SDK-loaded cache
275279
const userAgentDefs = getUserAgentDefinitions()
280+
const userAgentIds = userAgentDefs.map(def => def.id)
276281

277282
for (const agentDef of userAgentDefs) {
278283
// User agents override bundled agents with the same ID
279284
if (bundledIds.has(agentDef.id)) {
280285
const idx = definitions.findIndex(d => d.id === agentDef.id)
281286
if (idx !== -1) {
282-
definitions[idx] = agentDef
287+
definitions[idx] = { ...agentDef }
283288
}
284289
} else {
285-
definitions.push(agentDef)
290+
definitions.push({ ...agentDef })
291+
}
292+
}
293+
294+
// Auto-add user agent IDs to spawnableAgents of base agents
295+
// This allows users to spawn their custom agents without needing to
296+
// explicitly add them to the base agent's spawnableAgents list
297+
if (userAgentIds.length > 0) {
298+
for (const def of definitions) {
299+
// Consider any agent with an ID starting with 'base' as a base agent
300+
if (def.id.startsWith('base') && def.spawnableAgents) {
301+
const existingSpawnable = new Set(def.spawnableAgents)
302+
for (const userAgentId of userAgentIds) {
303+
if (!existingSpawnable.has(userAgentId)) {
304+
def.spawnableAgents = [...def.spawnableAgents, userAgentId]
305+
}
306+
}
307+
}
286308
}
287309
}
288310

packages/agent-runtime/src/main-prompt.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -106,13 +106,6 @@ export async function mainPrompt(
106106
throw new Error(`Agent template not found for type: ${agentType}`)
107107
}
108108

109-
const updatedSubagents = agentId
110-
? // Use only the spawnable agents from the main agent template if an agent ID is specified
111-
mainAgentTemplate.spawnableAgents
112-
: uniq([...mainAgentTemplate.spawnableAgents, ...availableAgents])
113-
mainAgentTemplate.spawnableAgents = updatedSubagents
114-
localAgentTemplates[agentType] = mainAgentTemplate
115-
116109
const { agentState, output } = await loopAgentSteps({
117110
...params,
118111
userInputId: promptId,

0 commit comments

Comments
 (0)