Files
ruflo/examples/parallel-2/specialist-agent-test.ts
T
rUvandClaude 8cbc07a6f4 fix: Implement critical swarm fixes and add v1.0.50 changelog
## 🔧 Critical Swarm System Fixes

### Fixed Task File Naming Bug
- Tasks were being saved as '[object Object].json' due to TaskId object structure
- Now properly extracts task ID string for file naming
- Files save correctly as 'task_<id>.json'

### Added Task Timeout Protection
- Implemented automatic timeout detection in task execution loop
- Tasks that exceed timeout (default 5 minutes) are marked as failed
- Prevents swarms from hanging indefinitely on stuck tasks
- Agent state properly cleaned up on timeout

### Fixed Target Directory Propagation
- Testing tasks were receiving null targetDir, preventing file access
- Target directory now extracted from objective description
- All tasks inherit targetDir through context
- Enhanced extractTargetDirectory to check multiple sources

### Improved Task Dependencies
- Fixed taskDependenciesMet to handle both string and TaskId objects
- Added convertDependenciesToTaskDependencies for Map structure
- Dependencies now properly resolve for sequential task execution

### Auto Strategy Integration
- Added missing autoStrategy property and initialization
- Proper AutoStrategy instantiation in coordinator constructor
- Enables intelligent task decomposition for 'auto' strategy

## 📊 Added Comprehensive Benchmarks

### Benchmark Suite Integration
- Added complete Python-based benchmarking tool
- Tests 7 strategies across 5 coordination modes
- 100% success rate across all test scenarios
- Performance metrics: 0.10s - 0.20s execution times

### Real-World Performance Data
- Calculator example: 4m 20s total (3 tasks)
- Task breakdown: Analysis 29%, Implementation 22%, Testing 48%
- Successfully created 6 files with proper directory structure

## 📝 Documentation Updates

### Updated README.md
- Added v1.0.50 changelog with critical fixes
- Integrated benchmark performance results table
- Added real-world timing example
- Removed old update notes for clarity
- Added dedicated Benchmarks & Performance section

## 🧪 Test Results
- Swarm now completes successfully with proper task coordination
- All fixes validated in production environment
- Task files save with correct names
- Testing tasks find implementation files
- Swarms exit cleanly after completion

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-06-14 22:48:11 +00:00

268 lines
8.2 KiB
TypeScript

#!/usr/bin/env ts-node
/**
* Specialist Agent Test - Designed for parallel execution
* This agent provides domain-specific expertise
*/
export class SpecialistAgent {
private agentId: string;
private startTime: number;
private specialty: string;
constructor(id: string = 'specialist-001', specialty: string = 'general') {
this.agentId = id;
this.startTime = Date.now();
this.specialty = specialty;
}
async provideMachineLearningExpertise(problem: string): Promise<any> {
console.log(`[${this.agentId}] Analyzing ML problem: ${problem}`);
await this.simulateWork(1500);
const mlAnalysis = {
problemType: 'Binary Classification',
recommendedApproach: {
algorithm: 'Gradient Boosting (XGBoost)',
alternativeAlgorithms: ['Random Forest', 'Neural Network', 'SVM'],
reasoning: 'Handles mixed data types well, good for tabular data'
},
dataRequirements: {
minimumSamples: 10000,
recommendedSamples: 50000,
features: [
'Customer demographics',
'Purchase history',
'Engagement metrics',
'Support interactions'
],
preprocessing: [
'Handle missing values',
'Encode categorical variables',
'Normalize numerical features',
'Feature engineering for recency/frequency'
]
},
expectedPerformance: {
accuracy: '85-90%',
precision: '82-87%',
recall: '80-85%',
f1Score: '81-86%'
},
implementation: {
estimatedTime: '2-3 weeks',
requiredTools: ['Python', 'scikit-learn', 'XGBoost', 'pandas'],
deployment: 'REST API with model versioning'
}
};
console.log(`[${this.agentId}] ML analysis completed`);
return {
agentId: this.agentId,
duration: Date.now() - this.startTime,
specialty: 'Machine Learning',
problem,
analysis: mlAnalysis
};
}
async provideSecurityExpertise(component: string): Promise<any> {
console.log(`[${this.agentId}] Security analysis for: ${component}`);
await this.simulateWork(1200);
const securityAnalysis = {
threatModel: {
assets: ['User credentials', 'Session tokens', 'Personal data'],
threats: [
'Brute force attacks',
'Session hijacking',
'Token replay attacks',
'SQL injection',
'XSS attacks'
],
riskLevel: 'Medium-High'
},
recommendations: {
authentication: [
'Implement PKCE for OAuth flows',
'Use argon2 for password hashing',
'Enforce MFA for sensitive operations',
'Implement account lockout policies'
],
sessionManagement: [
'Use secure, httpOnly, sameSite cookies',
'Implement JWT rotation',
'Set appropriate token expiration',
'Store refresh tokens securely'
],
dataProtection: [
'Encrypt sensitive data at rest',
'Use TLS 1.3 for transport',
'Implement field-level encryption',
'Regular security key rotation'
]
},
complianceConsiderations: {
GDPR: ['Right to deletion', 'Data portability', 'Consent management'],
PCI_DSS: ['Not applicable unless handling payment data'],
SOC2: ['Access controls', 'Audit logging', 'Encryption']
},
securityScore: 7.5
};
console.log(`[${this.agentId}] Security analysis completed`);
return {
agentId: this.agentId,
duration: Date.now() - this.startTime,
specialty: 'Security',
component,
analysis: securityAnalysis
};
}
async provideCloudArchitectureExpertise(requirements: any): Promise<any> {
console.log(`[${this.agentId}] Designing cloud architecture for: ${requirements.application}`);
await this.simulateWork(2000);
const cloudArchitecture = {
provider: 'AWS',
architecture: 'Microservices with Serverless components',
services: {
compute: ['ECS Fargate', 'Lambda', 'API Gateway'],
storage: ['S3', 'DynamoDB', 'ElastiCache'],
networking: ['VPC', 'CloudFront', 'Route53'],
security: ['WAF', 'Secrets Manager', 'IAM'],
monitoring: ['CloudWatch', 'X-Ray', 'CloudTrail']
},
scalingStrategy: {
type: 'Auto-scaling',
minInstances: 2,
maxInstances: 100,
targetCPU: 70,
targetMemory: 80
},
disasterRecovery: {
rto: '4 hours',
rpo: '1 hour',
backupStrategy: 'Cross-region replication',
failoverStrategy: 'Active-passive with Route53'
},
costEstimate: {
monthly: '$2,850',
breakdown: {
compute: '$1,200',
storage: '$450',
networking: '$600',
other: '$600'
},
optimization: [
'Use Spot instances for non-critical workloads',
'Implement S3 lifecycle policies',
'Reserved instances for baseline capacity'
]
},
implementationPlan: {
phase1: 'Core infrastructure (2 weeks)',
phase2: 'Service deployment (3 weeks)',
phase3: 'Security hardening (1 week)',
phase4: 'Performance optimization (1 week)'
}
};
console.log(`[${this.agentId}] Cloud architecture design completed`);
return {
agentId: this.agentId,
duration: Date.now() - this.startTime,
specialty: 'Cloud Architecture',
requirements: requirements.application,
architecture: cloudArchitecture,
monthlyCost: cloudArchitecture.costEstimate.monthly
};
}
async providePerformanceOptimization(system: string): Promise<any> {
console.log(`[${this.agentId}] Optimizing performance for: ${system}`);
await this.simulateWork(1800);
const optimization = {
currentPerformance: {
responseTime: '450ms avg',
throughput: '1,200 req/s',
errorRate: '1.2%',
cpuUsage: '75%',
memoryUsage: '82%'
},
bottlenecks: [
{ area: 'Database queries', impact: 'High', solution: 'Query optimization and indexing' },
{ area: 'API serialization', impact: 'Medium', solution: 'Implement response caching' },
{ area: 'Memory allocation', impact: 'Medium', solution: 'Object pooling and GC tuning' }
],
optimizationPlan: {
immediate: [
'Add database indexes on frequently queried columns',
'Implement Redis caching for hot data',
'Enable HTTP response compression'
],
shortTerm: [
'Refactor N+1 queries',
'Implement database connection pooling',
'Add CDN for static assets'
],
longTerm: [
'Migrate to read replicas',
'Implement CQRS pattern',
'Consider microservices decomposition'
]
},
expectedImprovements: {
responseTime: '150ms avg (-67%)',
throughput: '3,500 req/s (+192%)',
errorRate: '0.3% (-75%)',
cpuUsage: '45% (-40%)',
memoryUsage: '60% (-27%)'
},
roi: {
implementationCost: '$15,000',
monthlySavings: '$3,500',
paybackPeriod: '4.3 months'
}
};
console.log(`[${this.agentId}] Performance optimization completed`);
return {
agentId: this.agentId,
duration: Date.now() - this.startTime,
specialty: 'Performance Engineering',
system,
optimization
};
}
private async simulateWork(ms: number): Promise<void> {
await new Promise(resolve => setTimeout(resolve, ms));
}
}
// Allow direct execution
if (require.main === module) {
const specialist = new SpecialistAgent();
const cloudRequirements = {
application: 'E-commerce Platform',
expectedUsers: 500000,
regions: ['US', 'EU', 'Asia'],
budget: '$3000/month'
};
Promise.all([
specialist.provideMachineLearningExpertise('Customer churn prediction'),
specialist.provideSecurityExpertise('User Authentication Module'),
specialist.provideCloudArchitectureExpertise(cloudRequirements),
specialist.providePerformanceOptimization('Order Processing System')
]).then(results => {
console.log('\nSpecialist Agent Results:', JSON.stringify(results, null, 2));
});
}