---
issue: 148
title: Implement 3-Participant Coordination
analyzed: 2025-10-15T21:22:22Z
estimated_hours: 24
parallelization_factor: 2.0
---

# Parallel Work Analysis: Issue #148

## Overview
Implement real-time slide control coordination between 3 participants in a LiveKit room:
1. Customer (viewer) - receives audio & video
2. Voice agent (audio) - controls conversation and slides
3. Screenshare bot (video) - displays slides based on commands

The voice agent sends slide navigation commands via Supabase realtime, which the screenshare bot listens for and executes.

## Parallel Streams

### Stream A: Voice Agent Tool Implementation
**Scope**: Add slide navigation tool functions to voice agent
**Files**:
- `apps/voice-agent-livekit/src/voice_agent_livekit/tools/slide_control.py`
- `apps/voice-agent-livekit/src/voice_agent_livekit/tools/__init__.py`
- `apps/voice-agent-livekit/src/voice_agent_livekit/agent.py` (register tools)
- `apps/voice-agent-livekit/src/voice_agent_livekit/conversation.py` (track slide context)
**Agent Type**: backend-specialist (Python)
**Can Start**: immediately
**Estimated Hours**: 10
**Dependencies**: none

**Tasks**:
- Implement `navigate_slide(direction, slide_number)` tool function
- Send commands to Supabase realtime channel `slide_control:{deckId}`
- Handle confirmation responses
- Maintain current slide context in conversation state
- Add error handling for failed commands

### Stream B: Screenshare Bot Subscription
**Scope**: Add Supabase realtime subscription to screenshare bot
**Files**:
- `apps/slide-system/bots/screenshare-bot/transports/livekit_transport.py`
- `apps/slide-system/bots/screenshare-bot/bot.py`
- `apps/slide-system/bots/screenshare-bot/pyproject.toml` (add supabase-py if needed)
**Agent Type**: backend-specialist (Python)
**Can Start**: immediately
**Estimated Hours**: 8
**Dependencies**: none

**Tasks**:
- Subscribe to Supabase realtime channel `slide_control:{deckId}`
- Handle slide navigation commands (next, previous, goto)
- Execute slide changes in Slidev iframe
- Send confirmation responses back to channel
- Add latency logging (<500ms target)

### Stream C: Integration Testing
**Scope**: End-to-end testing with all 3 participants
**Files**:
- `apps/voice-agent-livekit/tests/test_slide_coordination.py` (new)
- `apps/slide-system/bots/screenshare-bot/tests/test_realtime_commands.py` (new)
- Integration test scripts
**Agent Type**: backend-specialist (Python)
**Can Start**: after Streams A & B complete
**Estimated Hours**: 6
**Dependencies**: Streams A & B

**Tasks**:
- Unit tests for voice agent tool functions
- Unit tests for screenshare bot command handling
- Integration test: voice command → Supabase → screenshare → visual update
- Latency measurement tests
- 3-participant room coordination test
- Error scenario testing (disconnection, invalid commands)

## Coordination Points

### Shared Concepts
- **Supabase channel name format**: `slide_control:{deckId}` (must match exactly)
- **Command message format**: Must agree on JSON structure
  ```json
  {
    "type": "navigate",
    "direction": "next" | "previous" | "goto",
    "slide_number": 3,  // optional, for goto
    "timestamp": "2025-10-15T21:22:22Z",
    "session_id": "sess_123"
  }
  ```
- **Response format**: Confirmation messages
  ```json
  {
    "type": "confirmation",
    "success": true,
    "current_slide": 3,
    "total_slides": 10,
    "timestamp": "2025-10-15T21:22:22Z"
  }
  ```

### Shared Dependencies
- `apps/voice-agent-livekit/pyproject.toml` - Stream A (may add supabase-py)
- `apps/slide-system/bots/screenshare-bot/pyproject.toml` - Stream B (may add supabase-py)

### Sequential Requirements
1. Define message format **before** both streams implement
2. Both Streams A & B must complete **before** Stream C integration tests
3. Unit tests can run in parallel with implementation

## Conflict Risk Assessment
- **Low Risk**: Streams A & B work on completely separate codebases
- **No file conflicts**: Different directories, different projects
- **Only coordination needed**: Agree on Supabase channel name and message format

## Parallelization Strategy

**Recommended Approach**: hybrid

**Phase 1 (Parallel)**: Launch Streams A & B simultaneously
- Both teams can work independently after agreeing on message format
- No file conflicts between codebases
- Can each write unit tests in parallel

**Phase 2 (Sequential)**: Stream C after A & B complete
- Integration tests require both components working
- Can validate latency and full flow
- Fix any discovered issues

## Expected Timeline

With parallel execution:
- **Phase 1**: 10 hours (max of Stream A=10h, Stream B=8h)
- **Phase 2**: 6 hours (Stream C)
- **Total wall time**: 16 hours (~2 days)
- **Total work**: 24 hours
- **Efficiency gain**: 33%

Without parallel execution:
- Wall time: 24 hours (~3 days)

## Communication Protocol Agreement

**Critical first step** before streams start:

### 1. Supabase Channel Format
```
slide_control:{deckId}
```
Example: `slide_control:deck_abc123`

### 2. Command Messages (Voice Agent → Bot)
```typescript
{
  "type": "navigate",
  "direction": "next" | "previous" | "goto",
  "slide_number"?: number,  // required for goto
  "timestamp": string,      // ISO 8601
  "session_id": string
}
```

### 3. Confirmation Messages (Bot → Voice Agent)
```typescript
{
  "type": "confirmation",
  "success": boolean,
  "current_slide": number,
  "total_slides": number,
  "error"?: string,        // if success=false
  "timestamp": string,
  "session_id": string
}
```

## Notes

1. **Existing infrastructure**: Both tools already exist in skeleton form from previous work. Stream A extends `slide_control.py`, Stream B extends `livekit_transport.py`.

2. **Alternative approach**: Issue mentions LiveKit data channels as a future optimization. For now, Supabase realtime is the proven pattern used elsewhere in the system.

3. **Latency target**: <500ms from voice command to visual update. This includes:
   - Voice agent processing: ~50ms
   - Supabase realtime: ~100ms
   - Screenshare bot processing: ~50ms
   - Browser render: ~50ms
   - Slack budget: ~250ms

4. **Testing priority**:
   - Unit tests first (can run while implementing)
   - Integration tests second (validates full flow)
   - Performance tests third (measures latency)

5. **3-participant coordination**: The LiveKit room already handles this correctly from Issue #142. This issue focuses on the slide control messaging layer.
