Skip to content

Repository files navigation

HybridRouter - Token-Efficient Routing Agent

Built for the AMD Developer Hackathon 2026 - Track 1: Hybrid Token-Efficient Routing Agent

An intelligent, multi-tier routing system designed to maximize task-solving accuracy while minimizing cloud API token costs. By leveraging local GPU resources for quick validation and classification, the system routes tasks dynamically across deterministic solvers, local hardware, and tiered cloud LLMs.


System Architecture

The router processes tasks through a 5-tier waterfall designed to maximize cost savings:

System Architecture

graph TD
    %% Define Styles
    classDef default fill:#141414,stroke:#f5f5f5,stroke-width:1px,color:#f5f5f5;
    classDef startNode fill:#f5f5f5,stroke:#f5f5f5,color:#0a0a0a;
    classDef solverNode fill:#00e676,stroke:#00e676,stroke-width:1px,color:#0a0a0a;
    classDef cloudNode fill:#ff5252,stroke:#ff5252,stroke-width:1px,color:#ffffff;
    
    A[Input Task Query]:::startNode --> B[Regex Heuristics Classifier]
    B --> C{T0: Deterministic Solvers}
    C -- "Solved (Free)" --> D[Return Output Answer]:::solverNode
    C -- "Unsolved" --> E[T1: Local LLM Gemma/Qwen]
    E --> F{Confidence Gate}
    F -- "High Confidence (Free)" --> D
    F -- "Low Confidence" --> G[T2: Fireworks Cheap Model Mixtral]
    G --> H{Validation Gate}
    H -- "Verified" --> D
    H -- "Uncertain" --> I[T3: Fireworks Strong Model Llama 70B]:::cloudNode
    I --> D
Loading

Dashboard Preview & Walkthrough

Here is a visual breakdown of the Control Center Dashboard and how it tracks operations:

1. Control Center Overview

Visualizes real-time metrics (Total processed tasks, Estimated Token Savings, Local Solver Rate, and P95 Pipeline Latency) computed directly from Firestore. Control Center Overview

2. Live Logs Explorer

Allows developers to monitor log entries as they sync from Firestore, paginated into pages of 5 items. Live Logs Explorer

3. Interactive Router Simulator

Lets you test prompts locally and witness how the orchestrator cascades each task through the routing waterfall. Interactive Router Simulator

4. Decision Distribution Analysis

Displays the live percentage breakdown of which tiers are solving tasks, helping tune model confidence thresholds. Decision Distribution Analysis

5. Multi-User Sync Dashboard

Real-time stats update instantly when other team members submit tasks from other clients. Multi-User Sync Dashboard


πŸ“Š Scoring Formula

The system is optimized around the official competition scoring logic:

$$\text{Score} = \text{Accuracy Score} - \text{Token Penalty}$$

  • Accuracy Score: Percentage of correct answers.
  • Token Penalty: Cost incurred through paid Fireworks cloud tokens.
  • Local & Solver Runs (Tier 0 & Tier 1): Incur zero token penalty, keeping your evaluation runs cheap and boosting the total leaderboard score.

βš™οΈ Environment Configuration

1. Root Orchestrator Backend Configuration (.env)

Create a .env file in the root directory:

# Fireworks API Configuration
FIREWORKS_API_KEY=fw_your_api_key_here
FIREWORKS_BASE_URL=https://api.fireworks.ai/inference/v1

# HuggingFace Configuration (For Local Model Download / Serverless API)
HF_TOKEN=hf_your_token_here
MODEL_NAME=google/gemma-3-12b-it
USE_HF_SERVERLESS=true

# Local Model Server Link
LOCAL_MODEL_URL=http://localhost:8000

# Tuning Thresholds
HIGH_CONFIDENCE_THRESHOLD=0.85
MEDIUM_CONFIDENCE_THRESHOLD=0.60

# Telemetry & Optimization
ENABLE_CACHE=true
ENABLE_DASHBOARD=false
LOG_LEVEL=info
LOG_DB_PATH=../../data/logs/tasks.db

2. React Dashboard Configuration (services/dashboard/.env)

Create a .env file in the services/dashboard/ directory:

# Gemini API Key for AI-Assist Smart Classifier
VITE_GEMINI_API_KEY=your-gemini-api-key-here

# Firebase Configuration (Google Auth + Firestore)
VITE_FIREBASE_API_KEY=your-firebase-api-key
VITE_FIREBASE_AUTH_DOMAIN=your-project.firebaseapp.com
VITE_FIREBASE_PROJECT_ID=your-project-id
VITE_FIREBASE_STORAGE_BUCKET=your-project.firebasestorage.app
VITE_FIREBASE_MESSAGING_SENDER_ID=your-sender-id
VITE_FIREBASE_APP_ID=your-app-id
VITE_FIREBASE_MEASUREMENT_ID=your-measurement-id

πŸš€ Quick Start Guide

