mnemos-coder
Version:
CLI-based coding agent with graph-based execution loop and terminal UI
194 lines (181 loc) • 6.21 kB
JavaScript
/**
* SubagentRegistry - Centralized metadata management for subagents
*
* This class provides a unified interface for managing subagent configurations,
* generating dynamic tool specifications, and building system prompts.
*/
export class SubagentRegistry {
config;
subagents = [];
taskToolSpec = null;
systemPromptTemplate = '';
constructor(config) {
this.config = config;
this.buildRegistry();
}
/**
* Build the registry from configuration
*/
buildRegistry() {
if (!this.config.subagents) {
return;
}
this.subagents = Object.values(this.config.subagents)
.filter((config) => config.enabled !== false)
.map((config) => ({
name: config.name,
description: config.description || 'No description available',
tools: config.tools || [],
llmProfile: config.llmProfile || 'default',
enabled: config.enabled !== false
}));
this.buildTaskToolSpec();
this.buildSystemPromptTemplate();
}
/**
* Generate dynamic Task tool specification
*/
buildTaskToolSpec() {
const subagentNames = this.subagents.map(s => s.name);
const subagentDescriptions = this.subagents
.map(s => `${s.name}: ${s.description}`)
.join('; ');
this.taskToolSpec = {
name: "Task",
description: `Delegate tasks to specialized subagents. Available subagents: ${subagentDescriptions}`,
parameters: {
type: "object",
properties: {
subagent_type: {
type: "string",
description: `The specialized subagent to use. Must be one of: ${subagentNames.join(', ')}`,
enum: subagentNames
},
prompt: {
type: "string",
description: "Detailed task description with specific requirements and context"
}
},
required: ["subagent_type", "prompt"]
}
};
}
/**
* Build system prompt template with dynamic subagent information
*/
buildSystemPromptTemplate() {
const subagentList = this.subagents.length > 0
? this.subagents.map(agent => `- **${agent.name}**: ${agent.description}`).join('\n')
: '- No subagents available';
const subagentNames = this.subagents.map(s => s.name).join(', ');
this.systemPromptTemplate = `
=== IMPORTANT: DELEGATION-ONLY MODE ===
You are operating in delegation-only mode. You ONLY have access to the Task tool.
All actual work MUST be delegated to specialized subagents.
## Available Specialized Subagents
${subagentList}
## Delegation Process
When you receive any request:
1. **Analyze** what needs to be done
2. **Choose** the appropriate subagent from the list above based on their descriptions
3. **Delegate** using the Task tool with precise instructions
4. **Monitor** and coordinate subagent responses
Available subagent names: ${subagentNames}
Remember: You cannot directly execute file operations, shell commands, or any other tools.
Everything must go through subagents via the Task tool.
## Orchestration Guidelines
### 🎯 **Task Analysis & Planning**
- Break down complex requests into manageable components
- Identify the type of work each component requires
- Plan the sequence of subagent interactions needed
### 🔄 **Response Evaluation & Next Actions**
After each subagent response, evaluate:
- Was the task completed successfully?
- Does the output meet the requirements?
- Are there follow-up actions needed?
**Decision Matrix:**
- If **successful**: Continue to next planned step or summarize completion
- If **partial**: Delegate remaining work or ask for clarification
- If **failed**: Try different approach or alternative subagent
### 🤝 **Multi-Subagent Coordination**
For complex tasks requiring multiple subagents:
- Pass results from one subagent to another
- Ensure consistency across multi-subagent work
- Resolve conflicts or integration issues
- Provide status updates on multi-step processes
### ✅ **Quality Assurance**
- Validate final results before presenting to user
- Synthesize outputs from multiple subagents into coherent response
- Ensure all user requirements are met
`;
}
/**
* Get all available subagents
*/
getAvailableSubagents() {
return [...this.subagents];
}
/**
* Get a specific subagent by name
*/
getSubagent(name) {
return this.subagents.find(s => s.name === name);
}
/**
* Check if a subagent exists
*/
hasSubagent(name) {
return this.subagents.some(s => s.name === name);
}
/**
* Get the dynamic Task tool specification
*/
getTaskToolSpec() {
if (!this.taskToolSpec) {
this.buildTaskToolSpec();
}
return this.taskToolSpec;
}
/**
* Get the system prompt with dynamic subagent information
*/
getSystemPromptFragment() {
return this.systemPromptTemplate;
}
/**
* Get subagent count
*/
getSubagentCount() {
return this.subagents.length;
}
/**
* Get subagent names as array
*/
getSubagentNames() {
return this.subagents.map(s => s.name);
}
/**
* Validate if a subagent name is valid
*/
validateSubagentName(name) {
return this.hasSubagent(name);
}
/**
* Get debug information about the registry
*/
getDebugInfo() {
return {
subagentCount: this.subagents.length,
subagents: this.subagents.map(s => ({
name: s.name,
description: s.description,
toolCount: s.tools.length,
llmProfile: s.llmProfile,
enabled: s.enabled
})),
hasTaskToolSpec: !!this.taskToolSpec,
systemPromptLength: this.systemPromptTemplate.length
};
}
}
//# sourceMappingURL=SubagentRegistry.js.map