Agentic RAG Router (question-only routers)

Two small PyTorch routers that read a question's intfloat/multilingual-e5-base embedding and choose one of five question-answering agents, ordered from cheapest to most expensive:

Agent Generator Strategy
A_direct_small Qwen2.5-1.5B-Instruct answer without retrieval
B_direct_large Qwen2.5-7B-Instruct answer without retrieval
C_rag_small Qwen2.5-1.5B-Instruct one retrieval (top 5), answer
D_rag_large Qwen2.5-7B-Instruct one retrieval (top 5), answer
E_iterative_large Qwen2.5-7B-Instruct up to 3 reason / retrieve steps

These weights are released so the paper's numbers can be checked, not as a recommended router. The paper's finding is negative: on the 300 test questions an oracle that picks the cheapest correct agent reaches 61.0% accuracy (the strongest agent alone: 45.7%), but question-only routers, including these, stay within 1.5 points of a fixed mix of agents at the same compute.

Files

File What it is
router_correctness.pt Predicts, for each agent, the probability that it answers correctly (5 sigmoids). Seed 4 of 5, lowest validation loss.
router_oracle.pt Predicts which agent is the cheapest correct one (softmax over 5). Seed 0 of 5, lowest validation loss.
router.py The network (DynamicNeuralRouter: sigmoid feature gate, then Linear 768β†’384, LayerNorm, GELU, Dropout, Linear 384β†’5). About 0.89 M parameters.
config.json Agent order, embedding model, training settings, the validation-chosen threshold Ο„*, the test metrics of each released seed, and the oracle-dataset manifest (models, sources, seeds, versions).

Each .pt file is a dictionary {"state_dict": ...} and loads with torch.load(..., weights_only=True).

Test results of the released seeds (300 questions)

Router Policy at Ο„* (chosen on validation) Accuracy Compute vs strongest agent
router_correctness cheapest agent with P(correct) β‰₯ 0.80, else E 45.3% 97%
router_oracle top agent (Ο„* = 0) 43.7% 72%
strongest agent E alone β€” 45.7% 100%
oracle (upper bound) β€” 61.0% 61%

Mean accuracy over the paper's shared compute range (15.6–17.6 TFLOPs per question), 5 seeds: correctness router 0.456 Β± 0.002, kNN (k = 15) 0.457, fixed mix of agents with no router 0.452. These numbers were reproduced exactly by the run that saved these files.

Use

import json, torch, torch.nn.functional as F
from huggingface_hub import hf_hub_download
from transformers import AutoTokenizer, AutoModel

repo = "MHkhan50/agentic-rag-router"
cfg = json.load(open(hf_hub_download(repo, "config.json")))
import importlib.util, sys
spec = importlib.util.spec_from_file_location("router", hf_hub_download(repo, "router.py"))
router_mod = importlib.util.module_from_spec(spec); spec.loader.exec_module(router_mod)

net = router_mod.DynamicNeuralRouter(cfg["d_model"], cfg["num_agents"], 384, 0.1, True)
net.load_state_dict(torch.load(hf_hub_download(repo, "router_correctness.pt"), weights_only=True)["state_dict"])
net.eval()

tok = AutoTokenizer.from_pretrained("intfloat/multilingual-e5-base")
enc = AutoModel.from_pretrained("intfloat/multilingual-e5-base").eval()
q = ["Who wrote the novel that the film Blade Runner is based on?"]
b = tok(["query: " + t for t in q], padding=True, truncation=True, return_tensors="pt")
with torch.no_grad():
    h = enc(**b).last_hidden_state
    m = b["attention_mask"].unsqueeze(-1).float()
    emb = F.normalize((h * m).sum(1) / m.sum(1), dim=-1)        # mean pooling, L2-normalised
    p_correct = torch.sigmoid(net(emb))[0]                     # correctness router: one sigmoid per agent

tau = cfg["routers"]["router_correctness"]["tau_star"]
ok = (p_correct >= tau).nonzero()
agent = cfg["agent_order"][int(ok[0]) if len(ok) else -1]      # cheapest agent with P(correct) >= tau, else the strongest
print(dict(zip(cfg["agent_order"], p_correct.round(decimals=3).tolist())), "->", agent)

For router_oracle.pt use torch.softmax(net(emb), -1) and take the top agent (Ο„* = 0).

Training data

2,000 English questions, 500 each from the validation splits of NQ-Open, SQuAD v1.1, HotpotQA (distractor) and MuSiQue-Ans, split 1,400 / 300 / 300. Every question was answered by all five agents on Kaggle (2 Γ— T4); an answer counts as correct at token F1 β‰₯ 0.6. Compute is measured per question in GFLOPs.

Limitations

  • Question-only routing: the router never sees retrieved passages or answers, which is the paper's explanation for the gap to the oracle.
  • English only. The planned code-mixed English / Roman Urdu test has not been run.
  • The agents, prompts and correctness threshold are fixed; a router trained for these five agents will not transfer to other agents without retraining.
  • Research use only.

Citation

@misc{hussain2026router,
  author    = {Hussain, Muzammal},
  title     = {{Routers and Cascades Miss a 15-Point Oracle Gap in Multi-Agent RAG}},
  year      = {2026},
  publisher = {Zenodo},
  doi       = {10.5281/zenodo.24464707},
  url       = {https://doi.org/10.5281/zenodo.24464707}
}
Downloads last month
26
Inference Providers NEW
This model isn't deployed by any Inference Provider. πŸ™‹ Ask for provider support

Model tree for MHkhan50/agentic-rag-router

Finetuned
(202)
this model

Datasets used to train MHkhan50/agentic-rag-router