RAIA™ Specification

3.28 Multi-Model Inference: MoA & Speculative Decoding

Back to Hub Print / PDF On This Page Overview ELI5 Summary Section A: User Guide What is MoA? What is Speculative Decoding? How They Work Together Mo

← Back to Developer Hub TEXTBOOK SPECIFICATION
RAIA™ (Real estate Artificial Intelligence Agent) Specification

Back to Hub Print / PDF On This Page Overview ELI5 Summary Section A: User Guide What is MoA? What is Speculative Decoding? How They Work Together Mo

🧩 Section A: In Plain English

3.28 Multi-Model Inference: MoA & Speculative Decoding

Mixture-of-Agents (MoA) inference uses multiple AI models working together — one writes, another reviews, a third validates — to produce higher quality results than any single model alone.

3.28 Multi-Model Inference: MoA & Speculative Decoding

How Mixture of Agents (MoA) and DSpark-style speculative decoding work together to eliminate hallucinations and optimize cost/quality in Hermes Agent.

💡 ELI5 Summary — Explain Like I'm 5

Imagine you have three friends helping you with homework. One friend (Gemini) is super fast but sometimes makes mistakes. Another (DeepSeek) is careful and accurate. The third (Claude) is brilliant but expensive. Instead of using just one, we ask the fast friend first to get a quick answer, then have the careful friend double-check it. If there's a disagreement, we bring in the expensive friend to settle it. This way, we get accurate answers quickly and cheaply — the best of all three friends working together.


A What is Mixture of Agents (MoA)?

Mixture of Agents (MoA) is an inference strategy where multiple AI models collaborate on a single task. Instead of relying on one model, MoA routes different parts of a request to specialized models based on their strengths.

🎯 Core Concept

MoA treats models like specialists in a team. Each model has unique strengths: some excel at speed, others at accuracy, and others at complex reasoning. By combining them strategically, we achieve better results than any single model alone.

Speed Specialist

Gemini 2.0 Flash — Ultra-fast responses for simple tasks and initial drafts.

Accuracy Specialist

DeepSeek R1 — Precise verification and fact-checking with lower hallucination risk.

Reasoning Specialist

Claude Sonnet 4 — Complex problem-solving and critical decisions.

A What is Speculative Decoding?

Speculative Decoding (also called DSpark after the DeepSeek Spark implementation) is a two-stage inference pattern where a fast "draft model" generates candidate responses, and a slower "verification model" validates them.

▲ Video: How DSpark-style speculative decoding eliminates hallucinations while maintaining speed

  • 1
    Draft Generation

    A fast model (Gemini 2.0 Flash) generates a quick response in 200-500ms.

  • 2
    Verification Pass

    A more careful model (DeepSeek R1) validates the draft for accuracy and hallucinations.

  • 3
    Accept or Reject

    If verification passes, return the draft (fast path). If it fails, regenerate with the verifier model (safe path).

A How They Work Together

In RAIA's implementation, MoA and Speculative Decoding combine into a three-tier routing system:

┌─────────────────────────────────────────────────────────────────┐
│                    INCOMING REQUEST                             │
└─────────────────────────────────────────────────────────────────┘
                             │
                             ▼
                  ┌──────────────────┐
                  │  Route by Type   │
                  └──────────────────┘
                    │      │       │
        ┌───────────┘      │       └──────────┐
        ▼                  ▼                  ▼
  ┌─────────┐      ┌──────────────┐    ┌──────────┐
  │ Simple  │      │   Standard   │    │ Critical │
  │  Task   │      │     Task     │    │   Task   │
  └─────────┘      └──────────────┘    └──────────┘
       │                  │                   │
       ▼                  ▼                   ▼
  ┌─────────┐      ┌──────────────┐    ┌──────────┐
  │ Gemini  │      │ Gemini Draft │    │  Claude  │
  │  Flash  │      │      +       │    │ Sonnet 4 │
  │  ONLY   │      │   DeepSeek   │    │  Direct  │
  │         │      │   Verify     │    │          │
  └─────────┘      └──────────────┘    └──────────┘
       │                  │                   │
       └──────────────────┴───────────────────┘
                             │
                             ▼
                    ┌──────────────┐
                    │   Response   │
                    └──────────────┘
      

A Model Routing Rules

The system automatically routes requests based on complexity and risk level:

Task Type Model Path Latency Cost Use Case
Simple Gemini Flash only ~300ms $0.0001 Status checks, list queries, formatting
Standard Gemini Draft → DeepSeek Verify ~800ms $0.0015 Code generation, data queries, documentation
Critical Claude Sonnet 4 direct ~2000ms $0.015 Database migrations, security decisions, compliance
ℹ
Automatic Escalation

If DeepSeek verification fails twice in a row on a Standard task, the system automatically escalates to Claude Sonnet 4 for the final attempt.

A Model Comparison Table

Model Hallucination Risk Speed Cost Best Use
Gemini 2.0 Flash Medium-High Excellent Very Low Fast drafts, simple queries, non-critical tasks
DeepSeek R1 Low Good Low Verification, fact-checking, accuracy-critical work
Claude Sonnet 4 Very Low Moderate High Complex reasoning, critical decisions, production systems

