SYNTOLOGY HomeExplorerAtlasCodeMethodologyAboutDevelopersFeedPricing
Paper · 2403.04746 · ACL · 2024

LLMs in the Imaginarium: Tool Learning through Simulated Trial and Error

Jason Eisner, Hao Fang, Benjamin Van Durme, Yu Su, Boshi Wang

arXiv · PDF · Open in the Atlas

Code that ran

6 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; 2 honoured the contract we drafted, 0 violated it and 0 have no contract verdict; 4 failures of our instrument; 7 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/2403.04746.json · badge: /api/ran/2403.04746.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
microsoft/simulated-trial-and-error canonical (classifier label)
classifier basis: census
6 ran · 7 no recorded run
FunctionStatusWhere it lives
find_reverse Ran
ran, honoured the contract we drafted
microsoft/simulated-trial-and-error/STE/utils.py
code served (permissive licence) · get_code("d905a14ca2a7fd88")
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
import numpy as np

def find_reverse(str_a, ch):
    assert type(str_a) == type(ch) == str
    for i in range(len(str_a) - 1, -1, -1):
        if str_a[i] == ch:
            return i
    return -1

ARGS = {
    "str_a": "hello world",
    "ch": "o"
}
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 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
format_tokens_split Ran
ran, honoured the contract we drafted
microsoft/simulated-trial-and-error/llama-recipes/ft_datasets/tool_dataset.py
code served (permissive licence) · get_code("42840b65b58c1a33")
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 int; 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

class SimpleTokenizer:
    """Stand-in tokenizer with encode method"""
    def __init__(self):
        self.token_map = {
            "hello": [1, 2],
            "world": [3, 4],
            "how": [5],
            "are": [6],
            "you": [7, 8],
            "fine": [9],
            "thanks": [10, 11],
        }
    
    def encode(self, text):
        """Encode text into token list"""
        text_lower = text.lower()
        tokens = []
        for word in text_lower.split():
            if word in self.token_map:
                tokens.extend(self.token_map[word])
            else:
                # Default: convert to simple token ids
                tokens.extend([ord(c) for c in word[:2]])
        return tokens

tokenizer = SimpleTokenizer()

dialog_history = [
    "hello world",
    "how are you",
    "fine thanks",
]

last_msg = "you are great"

ARGS = {
    "dialog_history": dialog_history,
    "last_msg": last_msg,
    "tokenizer": tokenizer,
}
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 list, ndim 1, dtype family int — 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_model Ran
ran; the contract check could not run (RAISES, DEP_MISSING or TIMEOUT)
microsoft/simulated-trial-and-error/llama-recipes/inference/model_utils.py
code served (permissive licence) · get_code("86440eb9f495e01b")
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 Mock. 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
from unittest.mock import Mock, MagicMock
from transformers import LlamaForCausalLM, MistralForCausalLM

torch.manual_seed(0)

# Mock the from_pretrained method to avoid network calls
def mock_from_pretrained(model_name, return_dict=True, load_in_8bit=False, device_map='auto', low_cpu_mem_usage=True):
    mock_model = Mock()
    mock_model.config = Mock()
    mock_model.config.hidden_size = 4
    mock_model.config.vocab_size = 256
    return mock_model

LlamaForCausalLM.from_pretrained = staticmethod(mock_from_pretrained)
MistralForCausalLM.from_pretrained = staticmethod(mock_from_pretrained)

ARGS = {
    'model_name': 'meta-llama/Llama-2-7b',
    'quantization': False,
    'model_type': 'llama'
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
torch, transformers — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type Mock — a Mock 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
load_peft_model Ran
ran; the contract check could not run (RAISES, DEP_MISSING or TIMEOUT)
microsoft/simulated-trial-and-error/llama-recipes/inference/model_utils.py
pointer only (licence: MIT); the stored copy get_code serves, from zhu-minjun/safetylock, is pointer only (licence: NONE) · get_code("6d5ba8546b6aad2c")
How it ran

The body of this sample is withheld: this paper's link allows the body inline (MIT), but get_code serves the stored copy, first harvested from zhu-minjun/safetylock, 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.

random_choose Ran
ran; the contract check could not run (RAISES, DEP_MISSING or TIMEOUT)
microsoft/simulated-trial-and-error/STE/utils.py
code served (permissive licence) · get_code("35aa73ace7771e74")
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 int; 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 numpy as np

# Set seed for reproducibility
np.random.seed(0)

# Construct arguments for random_choose
l = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]  # A list with more than num elements
num = 5  # Number of elements to randomly choose

ARGS = {
    "l": l,
    "num": num
}
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 int — 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
strip_end Ran
ran; our contract draft was wrong, not the code
microsoft/simulated-trial-and-error/STE/utils.py
code served (permissive licence) · get_code("ddfcf16bfe34d155")
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 strip_end(a, b):
    while a.endswith(b):
        a = a[:len(a) - len(b)]
    return a

ARGS = {
    "a": "hello_world_world",
    "b": "_world"
}
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
chat_my Not yet run
unverified (harvested, no recorded run)
microsoft/simulated-trial-and-error/STE/my_llm.py
code served (permissive licence) · get_code("8e1faaeb38a03d1c")
How it ran

no invocation recorded.

format_tokens Not yet run
unverified (harvested, no recorded run)
microsoft/simulated-trial-and-error/llama-recipes/ft_datasets/tool_dataset.py
code served (permissive licence) · get_code("0a6c3afab42d36ec")
How it ran

no invocation recorded.

format_tokens_single Not yet run
unverified (harvested, no recorded run)
microsoft/simulated-trial-and-error/llama-recipes/ft_datasets/tool_dataset.py
code served (permissive licence) · get_code("9c0d0d1ea3a973f6")
How it ran

no invocation recorded.

get_chat_completion_my Not yet run
unverified (harvested, no recorded run)
microsoft/simulated-trial-and-error/STE/my_llm.py
code served (permissive licence) · get_code("8808b039130caf65")
How it ran

no invocation recorded.

load_llama_from_config Not yet run
unverified (harvested, no recorded run)
microsoft/simulated-trial-and-error/llama-recipes/inference/model_utils.py
code served (permissive licence) · get_code("994fab6bf2f22a99")
How it ran

no invocation recorded.

prepare_tool_data Not yet run
unverified (harvested, no recorded run)
microsoft/simulated-trial-and-error/llama-recipes/data_proc_format.py
code served (permissive licence) · get_code("92809d0bd14c1523")
How it ran

no invocation recorded.

unwrap_model Not yet run
unverified (harvested, no recorded run)
microsoft/simulated-trial-and-error/llama-recipes/model_checkpointing/checkpoint_handler.py
code served (permissive licence) · get_code("b530360e413bc3fd")
How it ran

no invocation recorded.

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, 2 are also present in other papers whose code we hold (2 with at least one paper dated earlier, 0 the same month, 2 later) and 11 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
load_peft_model 7 other papers
4 dated earlier, 3 later
2308.10855 (2023-08)
LatEval: An Interactive LLMs Evaluation Benchmark with Incomplete Information from Lateral Thinking Puzzles
2310.02469 (2023-10)
PrivacyMind: Large Language Models Can Be Contextual Privacy Protection Learners
2310.06498 (2023-10)
A New Benchmark and Reverse Validation Method for Passage-level Hallucination Detection
and 4 more not named here
load_llama_from_config 6 other papers
3 dated earlier, 3 later
2310.02469 (2023-10)
PrivacyMind: Large Language Models Can Be Contextual Privacy Protection Learners
2310.06498 (2023-10)
A New Benchmark and Reverse Validation Method for Passage-level Hallucination Detection
2310.08491 (2023-10)
Prometheus: Inducing Fine-grained Evaluation Capability in Language Models
and 3 more not named here

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

Tools are essential for large language models (LLMs) to acquire up-to-date information and take consequential actions in external environments. Existing work on tool-augmented LLMs primarily focuses on the broad coverage of tools and the flexibility of adding new tools. However, a critical aspect that has surprisingly been understudied is simply how accurately an LLM uses tools for which it has been trained. We find that existing LLMs, including GPT-4 and open-source LLMs specifically fine-tuned for tool use, only reach a correctness rate in the range of 30% to 60%, far from reliable use in practice. We propose a biologically inspired method for tool-augmented LLMs, simulated trial and error (STE), that orchestrates three key mechanisms for successful tool use behaviors in the biological system: trial and error, imagination, and memory. Specifically, STE leverages an LLM's 'imagination' to simulate plausible scenarios for using a tool, after which the LLM interacts with the tool to learn from its execution feedback. Both short-term and long-term memory are employed to improve the depth and breadth of the exploration, respectively. Comprehensive experiments on Tool-Bench show that STE substantially improves tool learning for LLMs under both in-context learning and fine-tuning settings, bringing a boost of 46.7% to Mistral-Instruct-7B and enabling it to outperform GPT-4. We also show effective continual learning of tools via a simple experience replay strategy. 1 * Work done as an intern at Microsoft Semantic Machines.

For agents

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

get_harvested_code_for_paper("2403.04746")
get_code_for_paper("2403.04746")
have("2403.04746")

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

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

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

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

Connect an agent — have() is free.