---
issue: 134
title: Python Bot Type Hints (Tavus Tool Forwarder)
analyzed: 2025-10-13T19:18:58Z
estimated_hours: 4
parallelization_factor: 2.5
---

# Parallel Work Analysis: Issue #134

## Overview

Add complete type hints to the Tavus tool forwarder bot Python codebase (5 modules), configure mypy for type checking, and ensure 100% type coverage. Similar to issue #133, this is a clean parallelization opportunity since each module can be typed independently with minimal overlap.

## Parallel Streams

### Stream A: Main Bot Module + Environment Setup
**Scope**: Setup environment and type the main bot orchestration module
**Files**:
- `apps/slide-system/bots/tavus-tool-forwarder/pyproject.toml` (create)
- `apps/slide-system/bots/tavus-tool-forwarder/bot.py` (main bot logic)
**Agent Type**: general-purpose
**Can Start**: immediately
**Estimated Hours**: 2h
**Dependencies**: none

**Rationale**: bot.py is the largest file (~635 lines) with the main orchestration logic. Typing this first establishes the interfaces. Environment setup (pyproject.toml, mypy config) is a prerequisite for validation.

### Stream B: API Client & Parser Modules
**Scope**: Type the Railway API client and tool call parser
**Files**:
- `apps/slide-system/bots/tavus-tool-forwarder/railway_client.py` (~380 lines)
- `apps/slide-system/bots/tavus-tool-forwarder/tool_call_parser.py` (~289 lines)
**Agent Type**: general-purpose
**Can Start**: immediately
**Estimated Hours**: 1.5h
**Dependencies**: none

**Rationale**: These modules are standalone with clear interfaces. railway_client uses aiohttp types, tool_call_parser uses dataclasses and json. Both are independent of bot.py.

### Stream C: Test Files & Final Validation
**Scope**: Type test files and run final mypy validation
**Files**:
- `apps/slide-system/bots/tavus-tool-forwarder/test_bot_local.py`
- `apps/slide-system/bots/tavus-tool-forwarder/manual_test.py`
**Agent Type**: general-purpose
**Can Start**: after Stream A completes
**Estimated Hours**: 0.5h
**Dependencies**: Stream A (needs bot types)

**Rationale**: Test files depend on the TavusToolForwarderBot type from bot.py. This stream also runs final mypy validation across all modules.

## Coordination Points

### Shared Files
Minimal overlap:
- `.gitignore` - Stream A adds `.venv/` (one-time, low conflict risk)
- `pyproject.toml` - Stream A creates this file

### Sequential Requirements
1. Stream A must complete before Stream C (test files need TavusToolForwarderBot type)
2. All streams must complete before final mypy validation in Stream C

### Type Import Patterns
Common imports all streams will use:
```python
from typing import Dict, Optional, Any, List, Tuple
from typing import Callable, Awaitable, Coroutine
```

## Conflict Risk Assessment

- **Low Risk**: Each stream works on different files
- **No shared core files** being modified simultaneously
- **Clear module boundaries** prevent interface conflicts
- **Well-typed dependencies** (Daily SDK, aiohttp, Supabase, dataclasses)

## Parallelization Strategy

**Recommended Approach**: hybrid

**Execution Plan**:
1. Launch Streams A, B simultaneously (2 parallel agents)
2. Start Stream C when A completes
3. Stream C performs final validation and testing

**Why hybrid?**
- Streams A and B are fully independent
- Stream C depends on A for TavusToolForwarderBot type
- Maximizes parallelization while respecting dependencies

## Expected Timeline

**With parallel execution**:
- Wall time: 2h (max of Stream A) + 0.5h (Stream C) = **2.5h total**
- Total work: 4h
- Efficiency gain: **37.5% faster** than sequential

**Without parallel execution**:
- Wall time: 2h + 1.5h + 0.5h = **4h total**

**Parallelization factor**: 1.6x speedup

## Type Hint Patterns

### Module-level Type Definitions
Each stream should follow these patterns:

**Async functions:**
```python
async def start_supabase(self) -> None:
    """Initialize Supabase client."""
    ...

async def generate_deck(
    self,
    company_name: Optional[str] = None,
    pain_points: List[str] = None
) -> DeckGenerationResponse:
    """Generate deck via API."""
    ...
```

**Event handlers (Daily SDK):**
```python
def on_app_message(self, message: Dict[str, Any], sender: str) -> None:
    """Handle app-message events."""
    ...

def on_joined(self, data: Dict[str, Any], error: Optional[str]) -> None:
    """Called when bot joins room."""
    ...
```

**Dataclasses:**
```python
from dataclasses import dataclass

@dataclass
class DeckGenerationResponse:
    """Response from /api/slidev/generate"""
    deck_id: str
    deck_url: str
    session_id: Optional[str] = None
    raw_response: Optional[Dict[str, Any]] = None
```

**Class attributes:**
```python
class TavusToolForwarderBot(EventHandler):
    def __init__(
        self,
        room_url: str,
        bot_id: str,
        session_id: Optional[str] = None
    ):
        self.room_url: str = room_url
        self.bot_id: str = bot_id
        self.client: Optional[CallClient] = None
        self.is_running: bool = False
```

## Mypy Configuration

Stream A will create `pyproject.toml` (reuse config from screenshare bot):

```toml
[tool.mypy]
python_version = "3.11"
warn_return_any = true
warn_unused_configs = true
disallow_untyped_defs = true
ignore_missing_imports = false
show_error_codes = true
strict_optional = true
check_untyped_defs = true

# Per-module overrides for untyped third-party libraries
[[tool.mypy.overrides]]
module = "daily.*"
ignore_missing_imports = true

[[tool.mypy.overrides]]
module = "supabase.*"
ignore_missing_imports = true

[[tool.mypy.overrides]]
module = "dotenv"
ignore_missing_imports = true
```

## Testing Strategy

Each stream should:
1. Add type hints to all functions
2. Run `mypy <file>.py` locally to check for errors
3. Fix any type errors iteratively
4. Ensure existing functionality is unchanged

Stream C performs final validation:
```bash
cd apps/slide-system/bots/tavus-tool-forwarder
source .venv/bin/activate
mypy bot.py railway_client.py tool_call_parser.py \
     test_bot_local.py manual_test.py
```

Expected output: `Success: no issues found in 5 source files`

## Notes

- **Dependencies are well-typed**: aiohttp and dataclasses have excellent type support
- **Daily SDK may need type stubs**: Use `ignore_missing_imports` for daily.* modules
- **Supabase client**: May need `ignore_missing_imports` override
- **Test files**: Can be typed opportunistically within each stream
- **Performance**: Type hints have zero runtime cost in Python
- **Backwards compatibility**: Type hints are optional - adding them doesn't break existing code
- **Documentation benefit**: Type hints serve as inline documentation

## File Size Comparison

| File | Lines | Complexity | Estimated Time |
|------|-------|------------|----------------|
| bot.py | ~635 | High (event handlers, async) | 2h |
| railway_client.py | ~380 | Medium (HTTP client, retry logic) | 1h |
| tool_call_parser.py | ~289 | Low (dataclasses, parsing) | 0.5h |
| test_bot_local.py | ~150 | Low (test file) | 0.25h |
| manual_test.py | ~200 | Low (test file) | 0.25h |

**Total**: 5 files, ~1654 lines, 4 hours estimated