Prerequisites

  • Docker & Docker Compose
  • AMD GPU with ROCm support (for local inference acceleration)
  • Fireworks AI API Key
  • Firebase Project Credentials

Run via Docker (Recommended)

  1. Clone the repository and navigate to the project directory:
    git clone <your-repo-url>
    cd HybridRouter
  2. Set up your environment variables following the Environment Configuration templates above.
  3. Boot up the entire multi-service container pipeline:
    docker compose up --build
  4. Access the React Dashboard at http://localhost:5173.

Local Development Setup

If running services individually:

  • Local Model Server (FastAPI):
    cd services/local-model-server
    pip install -r requirements.txt
    python main.py
  • Orchestrator Backend (Express):
    cd services/orchestrator
    npm install
    npm run dev
  • Frontend App (Vite):
    cd services/dashboard
    npm install
    npm run dev

πŸ“ Project Structure

HybridRouter/
β”œβ”€β”€ README.md                           # ← You are here
β”œβ”€β”€ AGENTS.md                           # Agent behavioral instructions
β”œβ”€β”€ .env.example                        # Environment variable template
β”œβ”€β”€ docker-compose.yml                  # Multi-service Docker setup
β”‚
β”œβ”€β”€ docs/                               # πŸ“š Technical documentation
β”‚   β”œβ”€β”€ README.md                       # Documentation index
β”‚   β”œβ”€β”€ Architecture.png                # Architecture flow visual
β”‚   β”œβ”€β”€ architecture.md                 # System architecture deep-dive
β”‚   β”œβ”€β”€ classifier.md                   # Task classifier documentation
β”‚   β”œβ”€β”€ tier0-deterministic-solvers.md  # Deterministic solver docs
β”‚   β”œβ”€β”€ tier1-local-model.md            # Local model server docs
β”‚   β”œβ”€β”€ tier2-tier3-fireworks.md        # Fireworks escalation docs
β”‚   └── API-reference.md                # API endpoints reference
β”‚
β”œβ”€β”€ services/                           # πŸ”§ Application services
β”‚   β”œβ”€β”€ orchestrator/                   # Node.js + Express orchestrator
β”‚   β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”‚   β”œβ”€β”€ classifier.js           # Heuristics classifier
β”‚   β”‚   β”‚   β”œβ”€β”€ router.js               # Waterfall router rules
β”‚   β”‚   β”‚   β”œβ”€β”€ solvers/
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ deterministic.js    # Math, regex, parsing solvers
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ localLlm.js         # Local model connector
β”‚   β”‚   β”‚   β”‚   └── fireworksClient.js  # Fireworks integration
β”‚   β”‚   β”‚   └── server.js               # Express API server
β”‚   β”‚   β”œβ”€β”€ main.js                     # Entry point (batch mode)
β”‚   β”‚   β”œβ”€β”€ package.json
β”‚   β”‚   └── Dockerfile
β”‚   β”‚
β”‚   β”œβ”€β”€ local-model-server/             # Python + FastAPI local server
β”‚   β”‚   β”œβ”€β”€ main.py                     # FastAPI entry point
β”‚   β”‚   β”œβ”€β”€ api/
β”‚   β”‚   β”‚   └── routes.py               # Inference paths
β”‚   β”‚   β”œβ”€β”€ requirements.txt
β”‚   β”‚   └── Dockerfile
β”‚   β”‚
β”‚   └── dashboard/                      # React + Vite frontend
β”‚       β”œβ”€β”€ src/
β”‚       β”‚   β”œβ”€β”€ components/
β”‚       β”‚   β”‚   β”œβ”€β”€ CustomCursor.jsx    # Fluid cursor component
β”‚       β”‚   β”‚   β”œβ”€β”€ MetricsCards.jsx    # Stats card boxes
β”‚       β”‚   β”‚   β”œβ”€β”€ Playground.jsx      # Input simulator form
β”‚       β”‚   β”‚   β”œβ”€β”€ DecisionDistribution.jsx # Distribution charts
β”‚       β”‚   β”‚   └── LiveLogs.jsx        # Paginated audit log datatable
β”‚       β”‚   β”œβ”€β”€ pages/
β”‚       β”‚   β”‚   β”œβ”€β”€ Home.jsx            # Portal landing page
β”‚       β”‚   β”‚   └── Console.jsx         # Live control center page
β”‚       β”‚   β”œβ”€β”€ App.jsx                 # Routes & global configurations
β”‚       β”‚   └── index.css               # Theme style rules
β”‚       β”œβ”€β”€ package.json
β”‚       └── Dockerfile

πŸ”— Project Resources

Β Β 


Built with 🧠 by Team TetraFourge for the AMD Developer Hackathon 2026
Maximize accuracy. Minimize tokens. Win.

About

Built for AMD Developer Hackathon ACT II. A token-efficient routing agent cascading tasks through local code solvers and Gemma models on AMD ROCm before escalating to Fireworks AI.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages