claude-flow-novice
Version:
Claude Flow Novice - Advanced orchestration platform for multi-agent AI workflows with CFN Loop architecture Includes Local RuVector Accelerator and all CFN skills for complete functionality.
169 lines (168 loc) • 6 kB
JavaScript
import { ResourceTier } from './types/fleet-manager.types.js';
export class FleetManager {
redis;
agentRegistry;
dependencyTracker;
transparencyMiddleware;
config;
agentAllocations;
performanceHistory;
constructor(redisClient, agentRegistry, dependencyTracker, transparencyMiddleware, config){
this.redis = redisClient;
this.agentRegistry = agentRegistry;
this.dependencyTracker = dependencyTracker;
this.transparencyMiddleware = transparencyMiddleware;
this.config = {
maxAgents: config?.maxAgents ?? 1000,
resourceAllocationStrategy: config?.resourceAllocationStrategy ?? 'least-loaded'
};
this.agentAllocations = new Map();
this.performanceHistory = new Map();
}
async registerAgent(agentId, tier = ResourceTier.Shared) {
// Check if agent registry allows registration
const registrationResult = await this.agentRegistry.registerAgent(agentId);
if (!registrationResult) {
this.transparencyMiddleware.logEvent('fleet_manager', 'agent_registration_failed', {
agentId
});
return false;
}
// Validate agent count
const currentAgentCount = this.agentAllocations.size;
if (currentAgentCount >= this.config.maxAgents) {
this.transparencyMiddleware.logEvent('fleet_manager', 'max_agents_reached', {
currentCount: currentAgentCount,
maxAgents: this.config.maxAgents
});
return false;
}
// Store agent allocation
const defaultResources = this.getDefaultResourcesByTier(tier);
const initialMetrics = this.createInitialMetrics();
const allocation = {
agentId,
tier,
allocatedResources: defaultResources,
currentMetrics: initialMetrics
};
this.agentAllocations.set(agentId, allocation);
this.performanceHistory.set(agentId, [
initialMetrics
]);
// Redis tracking
await this.redis.hset(`fleet:agents:${agentId}`, 'tier', tier);
await this.redis.sadd('fleet:registered_agents', agentId);
this.transparencyMiddleware.logEvent('fleet_manager', 'agent_registered', {
agentId,
tier
});
return true;
}
async allocateResources(agentId, requirements) {
const currentAllocation = this.agentAllocations.get(agentId);
if (!currentAllocation) {
return false;
}
// Validate resource allocation based on tier
const isAllocationValid = this.validateResourceAllocation(currentAllocation.tier, requirements);
if (!isAllocationValid) {
this.transparencyMiddleware.logEvent('fleet_manager', 'resource_allocation_denied', {
agentId,
requirements,
tier: currentAllocation.tier
});
return false;
}
// Update allocation
currentAllocation.allocatedResources = requirements;
this.agentAllocations.set(agentId, currentAllocation);
// Redis tracking
await this.redis.hset(`fleet:agents:${agentId}`, 'resources', JSON.stringify(requirements));
this.transparencyMiddleware.logEvent('fleet_manager', 'resources_allocated', {
agentId,
requirements
});
return true;
}
async getPerformanceMetrics(agentId) {
const history = this.performanceHistory.get(agentId);
return history ? history[history.length - 1] : null;
}
async balanceLoad(agents) {
const loadBalancingResult = {
rebalancedAgents: [],
migrationPlan: {}
};
switch(this.config.resourceAllocationStrategy){
case 'least-loaded':
return this.leastLoadedBalancing(agents);
case 'round-robin':
return this.roundRobinBalancing(agents);
case 'weighted':
return this.weightedBalancing(agents);
default:
return loadBalancingResult;
}
}
getDefaultResourcesByTier(tier) {
switch(tier){
case ResourceTier.Shared:
return {
cpu: 2,
memory: 4,
network: 50,
storageIO: 100
};
case ResourceTier.Dedicated:
return {
cpu: 8,
memory: 16,
network: 200,
storageIO: 500
};
case ResourceTier.Premium:
return {
cpu: 16,
memory: 32,
network: 500,
storageIO: 1000
};
}
}
createInitialMetrics() {
return {
cpuUtilization: 0,
memoryUsage: 0,
networkThroughput: 0,
storageIOPS: 0,
timestamp: Date.now()
};
}
validateResourceAllocation(tier, requirements) {
const tierLimits = this.getDefaultResourcesByTier(tier);
return requirements.cpu <= tierLimits.cpu && requirements.memory <= tierLimits.memory && requirements.network <= tierLimits.network && requirements.storageIO <= tierLimits.storageIO;
}
leastLoadedBalancing(agents) {
// Placeholder implementation
return {
rebalancedAgents: [],
migrationPlan: {}
};
}
roundRobinBalancing(agents) {
// Placeholder implementation
return {
rebalancedAgents: [],
migrationPlan: {}
};
}
weightedBalancing(agents) {
// Placeholder implementation
return {
rebalancedAgents: [],
migrationPlan: {}
};
}
}
//# sourceMappingURL=fleet-manager.js.map