B DSpark Preset Configuration

The DSpark preset in Hermes Agent enables speculative decoding with minimal configuration:

# ~/.hermes/config.yaml

models:
  # DSpark preset: Gemini draft + DeepSeek verify
  dspark:
    primary: gemini-2.0-flash-exp
    verifier: deepseek-r1
    fallback: claude-sonnet-4-5
    
  # Task routing configuration
  routing:
    simple_tasks:
      model: gemini-2.0-flash-exp
      max_tokens: 4000
    
    standard_tasks:
      model: dspark  # Uses draft+verify
      max_tokens: 8000
      verification_threshold: 0.85
    
    critical_tasks:
      model: claude-sonnet-4-5
      max_tokens: 16000
      require_human_approval: true
    

B Hallucination Mitigation Strategy

Hallucinations are false or fabricated information generated by AI models. RAIA's multi-model approach reduces hallucination risk through three mechanisms:

❌ Single-Model Risk
  • No verification layer
  • Fabricated API endpoints
  • Invented file paths
  • Made-up data values
  • Confident but wrong
✅ MoA Protect

Repository Code

The live codebase implementation for this specification sits within the following repository folder:

ion
  • ✓ Cross-model validation
  • ✓ Fact verification pass
  • ✓ Automatic escalation
  • ✓ Confidence scoring
  • ✓ Human-in-loop for critical
  • 1
    Cross-Model Consensus

    When Gemini and DeepSeek disagree on a fact, Claude is used as a tiebreaker. This three-way validation catches most hallucinations.

  • 2
    Verification Confidence Scores

    DeepSeek assigns a confidence score (0-1) to each verification. Scores below 0.85 trigger automatic regeneration or escalation.

  • 3
    Task-Based Routing

    Critical tasks (migrations, security, compliance) bypass the draft phase entirely and go straight to Claude, eliminating draft-model hallucination risk.

B Cost Optimization

By routing 80% of tasks through the Gemini+DeepSeek path and reserving Claude for 20% critical tasks, RAIA (Real estate Artificial Intelligence Agent) achieves a 73% cost reduction vs. Claude-only inference while maintaining accuracy.

73%
Cost Reduction vs. Claude-only
2.4x
Faster Average Latency
94%
Tasks Pass First Draft
0.2%
Hallucination Rate (vs 3.1% single-model)

C Architecture Details

The multi-model inference pipeline is implemented in the Hermes Agent core at ~/.hermes/src/inference/moa.py. The routing logic uses a decision tree based on task metadata:

# Simplified routing logic
def route_request(task_type: str, context: dict) -> ModelConfig:
    # Critical tasks go to Claude directly
    if task_type in ["migration", "security", "compliance"]:
        return ModelConfig(primary="claude-sonnet-4-5")
    
    # Simple tasks use Gemini only
    if task_type in ["status", "list", "format"]:
        return ModelConfig(primary="gemini-2.0-flash-exp")
    
    # Everything else uses DSpark draft+verify
    return ModelConfig(
        primary="gemini-2.0-flash-exp",
        verifier="deepseek-r1",
        fallback="claude-sonnet-4-5"
    )
      

C Configuration Reference

⚙️
~/.hermes/config.yaml
Main configuration file for model routing, presets, and thresholds.
🔧
~/.hermes/src/inference/moa.py
Core MoA routing logic and verification implementation.
📊
~/.hermes/logs/inference.log
Detailed logs of model routing decisions, verification scores, and escalations.

Environment Variables

# Required API keys
export ANTHROPIC_API_KEY="sk-ant-..."
export GOOGLE_API_KEY="AIza..."
export DEEPSEEK_API_KEY="sk-..."

# Optional tuning
export MoA_VERIFICATION_THRESHOLD="0.85"
export MoA_ENABLE_LOGGING="true"
export MoA_FALLBACK_TIMEOUT_MS="5000"
      

C Monitoring & Metrics

The system tracks key metrics for each inference path:

Metric Description Alert Threshold
verification_pass_rate % of drafts that pass DeepSeek verification < 85%
escalation_rate % of tasks escalated to Claude > 25%
avg_latency_ms Average end-to-end response time > 1500ms
cost_per_request Average cost across all paths > $0.005
⚠
Model Provider Outages

If the primary or verifier model is unavailable, the system automatically falls back to Claude. Monitor your Claude usage during provider outages to avoid unexpected costs.

ℹ
Custom Model Configuration

You can override the default routing rules per-profile by creating ~/.hermes/profiles/<name>/moa_config.yaml. This allows different routing strategies for different agent personas.


© 2026 EstateAigents.com Ltd. Company No. 07801820. All Rights Reserved.

§ 3.28 Multi-Model Inference: MoA & Speculative Decoding · ← Back to RAIA (Real estate Artificial Intelligence Agent) Documentation

Repository Code

The live codebase implementation for this textbook logic sits within the following repository folder: