-
Notifications
You must be signed in to change notification settings - Fork 345
Expand file tree
/
Copy pathmulti-agent-coordination.ts
More file actions
88 lines (77 loc) · 3.73 KB
/
multi-agent-coordination.ts
File metadata and controls
88 lines (77 loc) · 3.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
/**
* Agentic-Jujutsu Multi-Agent Coordination Example
*
* Demonstrates how multiple AI agents can work simultaneously:
* - Concurrent commits without locks
* - Shared learning across agents
* - Collaborative workflows
* - Conflict-free coordination
*/
interface JjWrapper {
startTrajectory(task: string): string;
addToTrajectory(): void;
finalizeTrajectory(score: number, critique?: string): void;
getSuggestion(task: string): string;
newCommit(message: string): Promise<any>;
branchCreate(name: string): Promise<any>;
diff(from: string, to: string): Promise<any>;
}
async function multiAgentCoordinationExample() {
console.log('=== Agentic-Jujutsu Multi-Agent Coordination ===\n');
console.log('Scenario: Three AI agents working on different features simultaneously\n');
console.log('=== Agent 1: Backend Developer ===');
console.log('const backend = new JjWrapper();');
console.log('backend.startTrajectory("Implement REST API");');
console.log('await backend.branchCreate("feature/api");');
console.log('await backend.newCommit("Add API endpoints");');
console.log('backend.addToTrajectory();');
console.log('backend.finalizeTrajectory(0.9, "API complete");\n');
console.log('=== Agent 2: Frontend Developer (running concurrently) ===');
console.log('const frontend = new JjWrapper();');
console.log('frontend.startTrajectory("Build UI components");');
console.log('await frontend.branchCreate("feature/ui");');
console.log('await frontend.newCommit("Add React components");');
console.log('frontend.addToTrajectory();');
console.log('frontend.finalizeTrajectory(0.85, "UI components ready");\n');
console.log('=== Agent 3: Tester (benefits from both agents) ===');
console.log('const tester = new JjWrapper();');
console.log('// Get AI suggestions based on previous agents\' work');
console.log('const suggestion = JSON.parse(tester.getSuggestion("Test API and UI"));');
console.log('console.log("AI Recommendation:", suggestion.reasoning);');
console.log('console.log("Confidence:", suggestion.confidence);\n');
console.log('tester.startTrajectory("Create test suite");');
console.log('await tester.branchCreate("feature/tests");');
console.log('await tester.newCommit("Add integration tests");');
console.log('tester.addToTrajectory();');
console.log('tester.finalizeTrajectory(0.95, "Comprehensive test coverage");\n');
console.log('=== Key Benefits ===');
console.log('✓ No locks or waiting - 23x faster than Git');
console.log('✓ All agents learn from each other\'s experience');
console.log('✓ Automatic conflict resolution (87% success rate)');
console.log('✓ Shared pattern discovery across agents');
console.log('✓ Context switching <100ms (10x faster than Git)\n');
console.log('=== Coordinated Code Review ===');
console.log('async function coordinatedReview(agents) {');
console.log(' const reviews = await Promise.all(agents.map(async (agent) => {');
console.log(' const jj = new JjWrapper();');
console.log(' jj.startTrajectory(`Review by ${agent.name}`);');
console.log(' ');
console.log(' const diff = await jj.diff("@", "@-");');
console.log(' const issues = await agent.analyze(diff);');
console.log(' ');
console.log(' jj.addToTrajectory();');
console.log(' jj.finalizeTrajectory(');
console.log(' issues.length === 0 ? 0.9 : 0.6,');
console.log(' `Found ${issues.length} issues`');
console.log(' );');
console.log(' ');
console.log(' return { agent: agent.name, issues };');
console.log(' }));');
console.log(' ');
console.log(' return reviews;');
console.log('}\n');
}
if (require.main === module) {
multiAgentCoordinationExample().catch(console.error);
}
export { multiAgentCoordinationExample };