Files
ruflo/examples/parallel-2/coordinator-agent-test.ts
T
rUvandClaude 30280971bb 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

124 lines
3.6 KiB
TypeScript

#!/usr/bin/env ts-node
/**
* Coordinator Agent Test - Designed for parallel execution
* This agent orchestrates and manages other agents
*/
export class CoordinatorAgent {
private agentId: string;
private startTime: number;
private managedAgents: Set<string>;
constructor(id: string = 'coordinator-001') {
this.agentId = id;
this.startTime = Date.now();
this.managedAgents = new Set();
}
async orchestrateSwarmTask(taskDescription: string, agentCount: number = 3): Promise<any> {
console.log(`[${this.agentId}] Orchestrating swarm task: ${taskDescription}`);
console.log(`[${this.agentId}] Deploying ${agentCount} agents...`);
// Simulate agent deployment
await this.simulateWork(500);
const agents = [];
for (let i = 0; i < agentCount; i++) {
const agentId = `agent-${Date.now()}-${i}`;
this.managedAgents.add(agentId);
agents.push({
id: agentId,
type: this.selectAgentType(i),
status: 'active',
task: this.assignTask(taskDescription, i)
});
}
console.log(`[${this.agentId}] Swarm deployed successfully`);
return {
agentId: this.agentId,
duration: Date.now() - this.startTime,
swarmSize: agents.length,
agents
};
}
async monitorProgress(): Promise<any> {
console.log(`[${this.agentId}] Monitoring swarm progress...`);
await this.simulateWork(1000);
const progress = {
totalAgents: this.managedAgents.size,
activeAgents: Math.floor(this.managedAgents.size * 0.8),
completedTasks: Math.floor(Math.random() * 10) + 5,
pendingTasks: Math.floor(Math.random() * 5),
avgCompletionTime: Math.floor(Math.random() * 1000) + 500,
healthStatus: 'optimal'
};
console.log(`[${this.agentId}] Progress update generated`);
return {
agentId: this.agentId,
duration: Date.now() - this.startTime,
progress
};
}
async rebalanceWorkload(): Promise<any> {
console.log(`[${this.agentId}] Rebalancing workload across agents...`);
await this.simulateWork(700);
const rebalancing = {
agentsRebalanced: Math.floor(this.managedAgents.size / 2),
tasksRedistributed: Math.floor(Math.random() * 10) + 3,
efficiencyGain: `${Math.floor(Math.random() * 20) + 10}%`,
newDistribution: Array.from(this.managedAgents).map(id => ({
agentId: id,
workload: Math.floor(Math.random() * 100)
}))
};
console.log(`[${this.agentId}] Workload rebalancing completed`);
return {
agentId: this.agentId,
duration: Date.now() - this.startTime,
rebalancing
};
}
private selectAgentType(index: number): string {
const types = ['researcher', 'developer', 'analyzer', 'reviewer', 'tester'];
return types[index % types.length];
}
private assignTask(description: string, index: number): string {
const tasks = [
`Research ${description}`,
`Implement ${description}`,
`Analyze ${description}`,
`Review ${description}`,
`Test ${description}`
];
return tasks[index % tasks.length];
}
private async simulateWork(ms: number): Promise<void> {
await new Promise(resolve => setTimeout(resolve, ms));
}
}
// Allow direct execution
if (require.main === module) {
const coordinator = new CoordinatorAgent();
Promise.all([
coordinator.orchestrateSwarmTask('Build authentication system', 5),
coordinator.monitorProgress(),
coordinator.rebalanceWorkload()
]).then(results => {
console.log('\nCoordinator Agent Results:', JSON.stringify(results, null, 2));
});
}