SYNTOLOGY HomeExplorerAtlasCodeMethodologyAboutDevelopersFeedPricing
Paper · 2402.14320 · EMNLP · 2024

Triad: A Framework Leveraging a Multi-Role LLM-based Agent to Solve Knowledge Base Question Answering

Heng Chang, Yueting Zhuang, Yuchen Yan, Weiming Lu, Jian Shao, Yongfeng Huang, Chang Zong

arXiv · PDF · Open in the Atlas

Code that ran

5 of 5 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, 0 violated it and 0 have no contract verdict; 4 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.14320.json · badge: /api/ran/2402.14320.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
ZJU-DCDLab/Triad canonical (classifier label)
classifier basis: census
5 ran · 0 no recorded run
FunctionStatusWhere it lives
format_lm_input_and_response Ran
ran; our contract draft was wrong, not the code
ZJU-DCDLab/Triad/utils.py
code served (permissive licence) · get_code("de27068f288c8047")
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 torch

def format_lm_input_and_response(input, response):
    return f'\nPrompt for model: >>>>>>>>\n{input}\n<<<<<<<<\n\nResponse of model: >>>>>>>>\n{response}\n<<<<<<<<\n'

ARGS = {
    'input': 'What is the capital of France?',
    'response': 'The capital of France is Paris.'
}
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 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
format_uri Ran
ran; our contract draft was wrong, not the code
ZJU-DCDLab/Triad/query_generator.py
code served (permissive licence) · get_code("0f7cd1634c94f943")
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 torch

# Simple triple: (subject, predicate, object)
# Each can be either a URI (string starting with < or not) or a variable (string starting with ?)

# Example 1: all URIs
triple_uris = (
    'http://example.org/subject',
    'http://example.org/predicate',
    'http://example.org/object'
)

# Example 2: with variables
triple_vars = (
    '?subject',
    'http://example.org/predicate',
    '?object'
)

# Example 3: mixed
triple_mixed = (
    'http://example.org/Alice',
    '?predicate',
    'http://example.org/Bob'
)

ARGS = {
    'triple': triple_uris
}
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 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
log_lm Ran
ran; our contract draft was wrong, not the code
ZJU-DCDLab/Triad/utils.py
code served (permissive licence) · get_code("544fc9cf382eba79")
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 function. 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
import logging
from unittest.mock import Mock

torch.manual_seed(0)
logger = logging.getLogger()

# The log_lm decorator wraps a function that takes at least 2 positional arguments
# where args[1] is the prompt (or kwargs['prompt']).
# The wrapped function should return a response string.

def mock_lm_function(self, prompt, **kwargs):
    """Mock function that will be decorated by log_lm"""
    return f"Generated response for: {prompt}"

# Create a mock object to serve as 'self' (args[0])
mock_self = Mock()

# Define arguments for log_lm
# log_lm is a decorator that takes a function as its argument
# The decorator itself doesn't take arguments - it just wraps a function
# So we need to call log_lm with the function to decorate

# The function being decorated will be called with (*args, **kwargs)
# where args[0] is self, args[1] is prompt
ARGS = {
    'func': mock_lm_function
}
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 function — a function output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a function 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
log_time_cost Ran
ran; our contract draft was wrong, not the code
ZJU-DCDLab/Triad/utils.py
code served (permissive licence) · get_code("80efeec2d2ce9b72")
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 function. 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 logging
import time
from collections import defaultdict

logger = logging.getLogger()
logging.basicConfig(level=logging.INFO)

time_dict = defaultdict(list)

def print_time_dict(td):
    temp_dict = {k: round(sum(v), 5) for k, v in td.items()}
    print(temp_dict)
    logger.info(f'{temp_dict}')

def log_time_cost(method_name, reset=False):

    def decorator(func):

        def wrapper(*args, **kwargs):
            start_time = time.time()
            result = func(*args, **kwargs)
            end_time = time.time()
            execution_time = end_time - start_time
            time_dict[method_name].append(execution_time)
            log = '{} cost: {:.2f} s'.format(method_name, execution_time)
            logger.info(log)
            if reset:
                print_time_dict(time_dict)
                time_dict.clear()
            return result
        return wrapper
    return decorator


# Test function to decorate
@log_time_cost("test_function", reset=False)
def sample_function():
    time.sleep(0.01)
    return 42


@log_time_cost("test_function_with_reset", reset=True)
def sample_function_with_reset():
    time.sleep(0.01)
    return 42


# Arguments for log_time_cost
ARGS = {
    "method_name": "test_operation",
    "reset": 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 function — a function output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a function 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
rank_triples Ran
ran, honoured the contract we drafted
ZJU-DCDLab/Triad/query_generator.py
code served (permissive licence) · get_code("c4c58b4c8e527c57")
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 int, ndim 0, dtype family int, 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

def rank_triples(triple):
    s, p, o = triple
    if s.startswith('?') and o.startswith('?'):
        return 2
    elif s.startswith('?') or o.startswith('?'):
        return 1
    else:
        return 0

# Construct valid arguments
# The function expects a tuple of 3 elements (s, p, o)
# Each element should be a string that can be checked with startswith('?')

triple = ('?subject', 'predicate', '?object')

ARGS = {
    'triple': triple
}
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 int, ndim 0, dtype family int, 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 5 samples lifted from this paper's linked repositories, 5 carry a function identity and 0 do not. Of the 5 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 5 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

Recent progress with LLM-based agents has shown promising results across various tasks. However, their use in answering questions from knowledge bases remains largely unexplored. Implementing a KBQA system using traditional methods is challenging due to the shortage of task-specific training data and the complexity of creating task-focused model structures. In this paper, we present Triad, a unified framework that utilizes an LLM-based agent with multiple roles for KBQA tasks. The agent is assigned three roles to tackle different KBQA subtasks: agent as a generalist for mastering various subtasks, as a decision maker for the selection of candidates, and as an advisor for answering questions with knowledge. Our KBQA framework is executed in four phases, involving the collaboration of the agent's multiple roles. We evaluated the performance of our framework using three benchmark datasets, and the results show that our framework outperforms state-of-the-art systems on the LC-QuAD and YAGO-QA benchmarks, yielding F1 scores of 11.8% and 20.7%, respectively.

For agents

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

get_harvested_code_for_paper("2402.14320")
get_code_for_paper("2402.14320")
have("2402.14320")

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

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

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

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

Connect an agent — have() is free.