Toolformer

On this page 7

Toolformer is a language model, introduced by Meta AI researchers in 2023, that teaches itself to call external tools such as a calculator, a search engine or a translation system by inserting API calls directly into the text it generates. In the study of AI agents, Toolformer is a landmark because it showed that a model can learn when, which and how to use tools through self-supervised training, without large sets of human-written tool demonstrations.

The approach targets familiar weaknesses of language models, including arithmetic errors, outdated facts and poor handling of dates. Instead of making the model larger, Toolformer lets it delegate subtasks to specialized systems and continue writing with the returned result.

How Toolformer learns to insert API calls

Toolformer turns ordinary text into tool-augmented training data in three steps. First, the base model is prompted with a few examples to sample candidate API calls at promising positions in a large text corpus. Second, each candidate is actually executed, and its result is recorded. Third, a filter keeps only those calls whose results make the following text easier to predict.

The filter compares the model’s language modeling loss on the next tokens in three cases: with the call and its result, with no call, and with the call but no result. A call is kept only when the result lowers the loss by more than a threshold. The model is then fine-tuned on the original corpus enriched with these useful calls, so tool use becomes part of ordinary next-token prediction.

Calls appear inline in a simple text format, for example [Calculator(400 / 1400) → 0.29]. During inference, the model generates tokens until it emits the arrow symbol, the system pauses decoding, runs the tool and inserts the result, and generation resumes after the closing bracket.

StageInputOutput
SamplingPlain text plus a few-shot promptCandidate API calls at likely positions
ExecutionCandidate callsTool results paired with each call
FilteringCalls, results and loss valuesOnly calls that reduce prediction loss
Fine-tuningText with kept calls insertedA model that emits calls on its own
The three stages of Toolformer data construction

Tools used in the original Toolformer study

The original study fine-tuned GPT-J with 6.7 billion parameters and gave it five tools. Each tool covers a gap that is hard to close by scaling the model alone, and each has a text-in, text-out interface so its calls and results fit inside ordinary text.

ToolBackend typeGap it addresses
Question answeringRetrieval-augmented QA modelFactual knowledge
Wikipedia searchBM25 search over WikipediaUp-to-date and specific facts
CalculatorBasic arithmetic engineExact numerical results
CalendarCurrent date lookupTemporal reasoning
Machine translationMultilingual translation modelQuestions in other languages
Tools available to Toolformer and their purpose

The fine-tuned 6.7-billion-parameter model outperformed the much larger GPT-3 with 175 billion parameters on several math and factual question benchmarks. Its language modeling quality on text without tool calls stayed close to the original model, showing that the added skill did not damage general ability.

Toolformer compared with later tool-use approaches

Toolformer belongs to an early wave of tool-augmented language models and differs from the agent methods that followed in how tool use is learned and controlled. The comparison below places it among neighboring concepts in AI agents.

ApproachHow tool use is learnedInteraction styleTypical limitation
ToolformerSelf-supervised fine-tuningSingle inline callsNo chaining of tools
ReAct promptingFew-shot promptingInterleaved reasoning and actionsDepends on prompt quality
Function callingInstruction tuning on schemasStructured JSON callsRequires provider support
Model Context ProtocolStandard client-server interfaceDiscoverable tools at runtimeSecurity depends on server trust
CodeActPrompting or fine-tuningExecutable code as actionsNeeds a secure sandbox
Toolformer and related tool-use methods

Modern tool calling in commercial models relies more on instruction tuning with tool schemas than on Toolformer’s loss-based filtering. Nevertheless, the idea that a model should decide for itself when a tool helps strongly influenced how agent frameworks and training datasets were designed.

Limitations of the Toolformer approach

Toolformer has several structural limits that later research tried to remove. They follow mainly from the fact that each call is generated and judged in isolation.

LimitationCauseLater response
No tool chainingCalls are sampled independentlyAgent loops with multi-step plans
No interactive useOne call, one returned resultReAct-style observation cycles
Sample inefficiencyMany candidates are discardedSynthetic tool datasets and distillation
Prompt sensitivityWording affects call decisionsExplicit schemas and system prompts
No cost awarenessFilter ignores tool latencyPlanners that budget tool calls
Known limitations and how later work responds
  • Toolformer is not an autonomous agent. It inserts calls while writing text but does not pursue multi-step goals.
  • The tools are fixed at training time. Adding a new tool requires building new data and fine-tuning again.
  • Tool output is trusted without verification. A wrong search result is passed straight into the generated text.

The study also found that useful tool use emerges only at sufficient scale. Smaller models in the same family, below roughly one billion parameters, gained little from the procedure because they could not reliably judge when a call would help. This suggests that the self-supervised filter amplifies an existing capability rather than creating it from nothing.

For practitioners, the main lesson is architectural. Separating knowledge from computation lets a moderately sized model stay accurate on arithmetic, dates and facts, while the tools themselves can be updated, audited or replaced independently of the model weights.

Why Toolformer matters for AI agents

Toolformer showed that tool use can be treated as a learnable language skill rather than a hard-coded rule. This framing underlies today’s agents, which select among dozens of tools, read their outputs and decide on the next step. Its loss-based filtering also inspired later synthetic data pipelines that generate and verify tool-use examples automatically before training.

Stripped to the essentials

Toolformer is a language model that learned to ask for help. When it needs to multiply numbers, it calls a calculator. When it needs a fact, it runs a search.

Think of a student who knows when to grab a calculator or a dictionary. Nobody told the student every time. The student noticed that these tools gave better answers. Toolformer learned in the same way, by testing which tool calls actually helped.

Where it is applied

A research team at a university lab builds an internal assistant for financial reports. Their open-weight language model writes fluent summaries but often miscalculates growth rates and percentages. Following the Toolformer recipe, the team samples calculator calls in 200,000 report paragraphs, executes them, and keeps only the calls that lower prediction loss on the text that follows.

After fine-tuning, the model writes sentences such as “revenue grew by [Calculator((52.4 – 47.1) / 47.1) → 0.1125] 11.3 percent” on its own. In an internal test of 500 summaries, arithmetic errors drop sharply, while the writing style stays unchanged. The outcome is a more reliable assistant without a larger model, although the team still adds a human review step because the model cannot check whether its source figures are correct.