SYNTOLOGY HomeExplorerAtlasCodeMethodologyAboutDevelopersFeedPricing
Paper · 2502.11133 · ACL · 2025

MasRouter: Learning to Route LLMs for Multi-Agent System

Kun Wang, Dawei Cheng, Boyang Liu, Yiyan Qi, Guancheng Wan, Yanwei Yue, Gui-Min Zhang

arXiv · PDF · Open in the Atlas

Code that ran

13 of 13 samples (functions and classes) lifted from this paper's linked repositories executed on a synthesized input in Syntology's jail (0 of them constructed an object rather than computing a result; 1 honoured the contract we drafted, 1 violated it and 7 have no contract verdict; 4 failures of our instrument; 0 no recorded run), measured 2026-11-23; repository links from the Papers with Code archive attributed under CC BY-SA, no affiliation; bodies inline only under a permissive licence as GitHub detects it. Not a reproduction of the paper's results.

"Ran" means the function executed on a synthesized input and returned a value. It is not a reproduction of the paper's results. This record, dated, as JSON: /api/ran/2502.11133.json · badge: /api/ran/2502.11133.svg

Each repository's role is a label: a classifier's output recorded on the link, or, where no role is recorded, what the Papers with Code archive marked. The line under it names its basis. Neither says who wrote the code.

RepositoryRoleRan
yanweiyue/masrouter canonical (classifier label)
classifier basis not recorded on the link
13 ran · 0 no recorded run
FunctionStatusWhere it lives
dataloader Ran
ran; our contract draft was wrong, not the code
yanweiyue/masrouter/Experiments/run_gsm8k.py
pointer only (licence: Apache-2.0); the stored copy get_code serves, from jinxiy1104/CodebookAgent, is pointer only (licence: NONE) · get_code("ded2dee441b71d0d")
How it ran

The body of this sample is withheld: this paper's link allows the body inline (Apache-2.0), but get_code serves the stored copy, first harvested from jinxiy1104/CodebookAgent, and GitHub detected no licence in that repository when it was checked. The setup block that called it is withheld with it, because it is written against that body. source_path and origin say where the code lives, to read under the repository's own terms. A run is recorded.

delete_extra_zero Ran
ran; our contract draft was wrong, not the code
yanweiyue/masrouter/Datasets/gsm8k_dataset.py
pointer only (licence: Apache-2.0); the stored copy get_code serves, from TonySY2/AgentDropoutV2, is pointer only (licence: NONE) · get_code("1311b1da2c08b63b")
How it ran

The body of this sample is withheld: this paper's link allows the body inline (Apache-2.0), but get_code serves the stored copy, first harvested from TonySY2/AgentDropoutV2, and GitHub detected no licence in that repository when it was checked. The setup block that called it is withheld with it, because it is written against that body. source_path and origin say where the code lives, to read under the repository's own terms. A run is recorded.

gsm_data_process Ran
ran; our contract draft was wrong, not the code
yanweiyue/masrouter/Datasets/gsm8k_dataset.py
pointer only (licence: Apache-2.0); the stored copy get_code serves, from TonySY2/AgentDropoutV2, is pointer only (licence: NONE) · get_code("54b831c1e15e7821")
How it ran

The body of this sample is withheld: this paper's link allows the body inline (Apache-2.0), but get_code serves the stored copy, first harvested from TonySY2/AgentDropoutV2, and GitHub detected no licence in that repository when it was checked. The setup block that called it is withheld with it, because it is written against that body. source_path and origin say where the code lives, to read under the repository's own terms. A run is recorded.

gsm_get_predict Ran
ran on a synthesized input
yanweiyue/masrouter/Datasets/gsm8k_dataset.py
code served (permissive licence) · get_code("3ca24d2f48268285")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned str. The image it ran in was not recorded. If your copy returns the same type on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import re

# The function gsm_get_predict takes a single parameter: pred_str
# Looking at the function body, it:
# - checks if 'answer is ' is in the string
# - checks if 'boxed' is in the string
# - uses regex to find patterns
# - calls _strip_string on various substrings
# - All operations are string manipulations

# We need to construct a pred_str that exercises the function
# Let's create a comprehensive test case with a boxed answer

pred_str = "The answer is \\boxed{\\frac{1}{2}}"

ARGS = {
    "pred_str": pred_str
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
none outside the standard library — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type str — a str output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a str output the recorded ndim 0 and dtype family float describe that coercion, not the output, and are not stated
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
gsm_get_predict Ran
ran on a synthesized input
yanweiyue/masrouter/Datasets/gsm8k/gsm8k_dataset.py
code served (permissive licence) · get_code("60f5f7fbe1fa799d")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned str. The image it ran in was not recorded. If your copy returns the same type on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import re

# The function gsm_get_predict takes a single parameter: pred_str
# Looking at the function body, it:
# - Takes a string as input
# - Uses re.sub to remove commas between digits
# - Checks for various string patterns like 'The answer is', 'the answer is', 'boxed'
# - Uses re.findall to find numeric patterns
# - Calls helper functions like _strip_string on the extracted prediction
# The function processes mathematical/text output and extracts numerical answers

# Construct valid test inputs
ARGS = {
    'pred_str': 'The answer is 42'
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
none outside the standard library — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type str — a str output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a str output the recorded ndim 0 and dtype family float describe that coercion, not the output, and are not stated
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
is_equiv Ran
ran, violated the contract we drafted
yanweiyue/masrouter/Datasets/math_dataset.py
code served (permissive licence) · get_code("20063c675d638a77")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned bool, ndim 0, dtype family float, shape () as a later run recorded it. The image it ran in was not recorded. If your copy returns the same type, ndim and shape on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

ARGS = {
    'str1': '\\frac{1}{2}',
    'str2': '0.5',
    'verbose': False
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
none outside the standard library — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type bool, ndim 0, dtype family float, shape () — shape () as a later run recorded it
dtype family
int means an integer dtype; float means any other dtype the instrument saw, bool and complex included (fixture_check.py records only these two families)
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
is_number Ran
ran on a synthesized input
yanweiyue/masrouter/Datasets/gsm8k/gsm8k_dataset.py
code served (permissive licence) · get_code("4f015b339ccf7dee")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned bool, ndim 0, dtype family float, shape () as a later run recorded it. The image it ran in was not recorded. If your copy returns the same type, ndim and shape on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import torch
import numpy as np

def setup_is_number():
    """
    The function is_number takes a single parameter 's' and attempts to:
    1. Convert it to float
    2. If that fails, try to get its unicode numeric value
    3. Return True if either succeeds, False otherwise
    
    So 's' should be a string or string-like object.
    """
    
    # Test with a valid numeric string
    s = "42.5"
    
    return {"s": s}

ARGS = setup_is_number()
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
numpy, torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type bool, ndim 0, dtype family float, shape () — shape () as a later run recorded it
dtype family
int means an integer dtype; float means any other dtype the instrument saw, bool and complex included (fixture_check.py records only these two families)
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
last_boxed_only_string Ran
ran; our contract draft was wrong, not the code
yanweiyue/masrouter/Datasets/math_dataset.py
code served (permissive licence) · get_code("0b14c648516c38a7")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned str. The image it ran in was not recorded. If your copy returns the same type on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

# Analyzing the function: last_boxed_only_string
# The function takes a single parameter 'string' which is a string
# It searches for '\boxed' or '\fbox' in the string and extracts the boxed content
# The function uses string methods: rfind, len, indexing

ARGS = {
    "string": r"Some text before \boxed{answer here} and some text after"
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
none outside the standard library — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type str — a str output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a str output the recorded ndim 0 and dtype family float describe that coercion, not the output, and are not stated
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
load_config Ran
ran on a synthesized input
yanweiyue/masrouter/Experiments/run_gsm8k.py
code served (permissive licence) · get_code("3cc5969c32b1d933")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned dict. The image it ran in was not recorded. If your copy returns the same type on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import yaml
import tempfile
import os

# Create a temporary YAML config file
temp_dir = tempfile.mkdtemp()
config_file_path = os.path.join(temp_dir, "test_config.yaml")

# Write a simple config to the file
config_content = """
model:
  name: test_model
  layers: 3
training:
  epochs: 10
  learning_rate: 0.001
data:
  batch_size: 32
"""

with open(config_file_path, 'w', encoding='utf-8') as f:
    f.write(config_content)

ARGS = {
    "config_path": config_file_path
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
yaml — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type dict — a dict output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a dict output the recorded ndim 0 and dtype family float describe that coercion, not the output, and are not stated
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
load_math_dataset Ran
ran on a synthesized input
yanweiyue/masrouter/Datasets/math_dataset.py
code served (permissive licence) · get_code("abf234d8889f0012")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned list, ndim 1, dtype family float; no output shape is stated. The image it ran in was not recorded. If your copy returns the same type and ndim on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import glob
import os
import json
import tempfile
import shutil
from typing import Union, List, Literal, Any, Dict
import numpy as np

# Create a temporary directory structure with mock math dataset files
temp_dir = tempfile.mkdtemp()

# Create directory structure: temp_dir/train/category1, temp_dir/train/category2
train_dir = os.path.join(temp_dir, 'train')
os.makedirs(train_dir)

category1_dir = os.path.join(train_dir, 'algebra')
category2_dir = os.path.join(train_dir, 'geometry')
os.makedirs(category1_dir)
os.makedirs(category2_dir)

# Create sample JSON files in each category
sample_data_1 = {'question': 'What is 2+2?', 'answer': '4'}
sample_data_2 = {'question': 'What is 3*3?', 'answer': '9'}
sample_data_3 = {'question': 'What is the area of a circle?', 'answer': 'πr²'}

with open(os.path.join(category1_dir, 'problem1.json'), 'w', encoding='utf-8') as f:
    json.dump(sample_data_1, f)

with open(os.path.join(category1_dir, 'problem2.json'), 'w', encoding='utf-8') as f:
    json.dump(sample_data_2, f)

with open(os.path.join(category2_dir, 'problem3.json'), 'w', encoding='utf-8') as f:
    json.dump(sample_data_3, f)

# Also create sampled_train and test directories for completeness
for split_name in ['sampled_train', 'sampled_test', 'test']:
    split_dir = os.path.join(temp_dir, split_name)
    os.makedirs(split_dir)
    cat_dir = os.path.join(split_dir, 'sample_category')
    os.makedirs(cat_dir)
    with open(os.path.join(cat_dir, 'sample.json'), 'w', encoding='utf-8') as f:
        json.dump({'question': 'sample', 'answer': 'sample'}, f)

ARGS = {
    'data_path': temp_dir,
    'split': 'train'
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
numpy — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type list, ndim 1, dtype family float — a list output has no array shape of its own; none is stated
dtype family
int means an integer dtype; float means any other dtype the instrument saw, bool and complex included (fixture_check.py records only these two families)
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
load_result Ran
ran, honoured the contract we drafted
yanweiyue/masrouter/Experiments/run_gsm8k.py
pointer only (licence: Apache-2.0); the stored copy get_code serves, from jinxiy1104/CodebookAgent, is pointer only (licence: NONE) · get_code("bcde03579f1c0bee")
How it ran

The body of this sample is withheld: this paper's link allows the body inline (Apache-2.0), but get_code serves the stored copy, first harvested from jinxiy1104/CodebookAgent, and GitHub detected no licence in that repository when it was checked. The setup block that called it is withheld with it, because it is written against that body. source_path and origin say where the code lives, to read under the repository's own terms. A run is recorded.

process_data Ran
ran on a synthesized input
yanweiyue/masrouter/Datasets/mbpp_dataset.py
code served (permissive licence) · get_code("bda9fabfb8bf5d44")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned DataFrame. The image it ran in was not recorded. If your copy returns the same type on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import pandas as pd

# Create a simple DataFrame with the required columns
df = pd.DataFrame({
    'text': [
        'def add(a, b):\n    return a + b',
        'def multiply(x, y):\n    return x * y'
    ],
    'test_list': [
        ['assert add(2, 3) == 5', 'assert add(0, 0) == 0'],
        ['assert multiply(2, 3) == 6', 'assert multiply(5, 0) == 0']
    ]
})

ARGS = {
    'df': df
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
pandas — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type DataFrame — a DataFrame output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a DataFrame output the recorded ndim 2 and dtype family float describe that coercion, not the output, and are not stated
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
vae_loss_function Ran
ran on a synthesized input
yanweiyue/masrouter/MAR/MasRouter/mas_router.py
code served (permissive licence) · get_code("ac907213ed700f77")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned Tensor, ndim 0, dtype family float, shape () as a later run recorded it. The image it ran in was not recorded. If your copy returns the same type, ndim and shape on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import torch
import torch.nn.functional as F
import math

torch.manual_seed(0)

# Construct small tensors for the VAE loss function
batch_size = 2
latent_dim = 4
input_dim = 3

# x_hat: reconstructed output, shape (batch_size, input_dim)
x_hat = torch.randn(batch_size, input_dim)

# x: original input, same shape as x_hat
x = torch.randn(batch_size, input_dim)

# mu: mean of latent distribution, shape (batch_size, latent_dim)
mu = torch.randn(batch_size, latent_dim)

# log_var: log variance of latent distribution, shape (batch_size, latent_dim)
log_var = torch.randn(batch_size, latent_dim)

ARGS = {
    'x_hat': x_hat,
    'x': x,
    'mu': mu,
    'log_var': log_var
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type Tensor, ndim 0, dtype family float, shape () — shape () as a later run recorded it
dtype family
int means an integer dtype; float means any other dtype the instrument saw, bool and complex included (fixture_check.py records only these two families)
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block

Also present in other papers' code

Of 13 samples lifted from this paper's linked repositories, 13 carry a function identity and 0 do not. Of the 13 distinct functions with an identity, 6 are also present in other papers whose code we hold (2 with at least one paper dated earlier, 0 the same month, 6 later) and 7 are only here among the 52,977 papers whose code Syntology holds (as of 2026-09-26).

Only here means: among the 52,977 papers whose code Syntology holds (51,887 with lifted samples, 1,090 through their assemblies only), as of 2026-09-26, no other paper's lifted samples or current assembly bricks contain an identical function body after normalisation.

FunctionAlso present inEarliest-datedOthers named
last_boxed_only_string 17 other papers
10 dated earlier, 6 later, 1 same year, order not determinable
2309.06275 (2023-09)
Re-Reading Improves Reasoning in Large Language Models
2310.05914 (2023-10)
NEFTune: Noisy Embeddings Improve Instruction Finetuning
2024.findings-emnlp.407 (2024 (year only))
MultiAgent Collaboration Attack: Investigating Adversarial Attacks in Large Language Model Collaborations via Debate
and 14 more not named here
is_equiv 11 other papers
7 dated earlier, 4 later
2310.05914 (2023-10)
NEFTune: Noisy Embeddings Improve Instruction Finetuning
2310.09168 (2023-10)
EXPLORE-INSTRUCT: Enhancing Domain-Specific Instruction Coverage through Active Exploration
2024.findings-emnlp.407 (2024 (year only))
MultiAgent Collaboration Attack: Investigating Adversarial Attacks in Large Language Model Collaborations via Debate
and 8 more not named here
delete_extra_zero 2 other papers
2 later
2602.23258 (2026-02)
AgentDropoutV2: Optimizing Information Flow in Multi-Agent Systems via Test-Time Rectify-or-Reject Pruning
2609.02264 (2026-09)
Codebook Agent: Amortized Topology Design for LLM Multi-Agent Systems
gsm_data_process 2 other papers
2 later
2602.23258 (2026-02)
AgentDropoutV2: Optimizing Information Flow in Multi-Agent Systems via Test-Time Rectify-or-Reject Pruning
2609.02264 (2026-09)
Codebook Agent: Amortized Topology Design for LLM Multi-Agent Systems
dataloader 1 other paper
1 later
2609.02264 (2026-09)
Codebook Agent: Amortized Topology Design for LLM Multi-Agent Systems
load_result 1 other paper
1 later
2609.02264 (2026-09)
Codebook Agent: Amortized Topology Design for LLM Multi-Agent Systems

Presence, not direction: an identical function body in two papers' repositories does not say who wrote it, which came from which, or that either paper's method rests on it. Matching is exact after normalisation, so a renamed or edited function is not matched. Dates are when papers appeared, not when code was written. Only .py files the harvester lifted are covered; notebooks are not read. A new-style arXiv id YYMM.NNNN dates a paper to the month 20YY-MM; otherwise Paper.year dates it to the year; otherwise it is undated. Dates are when the paper appeared, not when the code was written. Read 2026-11-23.

Repositories linked to this paper

Some links come from the archived Papers with Code dataset (CC BY-SA 4.0): attribution and licence.

Abstract

Multi-agent systems (MAS) powered by Large Language Models (LLMs) have been demonstrated to push the boundaries of LLM capabilities, yet they often incur significant costs and face challenges in dynamic LLM selection. Current LLM routing methods effectively reduce overhead in single-agent scenarios by customizing LLM selection for each query, but they overlook the critical decisions regarding collaboration modes and agent roles in MAS. In response to this challenge, we first introduce the problem of Multi-Agent System Routing (MASR), which integrates all components of MAS into a unified routing framework. Toward this goal, we propose MasRouter, the first high-performing, cost-effective, and inductive MASR solution. MasRouter employs collaboration mode determination, role allocation, and LLM routing through a cascaded controller network, progressively constructing a MAS that balances effectiveness and efficiency. Extensive experiments demonstrate that MasRouter is (1) high-performing, achieving a 1.8% ∼ 8.2% improvement over the stateof-the-art method on MBPP; (2) economical, reducing overhead by up to 52.07% compared to SOTA methods on HumanEval; and (3) plugand-play, seamlessly integrating with mainstream MAS frameworks, reducing overhead by 17.21% ∼ 28.17% via customized routing. The code is available at https://github. com/yanweiyue/masrouter.

For agents

The same record, over MCP at https://syntology.ai/mcp:

get_harvested_code_for_paper("2502.11133")
get_code_for_paper("2502.11133")
have("2502.11133")

The run record, dated, one paper per request, free:

curl https://syntology.ai/api/ran/2502.11133.json

A badge for a README (the split and the date, never a ratio):

[![Syntology run record](https://syntology.ai/api/ran/2502.11133.svg)](https://syntology.ai/paper/2502.11133)

Connect an agent — have() is free.