Vibe Engines
YouTube

Vibe Engines is free, interactive AI engineering & system design — runs in your browser. Pick a learning path

~8 min readMeta · 2023

Toolformer,
explained.

A language model can write a sonnet about arithmetic and then get 17 × 24 wrong. It's fluent, but it has no calculator, no clock, no search bar — it only predicts words. Toolformer's idea was to hand it those things and, remarkably, to let it figure out on its own when to reach for them. No human labeling when to call a tool — the model learned that by asking a simple question: does calling this actually help me predict what comes next?

The delta

What changes against ReAct: the tool use is trained, self-supervised

Rung 1 gets tool use from a prompt at inference time, which means the model was never taught when a tool helps — it is being asked to improvise a judgement. This rung's change is to train that judgement in, and to do it with no human annotation whatsoever, which requires a criterion for whether a tool call was a good idea.

The criterion is the rung's whole content and it is unusually elegant. Take ordinary text. Insert a candidate API call at some position, execute it, and splice the result in. Then ask a purely mechanical question: does having that result make the text that follows easier to predict? If the call's answer lowers the loss on the subsequent tokens, it was useful; if not, it was noise. Keep the useful ones, discard the rest, and fine-tune on the surviving text with the calls in place.

Stated in the ladder's units: rung 1 needs a human to write a prompt describing when to use each tool, and this needs a corpus and an executor. The supervision signal is exactly the thing you want — a tool is worth calling when its result carries information the model did not already have — and it is free, because it is the model's own loss. Nobody has to decide in advance which sentences deserve a calculator.

01

What language models can't do alone

An LLM is a next-word predictor trained on frozen text. That makes it brilliant at language and unreliable at anything text-prediction doesn't guarantee: exact arithmetic (it approximates rather than computes), current facts (its knowledge stops at training time), precise lookups, and faithful translation. It will confidently produce a plausible-but-wrong number or an out-of-date fact.

Humans solve this by using tools — we reach for a calculator, a search engine, a reference. The obvious fix is to let the model do the same: call an external system that's actually correct at the thing the model is bad at. The hard part isn't the tools; it's teaching the model when to call them and what to ask, without hand-annotating thousands of examples.

02

The idea: put the call in the text

Toolformer's trick is beautifully simple: represent a tool call as just more text. Interrupt the generation with a special API-call notation, run the tool, splice its result back into the sequence, and carry on. To the model, a calculator call is a token pattern like any other — something it can learn to produce in the right spot.

A tool call, inline in the text
The population grew from 200 to [Calculator(200 × 1.5) → 300] people by 1990.

Because the call and its result live inline, the model reads the tool's answer as ordinary context and predicts the following words with it in hand. This framing means no new architecture is needed — teaching tool use becomes teaching the model to generate the right call text at the right moment, which is exactly what fine-tuning on the right examples can do.

03

The self-supervised filter

Where do the training examples come from if humans don't label them? This is the paper's real contribution. Toolformer generates its own data and keeps only what helps, judged by a single, elegant criterion: does the tool's result make the next words easier to predict?

Concretely, at many positions in ordinary text the model proposes candidate API calls. Each candidate is actually executed to get a real result. Then it checks: with the call's result inserted, is the model's loss on the subsequent tokens lower than it was without the call (or with a call whose result was withheld)? If the result genuinely helps prediction, the call is useful and is kept; if not, it's discarded. No human ever says "call the calculator here" — reduced prediction loss is the automatic label.

The key insight

"Was this tool call worth it?" gets an objective answer: keep the call only if seeing its result lets the model predict what follows more accurately. Usefulness becomes measurable, so tool-use training data can be generated without any human annotation.

Written out, the filter is one inequality. Keep the call only if its result cuts the loss on the following tokens by at least a margin τ, versus both not calling and calling-but-hiding-the-result:

The "withheld" term is the catch: the call must help because of what it returned, not just because a call is sitting there. The runnable version below applies exactly this test.

04

The three-step recipe

Put together, the method is a self-improving loop that starts from just a few hand-written example calls per tool:

