Skip to content

Commit 97ed9aa

Browse files
committed
docs(explorer): add comprehensive Coordinator integration guide
- Complete integration example with step-by-step setup - Task-based exploration patterns - Multi-agent coordination examples - Health monitoring and statistics - Graceful shutdown handling - Reference to integration tests
1 parent e1a7423 commit 97ed9aa

File tree

1 file changed

+187
-11
lines changed

1 file changed

+187
-11
lines changed

packages/subagents/src/explorer/README.md

Lines changed: 187 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -354,34 +354,210 @@ const response = await explorer.handleMessage({
354354

355355
## Integration with Coordinator
356356

357-
The Explorer works seamlessly with the Subagent Coordinator:
357+
The Explorer integrates seamlessly with the Subagent Coordinator, allowing it to work alongside other agents in a coordinated system.
358+
359+
### Complete Integration Example
358360

359361
```typescript
360-
import { SubagentCoordinator, ExplorerAgent } from '@lytics/dev-agent-subagents';
362+
import {
363+
SubagentCoordinator,
364+
ExplorerAgent,
365+
ContextManagerImpl
366+
} from '@lytics/dev-agent-subagents';
367+
import { RepositoryIndexer } from '@lytics/dev-agent-core';
361368

362-
const coordinator = new SubagentCoordinator();
363-
await coordinator.initialize({
369+
// 1. Initialize Repository Indexer
370+
const indexer = new RepositoryIndexer({
364371
repositoryPath: './my-repo',
365372
vectorStorePath: './.dev-agent/vectors',
366373
});
374+
await indexer.initialize();
375+
376+
// Index the repository
377+
await indexer.index({ force: false });
378+
379+
// 2. Create Coordinator
380+
const coordinator = new SubagentCoordinator({
381+
maxConcurrentTasks: 5,
382+
logLevel: 'info',
383+
healthCheckInterval: 60000, // Health checks every minute
384+
});
385+
386+
// 3. Share Indexer Context
387+
coordinator.getContextManager().setIndexer(indexer);
388+
389+
// 4. Register Explorer Agent
390+
const explorer = new ExplorerAgent();
391+
await coordinator.registerAgent(explorer);
367392

368-
// Register Explorer
369-
coordinator.registerAgent(new ExplorerAgent());
393+
// 5. Start Coordinator
394+
coordinator.start();
370395

371-
// Send exploration request via coordinator
396+
// 6. Send Exploration Requests via Coordinator
372397
const response = await coordinator.sendMessage({
373-
id: 'explore-1',
374398
type: 'request',
375-
sender: 'user',
399+
sender: 'app',
376400
recipient: 'explorer',
377401
payload: {
378402
action: 'pattern',
379-
query: 'authentication',
403+
query: 'authentication logic',
404+
limit: 10,
380405
},
381-
timestamp: Date.now(),
406+
});
407+
408+
console.log(response?.payload);
409+
410+
// 7. Or Submit Tasks for Async Execution
411+
const taskId = coordinator.submitTask({
412+
type: 'exploration',
413+
agentName: 'explorer',
414+
payload: {
415+
action: 'similar',
416+
filePath: 'src/auth/login.ts',
417+
},
418+
priority: 8, // Higher priority
419+
});
420+
421+
// Check task status
422+
const task = coordinator.getTask(taskId);
423+
console.log('Task status:', task?.status);
424+
425+
// 8. Monitor Health
426+
setInterval(async () => {
427+
const stats = coordinator.getStats();
428+
console.log('Coordinator stats:', stats);
429+
430+
const healthy = await explorer.healthCheck();
431+
console.log('Explorer healthy:', healthy);
432+
}, 30000);
433+
434+
// 9. Graceful Shutdown
435+
process.on('SIGINT', async () => {
436+
await coordinator.stop();
437+
await indexer.close();
438+
process.exit(0);
382439
});
383440
```
384441

442+
### Benefits of Coordinator Integration
443+
444+
**Shared Context** - Indexer and other resources shared across agents
445+
**Task Queue** - Async execution with priority and retries
446+
**Health Monitoring** - Automated health checks
447+
**Error Handling** - Centralized error responses
448+
**Message Routing** - Automatic routing to correct agents
449+
**Statistics** - Track message counts, response times, task status
450+
451+
### Task-Based Exploration
452+
453+
Submit exploration tasks for async execution:
454+
455+
```typescript
456+
// Pattern search task
457+
const taskId1 = coordinator.submitTask({
458+
type: 'pattern-search',
459+
agentName: 'explorer',
460+
payload: {
461+
action: 'pattern',
462+
query: 'error handling',
463+
},
464+
priority: 10, // High priority
465+
maxRetries: 3, // Retry on failure
466+
});
467+
468+
// Similar code task
469+
const taskId2 = coordinator.submitTask({
470+
type: 'similar-code',
471+
agentName: 'explorer',
472+
payload: {
473+
action: 'similar',
474+
filePath: 'src/handlers/api.ts',
475+
},
476+
priority: 5,
477+
});
478+
479+
// Check task completion
480+
const task = coordinator.getTask(taskId1);
481+
if (task?.status === 'completed') {
482+
console.log('Results:', task.result);
483+
}
484+
```
485+
486+
### Coordinator Statistics
487+
488+
Monitor system health and performance:
489+
490+
```typescript
491+
const stats = coordinator.getStats();
492+
493+
console.log({
494+
agentCount: stats.agentCount, // Number of registered agents
495+
messagesSent: stats.messagesSent, // Total messages sent
496+
messagesReceived: stats.messagesReceived,
497+
messageErrors: stats.messageErrors,
498+
tasksCompleted: stats.tasksCompleted,
499+
tasksFailed: stats.tasksFailed,
500+
avgResponseTime: stats.avgResponseTime, // In milliseconds
501+
uptime: stats.uptime, // In milliseconds
502+
});
503+
```
504+
505+
### Multi-Agent Coordination
506+
507+
Explorer works with other agents:
508+
509+
```typescript
510+
// Register multiple agents
511+
await coordinator.registerAgent(new ExplorerAgent());
512+
await coordinator.registerAgent(new PlannerAgent());
513+
await coordinator.registerAgent(new PrAgent());
514+
515+
// Explorer can send messages to other agents
516+
const response = await coordinator.sendMessage({
517+
type: 'request',
518+
sender: 'explorer',
519+
recipient: 'planner',
520+
payload: {
521+
action: 'analyze',
522+
codePatterns: explorerResults,
523+
},
524+
});
525+
```
526+
527+
### Coordinator Health Checks
528+
529+
The coordinator automatically performs health checks:
530+
531+
```typescript
532+
const coordinator = new SubagentCoordinator({
533+
healthCheckInterval: 60000, // Check every minute
534+
});
535+
536+
// Health checks run automatically
537+
// Logs warnings if agents become unhealthy
538+
539+
// Manual health check
540+
const healthy = await explorer.healthCheck();
541+
```
542+
543+
### Integration Tests
544+
545+
The Coordinator→Explorer integration is fully tested:
546+
547+
```bash
548+
# Run integration tests
549+
pnpm test packages/subagents/src/coordinator/coordinator.integration.test.ts
550+
```
551+
552+
**Test Coverage:**
553+
- ✅ Agent registration and initialization
554+
- ✅ Message routing (pattern, similar, relationships, insights)
555+
- ✅ Task execution via task queue
556+
- ✅ Health checks and monitoring
557+
- ✅ Context sharing (indexer access)
558+
- ✅ Error handling and edge cases
559+
- ✅ Graceful shutdown
560+
385561
## Error Handling
386562

387563
The Explorer returns error responses for invalid requests:

0 commit comments

Comments
 (0)