liveBook · Manning

Tool usage

As explained in Reinforcement Learning from Human Feedback

Tool use is a model capability in which generated interactions invoke external tools or services to perform tasks.

Tool usage extends a language model beyond its fixed weights. The model emits a structured request naming a tool and its arguments; an external orchestrator executes it, appends the result to context, and generation resumes. This supports current information, precise computation, and actions in external systems that a model alone cannot perform. section 13.0 section 13.6

Function calling is tool usage with declared function schemas, commonly JSON Schema, so arguments can be parsed and validated reliably. Code execution is a specialized case: the model sends code to an interpreter and uses its output rather than attempting a probabilistic answer from memory. section 13.0 section 13.1

Figure 13.1 Tool use interleaves model generation with external execution: the model generates tokens until it emits a tool call, an external system executes the tool and injects the output into the sequence, and then the model continues generating. Models can emit multiple tool calls in a single generation. Dur- ing training, tool call and output tokens are typically masked from the loss.
figure

The generation loop alternates model-produced text or calls with externally produced tool outputs. A single response can contain multiple calls; training commonly masks output tokens because the model did not generate them. section 13.2 section 13.5

A usable tool-calling pipeline needs the model and surrounding system to coordinate:

  • Declare available tools, descriptions, and parameter schemas in the prompt or message format. section 13.2
  • Train for call timing, tool selection, and correct argument formatting using tool trajectories; preference optimization can refine when a call is warranted. section 13.6
  • Execute each call outside the model, attach its result as a tool message, then let the model continue or make another call. section 13.2
  • Choose a consistent call representation, such as JSON or Python, and account for chat-template tokenization and context consumed by outputs. section 13.5

Precise Fibonacci computation

For a request for the 50th Fibonacci number, the model can decide to run a small loop, receive 12586269025 as tool output, and state that result. The key behavior is not predicting the number directly, but formatting executable input and grounding the response in returned output. section 13.2

More capable systems repeat the loop: reason about missing information, call a search engine or another tool, interpret the result, and call again if necessary. This interleaved thinking pattern supports multistep tasks, but it increases the importance of environment feedback, output management, and reliable call formatting. section 13.3 section 13.6

How Reinforcement Learning from Human Feedback covers it

How deep it goes
Explains orchestration, training objectives, formatting, masking, and multistep reasoning, while deferring detailed constrained-decoding mechanics.
Examples
Uses live-information search, file organization, pi calculation, movie search, Fibonacci code execution, and multistep web search.
What it assumes
Assumes familiarity with language-model generation and post-training, then defines tool calls and function schemas directly.
What you can do after
Build it from scratch by implementing a model-call, external-execution, tool-result, continuation loop.
How it connects
Connects function calling with code execution, RLHF, supervised fine-tuning, preference optimization, reinforcement learning, and Model Context Protocol.

Also explained in

Compare how 13 books explain tool usage →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Reinforcement Learning from Human Feedback. The section links point to the parts of the book it draws on.