1
Sample. Using a few examples, prompt the model to insert candidate API calls at many places in a large text corpus.
2
Execute & filter. Run each candidate call, and keep only those whose result lowers the loss on the following tokens.
3
Fine-tune. Fine-tune the model on this filtered dataset of useful calls, so it learns to call tools on its own.

The result is a model that, at inference, spontaneously emits an API call when it would help, pauses to let the tool run, reads the result, and continues — all learned, all self-supervised, from a tiny seed of examples.

05

The tools it learned

The paper equipped the model with five external systems, each an antidote to a known LLM weakness:

ToolFixes
Calculatorexact arithmetic
Search / Wikipedia + QAfacts & up-to-date knowledge
Machine translationother languages
Calendardate-aware queries ("today")

Each is something the model is unreliable at but a purpose-built system nails. And nothing about the method is specific to these five — any capability you can wrap in a simple API could, in principle, be learned the same way.

07

The limits

Toolformer's tool calls are essentially one-shot and independent — it doesn't learn to chain tools, use one tool's output as another's input, or run an interactive multi-step loop. That sequential, compositional tool use is what prompting-based agent frameworks such as ReAct — published a few months before Toolformer — were built around. Each tool also needs a handful of seed examples and its own integration, so adding tools isn't free.

And the self-supervised filter, while clever, is a heuristic: "lowers next-token loss" is a proxy for "is genuinely useful," and the two can diverge. The method works cleanly for tools with crisp inputs and outputs, and gets murkier for tools whose value is diffuse or hard to score against text prediction.

08

Why it still matters

Toolformer is a foundational step toward the AI agents that now define the frontier. It established the core idea underneath function calling and tool-using assistants: a language model can autonomously decide when to invoke external software and what to ask it. Every agent that searches the web, runs code, queries a database, or calls an API is exercising the capability Toolformer showed could be learned.

Its self-supervised angle is the lasting lesson — you don't have to hand-label tool use; let the model generate candidate calls and keep the ones that measurably help. Combined with reasoning (chain-of-thought) and interactive loops (ReAct), tool use turned the LLM from a closed oracle into an open system that can act on the world. Toolformer is where "the model can reach outside itself" began.

Read next

Pair with ReAct (interleaving reasoning and actions into multi-step agents) and the AI agent system design to see where tool use leads.

How it works

How Toolformer annotates CCNet with API calls and fine-tunes GPT-J

Toolformer turns a pretrained model into its own data generator. The base model M is GPT-J, with 6.7 billion parameters, and the text C is a subset of CCNet. The procedure runs once per tool, and the results are merged at the end.

prefix given to GPT-J loss on the next five tokens 29 % ) passed the no call (ε) Calc(400/1400), no result Calc(400/1400) → 0.29 L(ε) L(c, ε) L(c, r) weight w(t) = max(0, 1 − 0.2t) 1.0 0.8 0.6 0.4 0.2 L− = min(L(ε), L(c, ε)), L+ = L(c, r) keep the call if (L−) − (L+) ≥ τ
Toolformer's filter scores the same following tokens under three prefixes and keeps the call only if its result lowers the weighted loss by at least τ against both no call and the call without its result. Weights fall by 0.2 per token, so only the next five count. Bar heights are illustrative.
  1. Write a call as text. A call is a tool name and an input string, linearized as <API> Calculator(400 / 1400) → 0.29 </API>. In practice the markers are ordinary tokens, square brackets and an arrow, so the vocabulary does not change.
  2. Narrow the corpus per tool. Annotating everything is expensive, so heuristics pick likely text. For the calculator: documents with at least three numbers within 100 tokens where one is the result of an operation on two others, or phrases such as equals or total of followed by a number. For the calendar: documents whose URL yields a creation date, about 18 percent of them.
  3. Find where a call might go. A tool-specific prompt P(x) shows a few hand-written example calls. For every position i, the model's probability of opening a call there is computed; positions above a sampling threshold τs are kept, up to the top k.
  4. Sample candidate calls. At each kept position the model generates up to m calls, prompted with P(x), the text so far and the opening token, until it closes the call. Samples that never close are discarded.
  5. Execute them. Question answering is Atlas, a retrieval-augmented model fine-tuned on Natural Questions. Wikipedia search is BM25 over the KILT Wikipedia dump. The calculator does the four basic operations and rounds to two decimals. The calendar returns the current date. Translation is the 600M-parameter NLLB model into English, with fastText detecting the source language.
  6. Keep only calls whose answer helps. The filter measures the loss on the tokens after position i three ways: with the call and its result, with no call, and with the call but no result. The call is placed in front of the text as a prefix rather than at position i, because the untrained model has never seen a call mid-sentence, and splicing one in would raise its loss for the wrong reason. A call survives if the result beats the better alternative by τf; both thresholds are set per tool.
  7. Merge and fine-tune. Surviving calls are inserted at their positions to form C*, which holds exactly the texts of C plus calls, so fine-tuning should not shift the model's language distribution. GPT-J is fine-tuned on C* with batch size 128 and learning rate 1×10^−5, warming up over the first 10 percent of training.
  8. Decode with live tools. At inference the model decodes normally until it emits the arrow, meaning it expects a result. Decoding pauses, the API runs, the response and closing token are inserted, and generation resumes. In evaluation a call starts whenever the opening token is among the 10 most likely next tokens, not only the most likely, and each input gets at most one call so the model cannot loop.
The math

Toolformer's weighted loss and filtering criterion

Li(z) = − Σj=i^n wj−i · log pM(xj | z, x1:j−1)
Li^+ = Li(e(ci, ri)) · Li^− = min( Li(ε), Li(e(ci, ε)) ) · keep ci ⟺ Li^− − Li^+ ≥ τf
wt = w̃t / Σs w̃s, w̃t = max(0, 1 − 0.2·t)
  • z — the prefix placed before the text: nothing, the call alone, or the call with its result.
  • e(ci, ri) — the linearized call for position i together with the result it returned; e(ci, ε) is the same call with the result left empty.
  • wt — the weight on the token t places after the call position; it falls by 0.2 per token and is zero from the sixth token on.
  • τf — the minimum loss reduction, set per tool so enough examples survive.

The minimum inside L^− is the point. Comparing only against no call would credit calls whose text alone gives the answer away, such as a question that restates the fact; requiring the result to beat the bare call means the help has to come from what the tool returned. The weights decide where calls land: a result that only becomes useful six tokens later earns nothing, so surviving calls sit right before the words they explain. Set τf near zero and almost every harmless call survives; raise it and only calls whose answers are nearly copied into the next tokens remain.

The evidence

Toolformer against GPT-J and GPT-3, benchmark by benchmark

Every evaluation is zero-shot, with lenient scoring because the models are not told the answer format. The comparisons are GPT-J; Toolformer with calls disabled at inference, which separates what the fine-tuning taught from what the tools supply; and GPT-3 (175B), about 25 times larger. Tools that would make a task trivial were switched off: Wikipedia search on LAMA, whose facts come from Wikipedia, and the QA tool on the question-answering sets, since it was fine-tuned on Natural Questions.

BenchmarkGPT-JToolformer, calls offToolformerGPT-3 175B
LAMA SQuAD17.822.133.826.8
LAMA T-REx31.934.953.539.8
ASDiv7.514.840.414.0
SVAMP5.26.329.410.0
MAWPS9.915.044.019.8
WebQuestions18.518.926.329.0
Natural Questions12.812.617.722.6
TriviaQA43.946.748.865.9
Dateset3.95.927.30.8

The model learned when to call: the calculator on 97.9 percent of math examples, the QA tool on 98.1 percent of LAMA, Wikipedia search on 99.3 percent of the question sets. On math and dates, a 6.7B model with tools beats GPT-3 outright.

The losses are as instructive. Toolformer stays behind GPT-3 on all three question-answering sets; the authors blame a weak BM25 search engine and the model's inability to reformulate a query or browse past the top result. On the multilingual MLQA benchmark the translation tool helped in every language, but fine-tuning on CCNet hurt enough that Toolformer did not consistently beat plain GPT-J. On TempLAMA the gain did not come from the calendar, because the right strategy, a calendar call followed by a QA call, is ruled out by the one-call limit.

Language modeling was unharmed: with calls disabled, perplexity matched GPT-J fine-tuned on the same text without calls, 10.3 on WikiText and 10.5 on held-out CCNet. Size matters, though. Run on GPT-2 models of 124M, 355M, 775M and 1.6B parameters with three tools, the ability to use them only appeared at around 775M; smaller models scored about the same with and without tools.

