L−
i − L+

i ≥ τf

holds, i.e., adding the API call and its result reduces
the loss by at least τf , compared to not doing any
API call or obtaining no result from it.
Model Finetuning After sampling and ﬁltering
calls for all APIs, we ﬁnally merge the remaining
API calls and interleave them with the original
inputs. That is, for an input text x = x1, . . . , xn
with a corresponding API call and result (ci, ri) at
position i, we construct the new sequence x∗ =
3We provide e(ci, ri) as a preﬁx instead of inserting it at
position i because M is not yet ﬁnetuned on any examples
containing API calls, so inserting it in the middle of x would
interrupt the ﬂow and not align with patterns in the pretraining
corpus, thus hurting perplexity.

Figure 3: An exemplary prompt P (x) used to generate
API calls for the question answering tool.

M itself on this dataset. Each of these steps is
described in more detail below.
Toolformer