Toolformer Explained: How LLMs Taught Themselves to Use Tools
Key Insights
- Toolformer is a language-model training approach introduced in a 2023 NeurIPS paper that teaches models when and how to call external APIs.
- Toolformer uses self-supervised learning to generate candidate API calls, execute them, and retain useful calls based on their effect on subsequent token-prediction loss.
- The original Toolformer paper examines five tool categories: a calculator, question-answering system, search engine, translation system and calendar.
- Toolformer differs from function calling, which enables structured function requests, and ReAct, which combines reasoning, actions and observations in an iterative workflow.
- Modern tool-augmented LLMs can use search, retrieval, calculators and APIs without necessarily following Toolformer’s original training method.
- Tool access can improve calculations and factual retrieval, but incorrect tool selection, unreliable outputs and faulty interpretation can still cause errors.
Large language models (LLMs) can generate fluent text but may struggle with precise arithmetic, factual lookup and tasks that require external information. The Toolformer paper, published by Meta AI researchers in 2023, explored how language models could learn to address these limitations by using external tools through APIs. Instead of relying entirely on human-labelled examples, Toolformer uses self-supervised learning to identify when tool calls improve a model’s predictions.
This approach offers an important perspective on what tool use in LLMs means and how tool-augmented language models can go beyond text generation. This article explains how Toolformer works, its training pipeline, the tools used in the original research, and how its approach compares with function calling and ReAct agents.
Your roadmap to becoming a Generative AI Engineer
See what you already know, what to learn next and how long the switch to a GenAI engineering role takes. Tap any step for what to study and build.
What's inside8 stages · 30 steps to job-ready
- Python & engineering foundations
- ML & deep learning essentials
- How LLMs work
- Prompting & building LLM apps
- RAG & model customisation
- Agents & tool use
- Production, evaluation & safety
- Portfolio & job readiness
Python & engineering foundations
What to study
- Core Python: data types, functions, classes, modules
- Virtual environments and package management (pip, uv)
- Writing clean, testable scripts
What to build
A command-line script that reads a CSV, cleans it and writes a summary report.
What to study
- SQL joins, aggregations and window functions
- pandas for cleaning and reshaping data
- Working with text data at scale
What to build
A notebook that cleans a messy text dataset and prepares it for a model.
What to study
- Git branching and pull requests
- How REST APIs work: HTTP methods, status codes, auth headers
- Reading and writing JSON
What to build
Call a public API from Python, handle errors and save the results as JSON.
What to study
- Vectors, matrices and dot products
- Probability and distributions
- Gradients and optimisation, intuitively
What to build
Implement cosine similarity and gradient descent from scratch in NumPy.
ML & deep learning essentials
What to study
- Supervised vs unsupervised learning
- Train/test splits, overfitting and evaluation metrics
- scikit-learn workflows
What to build
Train and evaluate a text classifier with scikit-learn.
What to study
- Tokenisation and text preprocessing
- Word embeddings and semantic similarity
- Sequence models (RNN, LSTM) and why transformers replaced them
What to build
Build a semantic search over 500 short texts using sentence embeddings.
What to study
- Layers, activations, loss functions and backpropagation
- Training loops, batching and GPUs
- PyTorch tensors and autograd
What to build
Train a fully connected network on a small dataset and plot its learning curve.
How LLMs work
What to study
- Self-attention and multi-head attention
- Encoder, decoder and encoder-decoder models
- Positional encoding and why scale matters
What to build
Walk through a minimal transformer implementation and explain each block in a short write-up.
What to study
- The Transformers library, model hub and datasets
- Running open-weights models locally
- Fine-tuning a pre-trained model for a task
What to build
Fine-tune a small pre-trained transformer for sentiment or topic classification.
What to study
- Closed vs open-weights model families
- Tokens, context windows, temperature and sampling
- Comparing models on cost, latency and quality
What to build
A comparison table of three models answering the same 20 prompts, with cost and latency.
What to study
- Quantisation, pruning and distillation
- When a small model beats a large one
- On-device and low-cost inference
What to build
Quantise an open model and compare its speed and quality against the original.
Prompting & building LLM apps
What to study
- System prompts, few-shot examples and chain-of-thought
- Prompt test sets and versioning
- Reducing hallucinations through prompt design
What to build
A prompt library with a 30-example test set and before/after scores.
What to study
- Calling LLM APIs: streaming, rate limits, keys
- Serving with FastAPI and simple UIs with Streamlit
- Caching and cost control
What to build
A small chat app with streaming responses, deployed for others to try.
What to study
- JSON schema outputs and validation
- Function / tool calling
- Retries and graceful failure
What to build
An invoice or resume parser that returns validated JSON.
What to study
- Chains, prompts and output parsers
- Document loaders and retrievers
- When a framework helps and when it gets in the way
What to build
Rebuild your chat app with LangChain and compare the code with your plain-API version.
RAG & model customisation
What to study
- Embedding models and similarity search
- Vector databases (e.g. pgvector, Pinecone, Weaviate)
- Chunking strategies and metadata filters
What to build
Index a document set in a vector database and query it with filters.
What to study
- Supervised fine-tuning vs prompting vs RAG
- LoRA and other parameter-efficient methods
- Preparing instruction datasets
What to build
LoRA fine-tune an open-weights model on a narrow task and compare it with prompting alone.
What to study
- Vision transformers and CLIP-style models
- Image captioning and visual question answering
- Combining text and image retrieval
What to build
An image search app that finds photos from a text description.
What to study
- The RAG pipeline end to end
- Re-ranking, hybrid search and citations
- Measuring retrieval quality
What to build
A document Q&A assistant that cites its sources, with a retrieval-quality report.
What to study
- Instruction tuning and reward models
- RLHF and DPO, conceptually and with TRL
- Where alignment fits in real products
What to build
Train a small reward model and run a preference-tuning loop on a toy task.
Agents & tool use
What to study
- ReAct, planning and reflection patterns
- Single-agent vs multi-agent setups
- Memory: short-term, long-term and retrieval
What to build
A research agent that searches, reads and summarises sources on a topic.
What to study
- Model Context Protocol (MCP) servers and clients
- Connecting agents to databases, CRMs and internal APIs
- Permissions and audit trails for tool calls
What to build
An MCP server that exposes two tools from a real API, used by your agent.
What to study
- Graphs, state and checkpoints
- Human-in-the-loop approvals
- Error handling in multi-step workflows
What to build
Rebuild your research agent as a LangGraph workflow with an approval step.
Production, evaluation & safety
What to study
- Docker images for AI apps
- CI/CD basics
- Secrets and environment configuration
What to build
Containerise your RAG assistant and deploy it with a CI pipeline.
What to study
- Building evaluation datasets
- LLM-as-judge and its limits
- Regression testing prompts and models
What to build
An eval harness that scores your assistant on 50 cases and runs on every change.
What to study
- Tracing LLM calls
- Tracking token cost and latency
- Dashboards and alerting
What to build
Add tracing and a cost dashboard to your deployed app.
What to study
- Managed model platforms on AWS, GCP and Azure
- Serverless deployment and autoscaling
- Data privacy and region choices
What to build
Deploy your app on one cloud using a managed model endpoint.
What to study
- Hallucination, bias and privacy risks
- Prompt injection and defences
- PII handling and content filtering
What to build
Add input and output guardrails to your assistant and document the risks you tested.
Portfolio & job readiness
What to study
- GenAI system design questions
- Explaining trade-offs: RAG vs fine-tuning, cost vs quality
- Coding rounds in Python
What to build
Mock-interview notes for three GenAI system design questions.
What to study
- Choosing a domain problem (healthcare, fintech, edtech)
- Writing clear READMEs and architecture notes
- Recording a short demo
What to build
A client-ready AI agent for one domain, with a public demo and write-up.
Fine-tuned text classifier
Adapting a pre-trained transformer to a real task.
Fine-tune a small pre-trained transformer on a labelled dataset, evaluate it properly and compare it with a classic ML baseline.
Structured data extractor
Turning messy documents into clean JSON.
Use an LLM API with schema-validated outputs to extract fields from invoices or resumes, with a prompt test set to track accuracy.
Document Q&A assistant
Retrieval-augmented answers with citations.
Index a document collection in a vector database and build an assistant that answers questions with cited sources and a retrieval-quality report.
LoRA fine-tune of an open model
Customising a model when prompting isn't enough.
Fine-tune an open-weights model with LoRA on a narrow task and document when it beats prompting and RAG, and when it doesn't.
Reward model & preference tuning
Teaching a model what good looks like.
Train a small reward model on preference data and run a preference-tuning loop, with a write-up of what changed.
Multimodal image search
Finding images from plain-language descriptions.
Embed images and text in a shared space and build a search app that retrieves photos from a description.
Tool-using research agent
An agent that plans, acts and asks for approval.
Build a LangGraph agent that searches, reads and summarises sources, calls tools through an MCP server and pauses for human approval.
Deployed GenAI service
From notebook to a monitored production API.
Containerise an LLM app, deploy it on a cloud platform with CI/CD, and add tracing plus a cost and latency dashboard.
Eval harness with guardrails
Proving your AI app works, and stays safe.
Create a 50-case evaluation set, automate scoring on every change, and add input and output guardrails against prompt injection and PII leaks.
Domain AI agent capstone
A client-ready agent for a real industry problem.
Pick a domain such as healthcare, fintech or edtech and ship an agent that combines retrieval, tools, evals and guardrails, with a public demo and write-up.
GenAI glossary 17 terms
Tap a term to see what it means. You will hear these in every GenAI interview.
- LLM
- Large language model: a neural network trained on huge amounts of text to predict and generate language.
- Transformer
- The neural network architecture behind modern LLMs, built around the attention mechanism.
- Token
- A chunk of text (often part of a word) that a model reads and writes. Pricing and limits are counted in tokens.
- Context window
- The maximum number of tokens a model can consider at once, including your prompt and its answer.
- Prompt engineering
- Designing instructions and examples so a model reliably produces the output you need.
- Embeddings
- Numeric vectors that capture meaning, so similar texts end up close together.
- Vector database
- A database built to store embeddings and find the most similar ones quickly.
- RAG
- Retrieval-augmented generation: fetching relevant documents and giving them to the model so answers are grounded.
- Fine-tuning
- Further training a pre-trained model on your own data to specialise it.
- LoRA
- Low-rank adaptation: a parameter-efficient fine-tuning method that trains small add-on weights instead of the whole model.
- Agent
- An LLM system that plans steps, calls tools and acts towards a goal, often over several turns.
- Tool calling
- Letting a model call functions or APIs, such as search or a database query, with structured arguments.
- MCP
- Model Context Protocol: an open standard for connecting AI applications to tools and data sources.
- Evals
- Systematic tests that measure how well an AI system performs on representative cases.
- Guardrails
- Checks on inputs and outputs that keep an AI system safe, on-topic and compliant.
- Hallucination
- When a model states something false or unsupported with confidence.
- Prompt injection
- An attack where malicious text tricks a model into ignoring its instructions.
Close your gaps with a structured programme
The Certificate Programme in Generative AI from CEP, IIT Delhi covers transformers, fine-tuning, RAG, agents and responsible AI through live weekend classes and hands-on projects.
What Is Toolformer: The Meta AI Research Approach
Toolformer is a language-model training approach introduced in Toolformer: Language Models Can Teach Themselves to Use Tools, a paper published at NeurIPS 2023. It trains a model to decide which APIs to call, when to call them, what arguments to provide and how to incorporate the returned results into subsequent predictions.
How Toolformer differs from a conventional LLM
A conventional LLM generates text by predicting tokens based on learned patterns and the context available to it. Toolformer extends this process by learning to insert API calls when external information or computation can improve its predictions.
For example, instead of generating an arithmetic answer from its learned patterns alone, the model can call a calculator and use the result in its subsequent text.
The important distinction is that Toolformer is a specific self-supervised training method, not a generic term for every AI model that can use tools.
What Problem Does Toolformer Solve?
Toolformer addresses the gap between generating plausible language and reliably performing tasks that require calculation, factual retrieval or specialised operations.
Why LLMs struggle with arithmetic, facts, and dates
Next-token prediction does not guarantee accurate arithmetic or access to current information. A model might produce an incorrect numerical result, rely on outdated knowledge or generate an inaccurate factual answer.
External tools for LLMs can provide capabilities that text generation alone may not reliably supply. A calculator can perform arithmetic, while a search engine can retrieve relevant information.
However, tool access does not eliminate errors. A model can choose the wrong tool, provide incorrect arguments or misinterpret a tool’s response. The challenge is therefore not simply connecting an API to an LLM; it is teaching the model when using that API is worthwhile.
How Does Toolformer Work?
How Toolformer works can be understood through three stages: generating candidate API calls, filtering them based on loss reduction, and fine-tuning the model on the retained examples.
Step 1 — Generate candidate API calls
The process begins with a language model and a small number of demonstrations for each API. Using these examples, the model generates candidate tool calls at selected positions in text, including the arguments needed to execute them.
The calls and their outputs are represented in the training sequence. This allows the researchers to examine whether adding a tool response improves the model’s ability to predict the text that follows.
This is the foundation of Toolformer self-supervised learning: the model generates candidate training examples rather than depending entirely on manually labelled tool-use decisions.
Step 2 — Execute calls and filter by loss reduction
The candidate API calls are executed to obtain their results. The model then evaluates the subsequent text with and without the returned tool information.
The Toolformer loss-reduction filter retains calls when including the tool response improves the prediction of subsequent tokens according to the paper’s criterion.
This step matters because not every available tool is useful for every sentence. A calculator call may improve a numerical prediction, while an unnecessary search call may add no meaningful benefit.
The filtering process helps identify tool calls that contribute to the training objective instead of treating every generated call as useful.
Step 3 — Fine-tune the model
The retained examples become self-supervised training data. The model is fine-tuned to predict both ordinary text and useful tool calls, learning patterns associated with when and how to use external capabilities.
During inference, the model can generate a tool call, the surrounding application executes it, and the result is made available for subsequent generation.
This pipeline distinguishes Toolformer from an approach that simply prompts an existing LLM to call an API.
Which Tools Does Toolformer Use?
The original Toolformer research examines five tool categories: a calculator, a question-answering system, a search engine, a translation system and a calendar. Each addresses a different limitation of language generation.
| Tool | Purpose | Example use |
|---|---|---|
| Calculator | Arithmetic | Computing a numerical result |
| Question-answering system | Factual retrieval | Answering a specific factual question |
| Search engine | Information retrieval | Looking up relevant information |
| Translation system | Language translation | Translating a phrase into English |
| Calendar | Date information | Checking the current date |
How tool selection depends on the task
Tool selection depends on the problem. A calculator tool in LLMs is useful for numerical operations, while search tools can help retrieve information that may not be present in the model’s available context. Translation tools support language conversion.
These are the tools examined in the original paper, not a comprehensive list of capabilities available to modern LLM systems.
Toolformer vs Function Calling vs ReAct Agents
Toolformer, function calling and ReAct address related aspects of LLM tool use, but they differ in how tool-use behaviour is established and executed.
| Aspect | Toolformer | Function calling | ReAct agents |
|---|---|---|---|
| Core idea | Learn useful tool calls through training | Generate structured calls to defined functions | Combine reasoning steps with actions and observations |
| Behaviour | Self-supervised examples and fine-tuning | Model uses available function definitions and schemas | Prompting or training supports iterative interaction |
| Execution | External API executes the call | Application executes the requested function | Agent framework executes actions and returns observations |
| Typical use | Research into learned tool-use behaviour | Structured API and application integration | Multi-step tasks requiring repeated tool interaction |
Function calling in LLMs allows an application to expose defined functions and process the model’s structured requests. For example, the OpenAI API — Function calling documentation describes how models can request external functionality and receive tool outputs through an application-managed workflow.
ReAct agents, introduced in a separate research paper, interleave reasoning traces with actions and observations to support iterative task-solving.
When to use each approach
Function calling is useful when an application needs structured, schema-defined requests. ReAct is suitable for workflows that require multiple action-and-observation steps. Toolformer is primarily a research contribution demonstrating how models can learn when tool use improves their predictions.
These approaches are not mutually exclusive. A modern agent can use function calling within a ReAct-style interaction loop.
What Does Toolformer Mean for Tool-Augmented LLMs Today?
Toolformer helped demonstrate how models could learn tool-use behaviour from self-generated examples. Its significance lies in the training method, rather than being the architecture behind every current tool-using system.
From learned tool use to modern LLM workflows
Contemporary tool-augmented LLMs can combine language generation with search, retrieval, calculators, databases and application APIs. Their implementations may rely on fine-tuning, structured function calls or orchestration frameworks.
These systems share the broader goal of extending an LLM beyond its internally generated text, but they do not necessarily use Toolformer’s original training pipeline.
Benefits and limitations
External tools can support precise calculations, factual retrieval and specialised operations. However, the overall workflow remains vulnerable to incorrect tool selection, unreliable outputs and faulty interpretation.
Execution costs, latency, permissions and validation also matter when deploying tool-using systems. Tool access should therefore be treated as one component of system design, not a universal solution to hallucinations or reliability problems.
Conclusion
Toolformer demonstrated a self-supervised method for teaching language models when to use external APIs and how to incorporate their results into subsequent predictions. Its candidate-generation pipeline, loss-based filtering and fine-tuning process distinguish it from broader approaches such as function calling and ReAct. Although modern tool-augmented systems use different architectures and orchestration methods, Toolformer remains a useful research example of extending transformer-based language modelling with external capabilities.
To explore these ideas further, the Generative AI programme by IIT Delhi, delivered through Varsity by InterviewBit, covers transformer foundations, RAG, Toolformer and modern agentic AI workflows. These topics help learners connect language-model fundamentals with the design of AI systems that use external tools.
Frequently Asked Questions
Who introduced Toolformer, and when was the paper published?
Toolformer was introduced by researchers including Timo Schick and colleagues in the paper Toolformer: Language Models Can Teach Themselves to Use Tools, published at NeurIPS 2023. The work demonstrated a self-supervised method for learning API use.
Is Toolformer an open-source LLM that I can use directly?
Toolformer is a published research approach, and third-party implementations exist. However, an implementation should not automatically be treated as the original model or an officially maintained Meta AI release.
Does Toolformer require large amounts of human-labelled tool-use data?
The original method uses a small number of demonstrations per API to generate candidate training examples. It then applies a self-supervised filtering process rather than requiring every tool-use decision to be manually labelled.
How does Toolformer decide whether an API call is useful?
It compares the model’s prediction loss with and without the tool response. Candidate calls are retained when the response improves prediction of subsequent text under the paper’s filtering criterion.
Can Toolformer use tools that were not included in its original training?
The original method trains around specified APIs and demonstrations. Supporting a new tool requires suitable integration and, depending on the implementation, additional examples or training; arbitrary new tools are not automatically supported.
Is Toolformer the same as retrieval-augmented generation (RAG)?
No. RAG retrieves relevant information to provide context for generation. Toolformer learns when to call APIs that can support different operations, including calculation, translation and retrieval.
Does Toolformer eliminate hallucinations in language models?
No. Tools can improve selected tasks, but a model may still make incorrect calls, receive unreliable results or misinterpret an output. Tool use requires validation and appropriate safeguards.
Can Toolformer perform multi-step tasks like an AI agent?
Toolformer learns tool-call behaviour within language generation. Multi-step agents commonly use explicit orchestration loops to select actions, process observations and decide what to do next. The approaches are related but distinct.
What computing resources are required to reproduce the Toolformer research?
Reproduction requires a suitable language model, implementations of the relevant tools, data processing and fine-tuning resources. The exact requirements depend on the model size and implementation.
Why is Toolformer important for GenAI engineers to study?
Toolformer provides a concrete example of connecting transformer-based language modelling with external APIs and using a self-supervised signal to learn when tool use improves predictions. It also helps clarify the distinction between training a model to use tools and building an application that executes tool calls.