feat: Major performance optimizations and feature enhancements

## Performance Optimizations (3-10x faster responses)
- STT beam_size reduced to 1 (3-5x faster transcription, minimal quality loss)
- Smart query routing: Haiku (simple) → Sonnet (medium) → Opus (complex)
- TTS cache for common phrases (27 pre-generated responses)
- Sentence-level streaming TTS (start playing while generating)
- Sample-based VAD timing (30x improvement in silence detection)

## TTS Engine Upgrade
- Migrated from Chatterbox to Chatterbox-Turbo
- Zero-shot voice cloning (no fine-tuning required)
- Native paralinguistic tag support ([laugh], [sigh], [chuckle], etc.)
- Emotion presets with temperature control
- Improved marker conversion (*action*, (action), ~action~)

## Discord Bot Enhancements
- Multi-agent support (Jarvis, Sage)
- Improved voice receiving with discord-ext-voice-recv
- Enhanced /join, /leave, /status commands
- Per-agent personality configuration
- Better audio sink/receiver implementation

## OpenClaw Integration
- WebSocket support for Gateway communication
- Query complexity routing (auto-select model)
- Improved error handling and retries
- Session management per Discord guild
- Better latency tracking

## Pipeline Improvements
- Sentence splitter for streaming optimization
- Query router for intelligent model selection
- Enhanced VAD receiver with sample-based timing
- Improved audio buffering and format conversion
- Better transcript management

## Documentation
- Added QUICK_START.md (5-minute test guide)
- Added OPTIMIZATION_SUMMARY.md (performance analysis)
- Added DISCORD_OPTIMIZATION_TEST.md (testing guide)
- Added USAGE_GUIDE.md (comprehensive usage)
- Updated README.md with optimization details

## Utilities & Scripts
- Added get_invite_link.py (Discord bot invite)
- Added sync_commands.py, sync_to_guild.py (command sync)
- Added test_gateway.py, test_stt.py (testing utilities)
- Added openclaw_wrapper.py (wrapper script)
- Removed create_mock_turn_model.py (no longer needed)

## Configuration Updates
- STT model: medium → small (faster, acceptable quality)
- TTS engine: chatterbox → coqui (Turbo integration)
- Beam size: 5 → 1 (latency optimization)
- Added emotion_exaggeration per agent
- Updated .gitignore for project files

Total: ~2105 insertions, ~462 deletions across 35 files
Performance: ~5.5s total latency (down from 22-35s)
Target: ~3.5s (achieved in simple queries with cache)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
MCKRUZ 2026-02-16 19:29:57 -05:00
parent f1d884bb6a
commit 9fde3d31ba
36 changed files with 6050 additions and 471 deletions

76
openclaw_wrapper.py Normal file
View file

@ -0,0 +1,76 @@
"""OpenClaw Gateway LLM client wrapper.
Provides a simple callable interface for the pipeline orchestrator.
"""
from typing import Optional
from openclaw_client import OpenClawConfig, PerGuildOpenClawClient
from utils.logging import get_logger
logger = get_logger(__name__)
class OpenClawLLMWrapper:
"""
Wraps OpenClaw Gateway client for pipeline orchestrator.
Provides a callable interface that matches the orchestrator's expectations:
async def llm_client(agent: str, message: str, context: str, speaker: str) -> str
"""
def __init__(self, config: OpenClawConfig, guild_id: int):
"""
Initialize wrapper.
Args:
config: OpenClaw configuration
guild_id: Discord guild ID
"""
self.config = config
self.guild_id = guild_id
self.client_manager = PerGuildOpenClawClient(config)
async def __call__(
self,
agent: str,
message: str,
context: str,
speaker: str,
) -> str:
"""
Send message to OpenClaw Gateway and get response.
Args:
agent: Agent name (jarvis, sage, etc.)
message: User's message text
context: Conversation context (managed by Gateway, not used)
speaker: Speaker identifier (user ID or name)
Returns:
Agent's response text
"""
# Get or create client for this guild
client = self.client_manager.get_or_create(self.guild_id)
# Send message to Gateway
# Note: context is ignored because Gateway manages it internally
response = await client.send_message(
agent=agent,
message=message,
context="", # Gateway manages context
speaker=speaker,
)
return response
async def disconnect(self):
"""Disconnect the OpenClaw client."""
client = self.client_manager.get_or_create(self.guild_id)
await client.disconnect()
self.client_manager.remove_guild(self.guild_id)
def get_stats(self) -> dict:
"""Get client statistics."""
client = self.client_manager.get_or_create(self.guild_id)
return client.get_stats()