Skip to content

Commit ccd21f6

Browse files
committed
fix: actually fixed dynamic agents heh
1 parent e89e48d commit ccd21f6

File tree

4 files changed

+24
-28
lines changed

4 files changed

+24
-28
lines changed

backend/src/templates/agent-registry.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,8 @@ class AgentRegistry {
1919
* Initialize the registry with a file context (needed for dynamic agent loading)
2020
*/
2121
async initialize(fileContext: ProjectFileContext): Promise<void> {
22-
if (this.isInitialized) {
23-
return
24-
}
22+
// Reset state to ensure fresh loading
23+
this.reset()
2524

2625
// Load dynamic agents using the service
2726
const { templates: dynamicTemplates, validationErrors } =
@@ -80,6 +79,8 @@ class AgentRegistry {
8079
'Dynamic agent template validation errors'
8180
)
8281
}
82+
83+
8384
}
8485

8586
/**
@@ -169,6 +170,8 @@ class AgentRegistry {
169170
this.allAgentNames = {}
170171
this.isInitialized = false
171172
this.validationErrors = []
173+
// Also reset the dynamic agent service
174+
dynamicAgentService.reset()
172175
}
173176
}
174177

backend/src/templates/dynamic-agent-service.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ export class DynamicAgentService {
4747
const agentTemplates = fileContext.agentTemplates || {}
4848
const hasAgentTemplates = Object.keys(agentTemplates).length > 0
4949

50+
51+
5052
if (!hasAgentTemplates) {
5153
this.isLoaded = true
5254
return {
@@ -86,13 +88,7 @@ export class DynamicAgentService {
8688

8789
this.isLoaded = true
8890

89-
const templateCount = Object.keys(this.templates).length
90-
if (templateCount > 0 && logger?.info) {
91-
logger.info(
92-
{ templateCount, agentIds: Object.keys(this.templates) },
93-
'Dynamic agents loaded successfully'
94-
)
95-
}
91+
9692

9793
return {
9894
templates: this.templates,

backend/src/websockets/websocket-action.ts

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -279,32 +279,26 @@ const onInit = async (
279279
let allValidationErrors: Array<{ filePath: string; message: string }> = []
280280

281281
if (agentTemplates) {
282-
// Load dynamic agent templates first to get their IDs
283-
const { validationErrors: dynamicErrors } =
284-
await dynamicAgentService.loadAgents(fileContext)
285-
allValidationErrors.push(...dynamicErrors)
282+
// Initialize agent registry (this will load dynamic agents and handle validation)
283+
await agentRegistry.initialize(fileContext)
286284

287-
if (dynamicErrors.length > 0 && logger?.warn) {
285+
// Get validation errors from the registry
286+
allValidationErrors = agentRegistry.getValidationErrors()
287+
288+
if (allValidationErrors.length > 0) {
288289
logger.warn(
289-
{ errorCount: dynamicErrors.length },
290-
'Dynamic agent validation errors found'
290+
{ errorCount: allValidationErrors.length },
291+
'Agent template validation errors found'
291292
)
292293
}
293-
294-
// Get dynamic agent IDs for override validation
295-
const dynamicAgentIds = dynamicAgentService.getAgentTypes()
296-
// Validate override templates with dynamic agent IDs
297-
const { validationErrors: overrideErrors } = validateAgentTemplateConfigs(
298-
agentTemplates,
299-
dynamicAgentIds
300-
)
301-
allValidationErrors.push(...overrideErrors)
294+
} else {
295+
// Still need to initialize the registry even without agent templates
296+
await agentRegistry.initialize(fileContext)
302297
}
303298

304299
const errorMessage = formatValidationErrorMessage(allValidationErrors)
305300

306301
// Get all agent names (static + dynamic) for frontend
307-
await agentRegistry.initialize(fileContext)
308302
const allAgentNames = agentRegistry.getAllAgentNames()
309303

310304
// Send combined init and usage response

common/src/util/agent-template-validation.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@ import {
99
DynamicAgentTemplateSchema,
1010
} from '../types/dynamic-agent-template'
1111
import { AgentTemplateTypes } from '../types/session-state'
12-
import { normalizeAgentName, normalizeAgentNames } from './agent-name-normalization'
12+
import {
13+
normalizeAgentName,
14+
normalizeAgentNames,
15+
} from './agent-name-normalization'
1316

1417
export interface SpawnableAgentValidationResult {
1518
valid: boolean

0 commit comments

Comments
 (0)