Implements FED-010: Agent Spawn via Federation feature that enables spawning and managing Claude agents on remote federated Mosaic Stack instances via COMMAND message type. Features: - Federation agent command types (spawn, status, kill) - FederationAgentService for handling agent operations - Integration with orchestrator's agent spawner/lifecycle services - API endpoints for spawning, querying status, and killing agents - Full command routing through federation COMMAND infrastructure - Comprehensive test coverage (12/12 tests passing) Architecture: - Hub → Spoke: Spawn agents on remote instances - Command flow: FederationController → FederationAgentService → CommandService → Remote Orchestrator - Response handling: Remote orchestrator returns agent status/results - Security: Connection validation, signature verification Files created: - apps/api/src/federation/types/federation-agent.types.ts - apps/api/src/federation/federation-agent.service.ts - apps/api/src/federation/federation-agent.service.spec.ts Files modified: - apps/api/src/federation/command.service.ts (agent command routing) - apps/api/src/federation/federation.controller.ts (agent endpoints) - apps/api/src/federation/federation.module.ts (service registration) - apps/orchestrator/src/api/agents/agents.controller.ts (status endpoint) - apps/orchestrator/src/api/agents/agents.module.ts (lifecycle integration) Testing: - 12/12 tests passing for FederationAgentService - All command service tests passing - TypeScript compilation successful - Linting passed Refs #93 Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2.7 KiB
2.7 KiB
ORCH-115: Task dispatch from coordinator
Objective
Implement orchestrator API endpoint POST /agents/spawn to receive spawn requests from coordinator, queue tasks in Valkey, and spawn agents.
Acceptance Criteria
- Orchestrator API endpoint: POST /agents/spawn
- Coordinator calls orchestrator after quality pre-check
- Task queued in Valkey
- Agent spawned
- Return agentId to coordinator
Approach
- Create NestJS controller:
src/api/agents/agents.controller.ts - Create DTO for spawn request validation
- Integrate with QueueService (ORCH-108) and AgentSpawnerService (ORCH-105)
- Write comprehensive unit tests following TDD
- Create module and register in AppModule
API Specification
POST /agents/spawn
Request: {
taskId: string,
agentType: 'worker' | 'reviewer' | 'tester',
context: {
repository: string,
branch: string,
workItems: string[],
skills?: string[]
}
}
Response: {
agentId: string,
status: 'spawning' | 'queued'
}
Progress
- Write controller tests (RED)
- Implement controller (GREEN)
- Refactor if needed
- Create module
- Register in AppModule
- Integration test
- Add class-validator and class-transformer dependencies
- All tests passing (14/14)
- Test coverage 100%
Testing Strategy
- Mock QueueService.addTask()
- Mock AgentSpawnerService.spawnAgent()
- Test success scenarios
- Test validation errors (missing fields, invalid types)
- Test service integration errors
- Ensure coverage >= 85%
Notes
- Following existing patterns from health.controller.ts
- Using NestJS dependency injection
- DTOs will validate request payload
- Return agentId from spawner service
- Queue status reflects whether agent is spawning or queued
Implementation Summary
Files Created:
src/api/agents/agents.controller.ts- Main controller with POST /agents/spawn endpointsrc/api/agents/agents.controller.spec.ts- Comprehensive unit tests (14 tests, 100% coverage)src/api/agents/dto/spawn-agent.dto.ts- Request/response DTOs with validationsrc/api/agents/agents.module.ts- NestJS module
Files Modified:
src/app.module.ts- Added AgentsModule importpackage.json- Added class-validator and class-transformer dependencies
Test Results:
- All 238 tests passing
- Controller tests: 14/14 passing
- Coverage: 100% (statements, branches, functions, lines)
Key Features:
- Spawns agents using AgentSpawnerService
- Queues tasks using QueueService with default priority of 5
- Validates request payload (taskId, agentType, context)
- Supports all agent types: worker, reviewer, tester
- Proper error handling and propagation
- Returns agentId and status to coordinator