Thanks to visit codestin.com
Credit goes to github.com

Skip to content

meshag-ai/meshag

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

23 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

MeshAG - Distributed AI Agent Orchestrator

A high-performance, event-driven microservices architecture for orchestrating AI agents in real-time conversational applications with WebRTC transport and Valkey-based configuration management.

πŸš€ Overview

MeshAG is a distributed AI agent orchestrator that enables seamless coordination of multiple AI services using NATS JetStream for ultra-low latency message streaming, Valkey for configuration storage, and Daily.co for WebRTC transport. Each AI agent operates independently with pluggable connectors for different AI providers, creating a scalable and flexible conversational AI platform.

Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                           MeshAG Distributed AI Orchestrator                    β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   Client App    │────│ Transport Service │────│   Daily.co API   β”‚
β”‚                 β”‚    β”‚   (Port 8084)     β”‚    β”‚                  β”‚
β”‚ β€’ Web/Mobile    β”‚    β”‚ β€’ HTTP REST API   β”‚    β”‚ β€’ WebRTC Rooms   β”‚
β”‚ β€’ WebSocket     β”‚    β”‚ β€’ WebSocket       β”‚    β”‚ β€’ Meeting Tokens β”‚
β”‚ β€’ Daily.co SDK  β”‚    β”‚ β€’ Session Mgmt    β”‚    β”‚ β€’ Presence API   β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                β”‚
                                β”‚ HTTP POST /sessions/with-config
                                β”‚ (JSON Configuration)
                                β–Ό
                    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                    β”‚       Valkey          β”‚
                    β”‚   (Port 6379)         β”‚
                    β”‚ β€’ Config Storage      β”‚
                    β”‚ β€’ Session Management  β”‚
                    β”‚ β€’ TTL-based Cleanup   β”‚
                    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                β–²
                                β”‚ Config Retrieval
                                β”‚
                    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                    β”‚           NATS JetStream                β”‚
                    β”‚            (Port 4222)                  β”‚
                    β”‚         β€’ Event Streaming               β”‚
                    β”‚         β€’ Service Communication         β”‚
                    β”‚         β€’ Ultra-low Latency             β”‚
                    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                β–²
                                β”‚ Event Routing
                                β”‚
        β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
        β”‚                       β”‚                       β”‚
        β–Ό                       β–Ό                       β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”        β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”        β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ STT Service β”‚        β”‚ LLM Service β”‚        β”‚ TTS Service β”‚
β”‚ (Port 8081) β”‚        β”‚ (Port 8082) β”‚        β”‚ (Port 8083) β”‚
β”‚             β”‚        β”‚             β”‚        β”‚             β”‚
β”‚ β€’ OpenAI    β”‚        β”‚ β€’ OpenAI    β”‚        β”‚ β€’ ElevenLabsβ”‚
β”‚ β€’ Deepgram  β”‚        β”‚ β€’ Anthropic β”‚        β”‚ β€’ Azure     β”‚
β”‚ β€’ Self-routeβ”‚        β”‚ β€’ Self-routeβ”‚        β”‚ β€’ Self-routeβ”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜        β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜        β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
        β”‚                       β”‚                       β”‚
        β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                β”‚
                                β–Ό
                    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                    β”‚   Pipeline Flow       β”‚
                    β”‚                       β”‚
                    β”‚ transport β†’ stt       β”‚
                    β”‚ stt β†’ llm             β”‚
                    β”‚ llm β†’ tts             β”‚
                    β”‚ tts β†’ transport       β”‚
                    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸ—οΈ AI Agent Services

Service Port Purpose AI Providers Configuration
STT Service 8081 Speech-to-Text Deepgram Valkey + Self-routing
LLM Service 8082 Language Model OpenAI GPT Valkey + Self-routing
TTS Service 8083 Text-to-Speech ElevenLabs Valkey + Self-routing
Transport Service 8084 WebRTC Transport Twilio Valkey + Session Management

⚑ Key Features

  • Event-Driven Orchestration: NATS JetStream for ultra-high-performance agent coordination
  • Valkey Configuration Storage: Redis-compatible key-value store for dynamic configuration management (under dev)
  • Self-Routing Services: Each service determines its next consumer based on stored configuration
  • WebRTC Integration: Real-time audio/video communication via Daily.co
  • Pluggable AI Providers: Easy switching between AI providers (OpenAI, ElevenLabs, etc.)
  • Production Ready: Comprehensive health checks, metrics, and Docker containerization
  • Horizontally Scalable: Load balancing support for high-throughput applications
  • TTL-based Configuration: Automatic cleanup of expired session configurations

πŸš€ Quick Start

Prerequisites

  • Docker and Docker Compose
  • OpenAI API key
  • ElevenLabs API key
  • Deepgram API Key

1. Environment Setup

# Create environment file
cat > .env << EOF
OPENAI_API_KEY=your-openai-api-key-here
ELEVENLABS_API_KEY=your-elevenlabs-api-key-here
DEEPGRAM_API_KEY=your-deepgram-api-key-here
NATS_URL=nats://localhost:4222
VALKEY_URL=redis://localhost:6379
EOF

2. Start Services

make up

3. Setup Ngrok to hit port Transport servcie's port (8080/8084)

https://semiadhesive-stephane-uninchoative.ngrok-free.dev -> http://localhost:8080

4. Setup Twilio to hit endpoint /twilio

πŸ› οΈ Development

Local Development (Docker Required)

# Install Rust
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

make infra

# in seperate terminals
make t

# in seperate terminals
make s

# in seperate terminals
make l

# in seperate terminals
make tt

Adding New AI Providers

  1. Implement the connector trait (SttConnector, LlmConnector, or TtsConnector)
  2. Add to the appropriate provider module
  3. Register in the service's main.rs
  4. Update environment variables

Example:

// In crates/connectors/src/providers/newprovider.rs
pub struct NewProviderSttConnector { /* ... */ }

#[async_trait]
impl SttConnector for NewProviderSttConnector {
    // Implement required methods
}

// In services/stt-service/src/main.rs
if let Ok(api_key) = std::env::var("NEWPROVIDER_API_KEY") {
    let config = NewProviderConfig::new(api_key);
    let connector = NewProvider::stt_connector(config);
    stt_service.register_connector("newprovider", connector).await;
}

Service Ports

  • STT Service: 8081
  • LLM Service: 8082
  • TTS Service: 8083
  • Transport Service: 8084/8080
  • NATS: 4222 (client), 8222 (monitoring)
  • Valkey: 6379

🀝 Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Run cargo check --workspace
  5. Submit a pull request

Built with ❀️ using Rust by abskrj

About

Distributed Agents Orchestration

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages