Skip to main content

Custom Router Skill

End-to-end workflow: dataset → train → poll → infer. A custom router is an XGBoost classifier that learns which LLM model to route each request to, based on embeddings of the input text and training labels (correct_models) from your evaluation data.

Trigger

Activate when user says things like:
  • “train a router model”
  • “create a custom LLM router”
  • “run router training on my dataset”
  • “use my trained router for inference”
  • /custom-router

Prerequisites

Ask for these if not already provided:

Data Format

Training data must be a publicly accessible JSON file with a problems array. Each problem needs three fields:
Field rules:
  • problem_key — unique string identifier per problem
  • problem — the raw input text the router will learn to classify
  • correct_models — list of model strings that answered this problem correctly
  • Minimum 10 problems required; 100+ recommended for quality routing
Reference example: examples/sample_dataset.json (C++ coding problems with real model labels) Validation rules (from src/ml_tasks.py:138-141):
  • Problems missing any of problem_key, problem, or correct_models are silently filtered
  • Problems where no model is correct are dropped as “unsolvable”
  • Problems where only one model ever succeeds add limited signal — include diverse problems

Step 1 — Host the dataset


Step 2 — Submit training job

Request body: Response:

Step 3 — Poll status until complete

Status values: queuedrunningcompleted | failed Status response fields:

Step 4 — Get model details (optional)


Step 5 — Run inference

Once training completes and you have a model_id, route inputs through the trained router:
Inference request: Inference response:
Each prediction is the recommended model string for the corresponding input.

Complete end-to-end script

Usage:

Error handling


Reference examples

Pre-built example in examples/: