SYNTOLOGY HomeExplorerAtlasCodeMethodologyAboutDevelopersFeedPricing
Paper · 2402.01620 · ICML · 2024

MAGDI: Structured Distillation of Multi-Agent Interaction Graphs Improves Reasoning in Smaller Language Models

Mohit Bansal, Swarnadeep Saha, Elias Stengel-Eskin, Yao Chen, Justin Chih-Yao Chen, Justin Chih

arXiv · PDF · Open in the Atlas

Code that ran

6 of 6 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; 0 honoured the contract we drafted, 1 violated it and 0 have no contract verdict; 5 failures of our instrument; 0 no recorded run), measured 2026-11-22; 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/2402.01620.json · badge: /api/ran/2402.01620.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
dinobby/MAGDi canonical (classifier label)
classifier basis: census
6 ran · 0 no recorded run
FunctionStatusWhere it lives
construct_graphs Ran
ran; the contract check could not run (RAISES, DEP_MISSING or TIMEOUT)
dinobby/MAGDi/utils.py
code served (permissive licence) · get_code("bf01ec7c4053e257")
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. 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 torch

torch.manual_seed(0)

def remove_agreement(text, phrase=['I disagree', 'I agree']):
    sentences = text.split('. ')
    sentences = [sentence for sentence in sentences if not (sentence.startswith(phrase[0]) or sentence.startswith(phrase[1]))]
    result_text = '. '.join(sentences)
    return result_text

# Create sample all_result with the expected structure
all_result = [
    {
        'question': 'What is 2+2?',
        'gold_answer': '4',
        'claude_output_0': {'reasoning': 'Two plus two equals four', 'answer': '4'},
        'claude_output_1': {'reasoning': 'Adding two and two', 'answer': '5'},
        'claude_output_2': None,
        'claude_output_3': None,
        'gpt4_output_0': {'reasoning': 'Simple arithmetic', 'answer': '4'},
        'gpt4_output_1': {'reasoning': 'Two and two', 'answer': '3'},
        'gpt4_output_2': None,
        'gpt4_output_3': None,
        'bard_output_0': {'reasoning': 'Math calculation', 'answer': '4'},
        'bard_output_1': {'reasoning': 'Adding numbers', 'answer': '6'},
        'bard_output_2': None,
        'bard_output_3': None,
    },
    {
        'question': 'What is the capital of France?',
        'gold_answer': 'Paris',
        'claude_output_0': {'reasoning': 'France capital is Paris', 'answer': 'Paris'},
        'claude_output_1': {'reasoning': 'The answer is', 'answer': 'London'},
        'claude_output_2': None,
        'claude_output_3': None,
        'gpt4_output_0': {'reasoning': 'Capital city', 'answer': 'Paris'},
        'gpt4_output_1': {'reasoning': 'French city', 'answer': 'Lyon'},
        'gpt4_output_2': None,
        'gpt4_output_3': None,
        'bard_output_0': {'reasoning': 'European capital', 'answer': 'Paris'},
        'bard_output_1': {'reasoning': 'City in France', 'answer': 'Marseille'},
        'bard_output_2': None,
        'bard_output_3': None,
    }
]

# num_train_samples = 2 (one per result)
# max_node_num = 12 (4 claude + 4 gpt4 + 4 bard outputs per result)
num_train_samples = 2
max_node_num = 12

# Create embeddings: shape (num_train_samples, max_node_num, embedding_dim)
# Each embedding should be a tensor of shape (max_node_num, embedding_dim)
embeddings = [torch.randn(max_node_num, 4) for _ in range(num_train_samples)]

ARGS = {
    'all_result': all_result,
    'embeddings': embeddings,
    'num_train_samples': num_train_samples,
    'max_node_num': max_node_num,
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
torch, torch_geometric — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type list — a list output has no array shape of its own; none is 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
generate_ordered_list Ran
ran; our contract draft was wrong, not the code
dinobby/MAGDi/utils.py
code served (permissive licence) · get_code("b2178fcfdadace75")
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 tuple, ndim 2, 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 torch
import numpy as np

# Set seed for reproducibility
torch.manual_seed(0)

# Define the arguments for generate_ordered_list
all_result = [
    {
        'question': 'What is 2 + 2?',
        'gold_answer': '4',
        'claude_output_0': {
            'reasoning': 'Two plus two equals four. I agree with this statement.',
            'answer': '4'
        },
        'claude_output_1': {
            'reasoning': 'I disagree with the notion that two plus two is five.',
            'answer': '4'
        },
        'claude_output_2': None,
        'claude_output_3': {
            'reasoning': 'Basic arithmetic tells us that 2 + 2 = 4.',
            'answer': '5'
        },
        'gpt4_output_0': {
            'reasoning': 'The sum of two and two is definitely four.',
            'answer': '4'
        },
        'gpt4_output_1': {
            'reasoning': 'I agree that this is a simple calculation.',
            'answer': '4'
        },
        'gpt4_output_2': None,
        'gpt4_output_3': {
            'reasoning': 'Two plus two equals four without question.',
            'answer': '3'
        },
        'bard_output_0': {
            'reasoning': 'In mathematics, 2 + 2 = 4 is a fundamental truth.',
            'answer': '4'
        },
        'bard_output_1': {
            'reasoning': 'I disagree with incorrect answers.',
            'answer': '4'
        },
        'bard_output_2': None,
        'bard_output_3': {
            'reasoning': 'The answer is straightforward.',
            'answer': '6'
        }
    },
    {
        'question': 'What is the capital of France?',
        'gold_answer': 'Paris',
        'claude_output_0': {
            'reasoning': 'The capital of France is Paris, a major European city.',
            'answer': 'Paris'
        },
        'claude_output_1': {
            'reasoning': 'I agree this is well known.',
            'answer': 'Paris'
        },
        'claude_output_2': None,
        'claude_output_3': {
            'reasoning': 'France has a well-known capital.',
            'answer': 'Lyon'
        },
        'gpt4_output_0': {
            'reasoning': 'Paris is the capital and largest city of France.',
            'answer': 'Paris'
        },
        'gpt4_output_1': {
            'reasoning': 'I disagree with any other answer.',
            'answer': 'Paris'
        },
        'gpt4_output_2': None,
        'gpt4_output_3': {
            'reasoning': 'This is basic geography.',
            'answer': 'Berlin'
        },
        'bard_output_0': {
            'reasoning': 'Paris is the capital of France.',
            'answer': 'Paris'
        },
        'bard_output_1': {
            'reasoning': 'I agree with historical facts.',
            'answer': 'Paris'
        },
        'bard_output_2': None,
        'bard_output_3': {
            'reasoning': 'France has a notable capital city.',
            'answer': 'Marseille'
        }
    }
]

ARGS = {
    'all_result': all_result
}
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 tuple, ndim 2, dtype family float — a tuple 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
is_equiv_1 Ran
ran, violated the contract we drafted
dinobby/MAGDi/data_utils.py
code served (permissive licence) · get_code("6864bb6570ea95b0")
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.

# Setup code for is_equiv_1 function

# The function takes two string parameters and an optional verbose boolean
# It performs LaTeX string normalization and comparison

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
normalize_fraction_notation Ran
ran; our contract draft was wrong, not the code
dinobby/MAGDi/data_utils.py
code served (permissive licence) · get_code("c5f35db9cb688b48")
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

def normalize_fraction_notation(expr):
    """
    Normalizes different fraction notations (\\frac, \x0crac, rac) into a consistent format.

    :param expr: A string containing the expression with fraction notations.
    :return: A string with the normalized fraction format.
    """
    frac_pattern = '(\\\\\\\\frac|\\\\frac|rac)\\{([^}]+)\\}\\{([^}]+)\\}'

    def replace_frac(match):
        _, num, den = match.groups()
        return f'({num})/({den})'
    return re.sub(frac_pattern, replace_frac, expr)


# Setup code
ARGS = {
    'expr': r'\frac{a+b}{c+d} and rac{x}{y} and \\frac{1}{2}'
}
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
pad_graphs Ran
ran; our contract draft was wrong, not the code
dinobby/MAGDi/utils.py
code served (permissive licence) · get_code("9b09aa346afde94f")
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 tuple, ndim 2, 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 torch
import torch.nn as nn
from itertools import cycle

torch.manual_seed(0)

# Create training_batch: a list of dicts, each with a 'graph' key that will be populated
training_batch = [
    {'data': torch.randn(2, 4)},
    {'data': torch.randn(2, 4)}
]

# Create graphs: a list of graph objects (can be simple dicts or tensors)
graphs = [
    {'nodes': torch.randn(3, 4)},
    {'nodes': torch.randn(3, 4)},
    {'nodes': torch.randn(3, 4)}
]

ARGS = {
    'training_batch': training_batch,
    'graphs': graphs
}
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 tuple, ndim 2, dtype family float — a tuple 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
prepare_test_data Ran
ran; our contract draft was wrong, not the code
dinobby/MAGDi/data_utils.py
code served (permissive licence) · get_code("6a272c4b18d461a9")
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 tuple, ndim 2, 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 json
import tempfile
import os

# Create a temporary directory with test data
temp_dir = tempfile.mkdtemp()
test_data_dir = os.path.join(temp_dir, 'test_data')
os.makedirs(test_data_dir, exist_ok=True)

# Create sample test data file
sample_dataset = 'sample'
test_file_path = os.path.join(test_data_dir, f'{sample_dataset}_test.json')

test_data = [
    {'question': 'What is 2+2?'},
    {'question': 'What is the capital of France?'},
    {'question': 'Explain machine learning'}
]

with open(test_file_path, 'w') as f:
    json.dump(test_data, f)

# Change to temp directory so the function can find test_data/
original_dir = os.getcwd()
os.chdir(temp_dir)

ARGS = {
    'dataset': 'sample'
}
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 tuple, ndim 2, dtype family float — a tuple 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

Also present in other papers' code

Of 6 samples lifted from this paper's linked repositories, 6 carry a function identity and 0 do not. Of the 6 distinct functions with an identity, 0 are also present in other papers whose code we hold (0 with at least one paper dated earlier, 0 the same month, 0 later) and 6 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.

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-22.

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 interactions between Large Language Model (LLM) agents have shown major improvements on diverse reasoning tasks. However, these involve long generations from multiple models across several rounds, making them expensive. Moreover, these multi-agent approaches fail to provide a final, single model for efficient inference. To address this, we introduce MAGDI, a new method for structured distillation of the reasoning interactions between multiple LLMs into smaller LMs. MAGDI teaches smaller models by representing multi-agent interactions as graphs, augmenting a base student model with a graph encoder, and distilling knowledge using three objective functions: next-token prediction, a contrastive loss between correct and incorrect reasoning, and a graph-based objective to model the interaction structure. Experiments on seven widelyused commonsense and math reasoning benchmarks show that MAGDI improves the reasoning capabilities of smaller models, outperforming several methods that distill from a single teacher and multiple teachers. Moreover, MAGDI also demonstrates an order of magnitude higher efficiency over its teachers. We conduct extensive analyses to show that MAGDI (1) enhances the generalizability to out-of-domain tasks, (2) scales positively with the size and strength of the base student model, and (3) obtains larger improvements (via our multi-teacher training) when applying self-consistency -an inference technique that relies on model diversity. 1

For agents

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

get_harvested_code_for_paper("2402.01620")
get_code_for_paper("2402.01620")
have("2402.01620")

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

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

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

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

Connect an agent — have() is free.