/** * @license * Copyright 2025 Google LLC * SPDX-License-Identifier: Apache-2.0 */ import type { Config } from '../config/config.js'; import type { AgentDefinition } from './types.js'; import { CodebaseInvestigatorAgent } from './codebase-investigator.js'; import { type z } from 'zod'; /** * Manages the discovery, loading, validation, and registration of * AgentDefinitions. */ export class AgentRegistry { // eslint-disable-next-line @typescript-eslint/no-explicit-any private readonly agents = new Map>(); constructor(private readonly config: Config) {} /** * Discovers and loads agents. */ async initialize(): Promise { this.loadBuiltInAgents(); if (this.config.getDebugMode()) { console.log( `[AgentRegistry] Initialized with ${this.agents.size} agents.`, ); } } private loadBuiltInAgents(): void { this.registerAgent(CodebaseInvestigatorAgent); } /** * Registers an agent definition. If an agent with the same name exists, * it will be overwritten, respecting the precedence established by the * initialization order. */ protected registerAgent( definition: AgentDefinition, ): void { // Basic validation if (!definition.name || !definition.description) { console.warn( `[AgentRegistry] Skipping invalid agent definition. Missing name or description.`, ); return; } if (this.agents.has(definition.name) && this.config.getDebugMode()) { console.log(`[AgentRegistry] Overriding agent '${definition.name}'`); } this.agents.set(definition.name, definition); } /** * Retrieves an agent definition by name. */ getDefinition(name: string): AgentDefinition | undefined { return this.agents.get(name); } /** * Returns all active agent definitions. */ getAllDefinitions(): AgentDefinition[] { return Array.from(this.agents.values()); } }