Since then

What the authors admit, and what happened next

The method's shape constrains what it can learn. Each call has to be insertable into a span of text and independent — its usefulness is scored locally, against the next few tokens — so it cannot learn chains of dependent calls, where one tool's output determines the next tool's input and neither is individually useful. That is most of what a real agent does. It also needs a pass over the corpus per tool, and the tool set is fixed at training time.

How it held up: the practice went a different way. Tool use is now taught by instruction tuning on demonstrations of tool-calling conversations — including, at the top of the open-weights ladder, on synthesised agentic trajectories at enormous scale — which handles dependent multi-step calls that this method cannot express. So the recipe was superseded fairly quickly.

What survives is the criterion, and it deserves to outlive the paper. "Was this retrieval worth doing" is a question people usually answer with a human judgement or a benchmark, and this rung shows it can be answered mechanically by asking whether the retrieved information reduced the model's uncertainty about what it was about to say. That measurement is available in any system that retrieves anything, and it is still under-used.

SOLVE IT YOURSELF

Apply the loss-reduction filter

Toolformer's self-supervision is a single test you can run: does a tool call's result make the next tokens easier to predict? "Easier" means lower loss — negative log-likelihood of the true next token. This scores three candidate calls: a calculator returning the right number, one returning a wrong number, and a call on text that never needed a tool. Only the first survives, because only its result cuts the loss past the threshold. That filter is how a raw corpus becomes tool-use training data with zero human labels.

YOUR TASK

Write the body of keep_call. Everything else in the file is already written; this is the function the paper is about. Press ▶ Run to check it against the 5 assertions below — they start red.

WHAT IT HAS TO SATISFY — 5 ASSERTIONS
  1. Loss falls as the model gets more confident in the true token
  2. A correct tool result sharply lowers the loss vs no call
  3. The filter keeps a call whose result cuts loss past the threshold
  4. The filter drops a call whose wrong result does not help
  5. Withholding the result gives no benefit over not calling
CPython · WebAssembly
Questions

Questions people ask about Toolformer

What is Toolformer's filtering criterion for API calls?

A sampled call is kept only if it makes the following text easier to predict because of what the tool returned. Toolformer computes a weighted language-modeling loss over the tokens after the call position in three conditions: no call, the call with its result left empty, and the call with its result. The call survives if the loss with the result is lower than the better of the other two by at least a threshold that is set per tool. The weights fall linearly over the next five tokens, so the result must help almost immediately. Comparing against the empty-result call rules out calls whose question text alone gives the answer away.

Why does Toolformer score API calls as a prefix instead of inserting them mid-text?

Because the model used to judge them, GPT-J before fine-tuning, has never seen an API call in the middle of a sentence. Splicing one in at the candidate position would interrupt the text in a way that does not resemble its pretraining data, raising the loss on what follows and making useful calls look harmful. So during filtering the call and its result are given to the model in front of the text, and the loss is measured on the tokens after the position where the call would go. Only the calls that survive are inserted at their real positions, to build the fine-tuning set that teaches the model to make calls mid-text.

Did Toolformer beat GPT-3?

On some tasks decisively, and on others not at all. Toolformer, a 6.7B GPT-J model, beat the 175B GPT-3 on the LAMA fact-completion subsets (53.5 against 39.8 on T-REx), on math word problems (40.4 against 14.0 on ASDiv) and on the date questions of Dateset (27.3 against 0.8), all zero-shot. It lost on every question-answering set: 26.3 against 29.0 on WebQuestions, 17.7 against 22.6 on Natural Questions and 48.8 against 65.9 on TriviaQA. The authors attribute those losses to a simple BM25 search engine that often returns poor matches and to the model's inability to rephrase a query or look past the top result.

How large does a model have to be before Toolformer's tool use works?

In the paper's scaling test, about 775 million parameters. The authors applied the same recipe to GPT-2 models with 124M, 355M, 775M and 1.6B parameters, alongside the 6.7B GPT-J, using three tools: question answering, the calculator and Wikipedia search. Below roughly 775M the models scored about the same with and without tools, meaning they had not learned to use them productively. The exception was Wikipedia search, which even small models used to some effect, probably because it is easy to call. Larger models also got better without tools, but their ability to exploit the tools grew at the same time, so the gap between using and not using them stayed large.

Can Toolformer chain tools or use them interactively?

No, and the authors list this among its limitations. Calls for each tool are sampled independently over the corpus, so the fine-tuning data contains no example of one tool's output feeding another tool, and at evaluation each input was allowed at most one call so the model could not loop. It also cannot browse a search engine's results or refine a query. The authors add that the method is sample-inefficient for some tools, with more than a million processed documents yielding only a few thousand useful calculator calls, that the model is sensitive to the exact wording of its input when deciding whether to call, and that it ignores what a call costs.

Did Toolformer come before or after ReAct?

After. ReAct was posted in October 2022 and published at ICLR 2023; Toolformer was posted in February 2023. The two attack tool use from opposite ends. ReAct prompts a frozen model to interleave reasoning with actions at inference time, using hand-written example trajectories and no training at all. Toolformer trains the decision into the weights, using the model's own loss to label where a call is worth making, with no human annotation beyond a few example calls per tool. ReAct handles multi-step, dependent tool use that Toolformer cannot express, while Toolformer learns when a single call helps without being told.

Check yourself

4 questions to test what you just read

Work each one out before you open it — a number, a prediction or a reason, not a definition. Producing the answer is what makes it stick. Your progress is kept on this device.

With raw weights max(0, 1 − 0.2t), what normalized weight does the fourth token after a call (t = 3) get, and how much credit does a result that only helps at t = 6 earn?

Show answer

The raw weights for t = 0 to 4 are 1.0, 0.8, 0.6, 0.4 and 0.2, which sum to 3.0, so t = 3 gets 0.4 / 3.0 ≈ 0.13. At t = 6 the raw weight is max(0, −0.2) = 0, so the call earns nothing: the filter only rewards calls placed right before the words they explain.

A candidate call scores loss 2.0 with no call, 1.6 with the call but no result, and 1.3 with the result, and the threshold is 0.5. Is it kept, and what would happen if the filter ignored the no-result case?

Show answer

L− = min(2.0, 1.6) = 1.6, so the gain is 1.6 − 1.3 = 0.3, below 0.5: rejected. Against no call alone the gain would be 0.7 and the call would pass, even though most of that help came from the call's own text, not from the tool's answer.

Toolformer with calls disabled scored 14.8 on ASDiv, about twice GPT-J's 7.5, without making a single call. Why might training on calls help even when calls are blocked?

Show answer

The authors' explanation is that fine-tuning on many calculator calls and their results improved the model's own arithmetic. GPT-J fine-tuned on the same text without calls scored only 9.6, so the gain is not just extra training. Allowing calls then lifted the score again, to 40.4.

What would you expect from running the full Toolformer recipe on a 355M-parameter GPT-2 with the calculator, QA and search tools?

Show answer

Little or no gain. In the paper's scaling test, models below about 775M parameters scored about the same with and without tools, so a 355M model mostly fails to place useful calls or use their results. The partial exception is Wikipedia search, which even small models used to some benefit.

Where this sits

Agents that act

Give the model a tool, then a loop, then a memory, then a world. Ends on the 2026 paper measuring how badly the whole stack degrades over many turns.

  1. 1ReAct2023
  2. 2Toolformer2023
  3. 3Reflexion2023
  4. 4Voyager2023
  5. 5Generative Agents2023
  6. 6MemGPT2023
  7. 7LLMs Get Lost in Multi-Turn Conversation2026

All 110 papers, in 19 ladders →

Toolformer: Language Models Can Teach Themselves to Use Tools · Schick, Dwivedi-Yu, Dessì, et al. · Meta AI 2023 · read the original paper on arXiv → · Vibe Engines · 2026
Finished this one? 0 / 110 Paper Breakdowns done
NextReflexion Next on the “Agents that act” ladder · rung 3 of 7

Explore the topic

See this alongside everything else on the same subject — handbooks, system designs, challenges and tools, in one place.

More Paper Breakdowns