Tool Use in Language Model Agents
- 79Unfamiliar
- 0Learning
- 0Familiar
- 0Mastered
What is a tool in the context of a language-model agent?
79 questions
- 1
What is a tool in the context of a language-model agent?
Model answer
A tool is an interface that lets a language model invoke an external computer program.
Explanation
A tool is the interface through which an agent invokes an external program or service.
- 2
Why can’t a language model use external programs on its own?
Model answer
A language model predicts tokens and cannot by itself invoke external programs or act on external systems.
Explanation
A language model generates tokens; without an external tool, it cannot directly perform actions outside that process.
- 3
How can tool calling be standardized while tools themselves perform very different tasks?
Model answer
Tool calls can use a standardized format, while the program or service invoked can perform many different tasks.
Explanation
The invocation method can be standardized even though the downstream tool’s purpose and behavior vary.
- 4
Distinguish extending a language model’s abilities from facilitating its abilities.
Model answer
Extension gives a model capabilities outside its own action space; facilitation delegates a task the model could do but can perform more efficiently through a tool.
Explanation
Extension adds capabilities beyond what the model can do internally; facilitation makes an internally possible task easier or faster.
- 5
Why does a model need an external tool to obtain information that became available after its training data?
Model answer
A model with frozen parameters cannot know new events or the current time from its training alone, so it must use an external source to obtain that information.
Explanation
A frozen model cannot learn events that occurred after its information cutoff unless it accesses an external source.
- 6
How can web search improve the freshness and grounding of a model’s answers?
Model answer
Web search retrieves current information that the model can use as fresh evidence when generating an answer.
Explanation
Searching supplies up-to-date evidence that can ground an answer rather than relying only on what the model learned previously.
- 7
Why might an agent use a calculator for a calculation the language model could perform itself?
Model answer
A calculator or Python can execute computations more quickly and reliably than having the model perform the calculation through its own reasoning.
Explanation
Tools such as calculators or Python carry out exact computations without requiring the model to reason through every arithmetic step.
- 8
What are two ways tools can connect a model to information or state outside the model?
Model answer
Tools can expose private or user-specific state to the model and can let it change an external environment through actions such as API calls.
Explanation
A tool can supply user-specific information or change something outside the model, such as making an API call.
- 9
Name several kinds of functions a language-model agent can access through tools.
Model answer
Examples include web search, a browser, a calculator, Python execution, and arbitrary APIs.
Explanation
Common tool functions include searching, browsing, calculating, executing code, and invoking APIs.
- 10
What are two ways an agentic loop can produce a final textual response?
Model answer
The agent can use a finish tool to return text, or the system can end the loop when the agent makes no tool call.
Explanation
A final textual response can be represented as a dedicated finish action or as the end of the loop when no tool is called.
- 11
What behavior distinguishes an agentic chat application from a text-only chat application?
Model answer
An agent can iteratively call tools to answer a query; this is why a tool-using application such as ChatGPT is more than a text-only chat interface.
Explanation
An agent iteratively makes tool calls to complete a request, rather than only returning a single text response.
- 12
What is retrieval-augmented generation, and how does web search commonly implement it?
Model answer
Retrieval-augmented generation retrieves information and uses it as context for answer generation; web search followed by answer generation is a common form of it.
Explanation
Retrieval-augmented generation retrieves context and then uses that context to generate an answer; this pattern has become common in chat applications.
- 13
How can a language model’s handling of a request for an image differ from simply forwarding the user’s wording?
Model answer
An image-generation tool produces image output, and the language model may expand the user’s prompt into a more detailed query before sending it to the tool.
Explanation
Image-generation tools work with images, and the model may expand a user’s short request into a more detailed prompt before making the tool call.
- 14
Give an example of how a custom function can let an agent act on an external service.
Model answer
A custom tool can invoke an API to carry out a specific task, such as adding requested items to a grocery cart.
Explanation
Custom functions can connect an agent to practical tasks, such as creating a grocery cart through a service API.
- 15
Why can code be considered a meta-tool rather than just another individual tool?
Model answer
A fixed tool list exposes specific API functions, while code can combine function calls with loops and other control flow, making it a more expressive meta-tool.
Explanation
A fixed tool list provides callable operations one at a time or, where supported, in parallel; code is unusually expressive because it can combine calls and control flow.
- 16
How do code structure and control flow make it possible to combine tool calls?
Model answer
Code organizes function calls into a program structure and can use loops and other control flow to coordinate them.
Explanation
A program can represent many function calls in a tree and use control flow to determine how they are combined or repeated.
- 17
How can libraries and custom utility functions expand the tools available to a programmatic agent?
Model answer
Importing a library such as pandas makes its functions available, while custom utility functions can add specialized operations.
Explanation
Libraries expose many additional functions, and custom utility functions can provide task-specific operations.
- 18
How can programmatic tool calling reduce interaction steps in a multi-step calculation task?
Model answer
A program can combine lookups, conversions, and calculations into one execution instead of requiring a separate agent turn for each operation.
Explanation
Instead of repeatedly calling separate lookup and conversion tools, a program can perform the sequence in one coordinated execution.
- 19
What results were reported for CodeAct compared with conventional step-by-step tool calling?
Model answer
CodeAct was reported to increase task success and reduce average interaction turns, even for tasks viewed as ordinary tool-use tasks.
Explanation
The described CodeAct research found higher success rates and fewer average interaction turns, including on tasks not traditionally categorized as coding tasks.
- 20
What risk do loops in agent-generated code create?
Model answer
An agent may write an infinite loop, so the execution system needs safeguards to stop or contain it.
Explanation
Expressive code can loop indefinitely, so systems need a way to detect or stop runaway execution.
- 21
Why can importing libraries pose security and maintenance risks for a programmatic agent?
Model answer
An agent might import a compromised library, exposing the agent and system to attack; library versioning is another concern.
Explanation
A compromised library can compromise the agent and potentially its surrounding system; dependency versions can also be difficult to manage.
- 22
What disadvantages follow from giving an agent the broad capabilities of code execution?
Model answer
Code is harder to constrain and validate because it has a broad action space, and it can consume excessive memory, disk, or CPU.
Explanation
A broad action space makes it harder to restrict and validate behavior, while code can consume substantial system resources.
- 23
Why should a system consider sandboxing when it enables programmatic tool calling?
Model answer
Programmatic tool calling may require a sandbox to isolate the agent and contain its actions and resource use.
Explanation
Because arbitrary code can have substantial effects on a system, execution should be isolated and resource use controlled.
- 24
How does a tool continuation differ from an ordinary text continuation?
Model answer
A text continuation produces text for the user, while a tool continuation produces a structured tool call for an external function.
Explanation
Tool calls are represented in the model’s output as structured tokens, unlike ordinary text continuations.
- 25
Can an assistant response contain both user-facing text and a tool call? Explain.
Model answer
An output can include a message for the user and a separate structured section containing the actual tool call.
Explanation
A single model output may contain user-facing text as well as the tool call that the agent is making.
- 26
What are the roles of the thinking, message, and tool-call portions of a reasoning model’s output?
Model answer
The output may contain hidden reasoning, a less verbose message shown to the user, and a structured tool call.
Explanation
Reasoning models may include verbose internal thinking, a shorter user-visible message, and a tool call in the same output.
- 27
Must tool-call tokens be included in a model’s vocabulary during initial pretraining?
Model answer
Not necessarily. Tool-call tokens are often introduced during mid-training, which follows pretraining and uses data in a desired format.
Explanation
Tool-call tokens are not necessarily included in the initial pretraining vocabulary; they are often introduced during mid-training or later training.
- 28
What does a model’s chat template do to system, user, and assistant messages?
Model answer
A chat template converts messages such as system, user, and assistant messages into the model’s formatted token sequence.
Explanation
A chat template turns structured messages into the special-token format expected by a particular model.
- 29
What information does a tool definition or schema provide to a model?
Model answer
A tool schema specifies the function name and its parameters, including details such as each parameter’s type and whether it is required.
Explanation
A tool definition describes the callable function and its arguments, including types and required fields, so the model can form an appropriate call.
- 30
Why can’t tool-call parsing code for one model format automatically be used for another?
Model answer
Different models may use different tool-call formats, so their outputs must be parsed according to the format used by that model.
Explanation
Model families may use different structured representations, so a parser or training setup for one format cannot be assumed to work with another.
- 31
What should be matched when fine-tuning a model that already supports tool calling?
Model answer
Fine-tuning should match the model’s trained tool-call format, and the model’s own chat template should be applied.
Explanation
Fine-tuning an already trained model should preserve the format it learned, and the appropriate chat template should be applied.
- 32
How does an agent framework connect a tool name in a model’s output to executable code?
Model answer
The system registers tools by name and maps each name to a function or other implementation that can be executed with the supplied arguments.
Explanation
A tool registry maps each tool name to its implementation so the agent can dispatch a parsed call to the right function.
- 33
Describe the main steps that occur after a model emits a tool call.
Model answer
The system parses the call, resolves the tool name, validates the arguments, executes the tool, and returns the result as an observation.
Explanation
A typical execution pipeline parses the call, finds the tool, validates the arguments, runs it, and returns an observation.
- 34
Distinguish a tool-call validation error from a tool-execution error.
Model answer
Validation can reject a malformed or incorrect call, while execution can fail when a syntactically accepted input cannot actually run, such as Python code that raises an error.
Explanation
A call may fail validation if it does not match the expected tool or arguments; execution can fail even when the input passes validation, such as invalid Python code.
- 35
Why should tool calls and their results have matching IDs?
Model answer
A call ID links a tool result to the corresponding call, which is particularly important when multiple calls run in parallel.
Explanation
Call IDs let the system associate each result with the request that produced it, especially when calls are made concurrently.
- 36
What can happen if an agent’s history contains a tool call with no matching tool result?
Model answer
A missing tool result can make the history invalid for some providers, so a system must preserve or recover the result before resuming the conversation.
Explanation
Some systems reject conversation histories that include a tool call without its corresponding result, so interrupted executions must be handled carefully.
- 37
Why can a language model’s tool-call output fail to parse even when it appears nearly correct?
Model answer
A generated call can have invalid syntax, such as incomplete JSON, and then a standard parser may fail to extract its arguments.
Explanation
A model’s tool-call output may be malformed, such as JSON missing a closing bracket, which prevents ordinary parsing.
- 38
What do syntax, shape, and type constraints check in a tool call?
Model answer
Syntax requires a valid representation, shape requires the expected fields, and types require each value to have the correct data type.
Explanation
Syntax checks whether the call can be parsed; shape checks required fields; type checks that values have the expected forms.
- 39
How can JSON Schema express constraints on tool arguments?
Model answer
A JSON schema can specify required fields, types, and allowed values, such as requiring a string for a city and restricting temperature units to Celsius or Fahrenheit.
Explanation
A schema can require a city string, specify allowable units, and mark the city field as required, enabling machine-readable validation.
- 40
How do regular grammars and context-free grammars differ in the kinds of tool-call structures they can represent?
Model answer
Regular grammars can be parsed with finite-state automata, but JSON Schema constraints are represented using context-free grammars rather than regular grammars.
Explanation
Regular expressions are regular grammars, which can be recognized by finite-state automata; JSON structures require richer context-free grammar representations.
- 41
Why is a pushdown automaton useful for validating nested JSON-like tool calls?
Model answer
A pushdown automaton adds a stack to track nested structure, allowing it to handle context-free grammar patterns such as nested JSON.
Explanation
Nested JSON structures require tracking context beyond a finite set of states; a pushdown automaton uses a stack for this purpose.
- 42
How does grammar-based constrained decoding guide the next-token choice?
Model answer
At each generation step, the decoder masks tokens that would violate the grammar, leaving probability only for valid next tokens.
Explanation
The system checks each next token against the grammar and masks invalid options, restricting generation to tokens that preserve a valid output path.
- 43
What happens to the model’s token scores when a candidate token violates the tool-call grammar?
Model answer
Invalid next tokens are assigned negative infinity in the logits, and the distribution is renormalized over the valid tokens.
Explanation
A token that violates the grammar is assigned an impossible score, after which the remaining token probabilities are renormalized.
- 44
Which token-validity decisions can be precomputed, and which must be checked in context?
Model answer
Always-valid or always-invalid tokens can be precomputed, while context-dependent token validity is calculated during decoding.
Explanation
Some tokens are always valid or invalid and can be precomputed; tokens whose validity depends on the current grammar or stack context are determined during generation.
- 45
What important limitation remains even when grammar-based decoding produces well-formed tool calls?
Model answer
Constrained decoding can ensure a call is well-formed according to its grammar, but it cannot guarantee semantic correctness, such as correct Python logic.
Explanation
Grammar constraints can ensure structural validity but cannot guarantee that the program’s logic or the call’s meaning is correct.
- 46
How can a token limit prevent constrained decoding from producing a complete valid tool call?
Model answer
The output can be truncated at the token limit before reaching a complete final state, leaving a partial tool call despite constrained decoding.
Explanation
If the model reaches its output-token limit while still on a valid but incomplete path, the result may be a partial structure rather than a complete valid call.
- 47
What kind of safeguard could address incomplete tool calls caused by output-token limits?
Model answer
A system could track the remaining token budget and manage generation so it does not end on an incomplete output.
Explanation
One possible mitigation is to account for remaining output tokens and stop or otherwise manage generation before the limit leaves an incomplete structure.
- 48
Why is a Python function in a local program not necessarily usable as a remote or standard tool API?
Model answer
A local function in a Python program can be used through programmatic tool calling, but it is not automatically callable remotely or through standard non-programmatic tool calling.
Explanation
A local Python function can be called from code execution, but it is not automatically a remotely accessible service or a standard function-calling endpoint.
- 49
How can FastAPI turn a Python function into an API that an agent can access?
Model answer
FastAPI can turn a Python function into a web API endpoint and can require an API key to authorize access.
Explanation
FastAPI can expose Python functions as web endpoints, with an API key used to control access.
- 50
What useful tool-calling information can FastAPI generate from an API definition?
Model answer
FastAPI can provide a JSON schema for an API based on its function and parameter definitions.
Explanation
FastAPI can derive a machine-readable schema from the endpoint’s function definition and argument types.
- 51
What are two ways to control or make a REST API call in an agent system?
Model answer
An API key can limit who may use an endpoint, and a coding agent can use curl from a shell to make a REST request.
Explanation
An API key can restrict access, while a coding agent with shell access can use curl to call a REST endpoint directly.
- 52
What purpose does the Model Context Protocol serve?
Model answer
The Model Context Protocol provides a standard way for an AI application to connect to MCP servers that expose tools and other context.
Explanation
MCP defines a standard protocol for connecting an AI application to additional context and tools through MCP servers and clients.
- 53
How does separating MCP credentials from upstream API credentials improve security?
Model answer
The MCP server can keep the sensitive upstream API key, while the agent uses a separate MCP credential to access the server.
Explanation
An MCP server can hold the upstream service credential, while the agent receives a separate credential for accessing the MCP server.
- 54
What security risk is reduced by withholding an upstream API key from the agent?
Model answer
A leaked MCP key need not expose the upstream service account because the MCP server, not the agent, holds the upstream key.
Explanation
If the agent leaks its limited MCP credential, the sensitive upstream credential remains protected on the server side.
- 55
Compare how REST APIs and MCP handle tool discovery and invocation.
Model answer
REST APIs commonly use OpenAPI for discovery and HTTP for calls, whereas MCP offers a tool-listing API and an MCP transport such as standard input/output or a socket.
Explanation
REST integrations commonly use an OpenAPI document for discovery and HTTP requests for invocation; MCP provides tool listing and its own transport options.
- 56
What can MCP provide beyond a set of callable tools?
Model answer
MCP can provide resources, prompts, and extensions in addition to tools.
Explanation
MCP can expose resources, prompts, and extensions as well as tools, providing conveniences beyond basic API calls.
- 57
What is FastMCP designed to do?
Model answer
FastMCP is a library for creating MCP servers simply, similar to how FastAPI simplifies creating web APIs.
Explanation
FastMCP is designed to make creating MCP servers simple in a way analogous to FastAPI for web APIs.
- 58
How can a developer discover MCP servers that provide particular capabilities?
Model answer
An MCP registry or directory can be used to find available MCP servers and browse them, including by popularity.
Explanation
MCP registries and directory sites help users discover available MCP servers, including by popularity.
- 59
When is it appropriate to execute tool calls in parallel?
Model answer
Independent tool calls can be issued in one response and run concurrently to reduce total waiting time.
Explanation
An agent can expose several tool calls in one response and execute them together when their results do not depend on one another.
- 60
Why can’t an agent parallelize a sequence in which each tool call depends on the previous result?
Model answer
Calls cannot be safely parallelized when later calls require earlier results, such as fetching orders using a customer ID and then refunding a selected order.
Explanation
A dependent sequence must wait for earlier results: for example, an order lookup needs a customer ID, and a refund needs the selected order.
- 61
Give an example of tool calls that could be run in parallel and state the condition that makes this valid.
Model answer
Weather, calendar, and flight-status requests can be parallelized if they are independent of one another.
Explanation
Independent requests such as checking weather, reading a calendar, and checking a flight can run together if none requires another’s result.
- 62
How might a Python agent execute several independent tool calls concurrently?
Model answer
A Python system can use asynchronous execution, such as asyncio.gather, to run calls concurrently and collect their results.
Explanation
Asyncio.gather is one common Python method for running multiple asynchronous calls and collecting their results.
- 63
Why might a more expensive language model be cheaper when measured by cost per completed task?
Model answer
A more expensive model can cost less per task if it solves tasks faster or makes better use of parallel tool calls, reducing the total work required.
Explanation
A stronger model may use fewer turns or make more calls at once, so the cost of completing a task can be lower even if each model call is more expensive.
- 64
How can reinforcement learning encourage a model to make more parallel tool calls?
Model answer
Reinforcement learning that strongly rewards brevity or rapid task completion can incentivize models to make independent tool calls in parallel.
Explanation
Recent reinforcement learning training has rewarded completing tasks quickly, making parallel calls a useful strategy for models to learn.
- 65
What is the main efficiency benefit of parallel tool use, and what limits that benefit?
Model answer
Parallel calls can reduce waiting time for independent operations, but dependent operations must still be performed in sequence.
Explanation
Parallel execution reduces elapsed time when calls are independent, but it cannot remove genuine dependencies between operations.
- 66
Why are call IDs particularly useful when tools execute concurrently?
Model answer
Matching IDs let the system associate each returned result with its call even when several calls execute concurrently.
Explanation
Call IDs remain important when concurrent calls return in a different order, because each result must be matched to its original request.
- 67
How did the Berkeley Function Calling Leaderboard’s scope evolve?
Model answer
The benchmark evolved from single-turn tool calling to also measure multi-turn calling, agentic tool calling, and tool-call robustness.
Explanation
The Berkeley Function Calling Leaderboard developed from single-turn calling to include multi-turn calling, agentic tool calling, and robustness.
- 68
What two basic aspects of a model’s tool-call decision can be evaluated?
Model answer
Evaluation can check whether the model selected a suitable tool and supplied the correct argument values.
Explanation
Choosing the appropriate tool and supplying the correct arguments are basic measures of whether the model can form useful calls.
- 69
What additional measures are useful when evaluating multi-step agentic tool use?
Model answer
Agentic tool-call evaluation can measure call order and end-to-end task accuracy.
Explanation
For agentic tasks, evaluation can test whether calls occurred in the right sequence and whether the full task was completed correctly.
- 70
What do efficiency and reliability measures assess in tool-use evaluation?
Model answer
Efficiency can be measured by time, tokens, or cost, while reliability can be measured by how appropriately the agent handles timeouts or unavailable tools.
Explanation
Efficiency includes time, token use, and cost; reliability includes handling failures such as timeouts or unavailable tools.
- 71
How can a tool-use benchmark assess safety?
Model answer
Safety evaluation checks whether the model avoids inappropriate tool use, including when faced with adversarial inputs or outputs.
Explanation
Safety evaluation tests whether a model resists using tools in inappropriate ways, including in response to adversarial requests or outputs.
- 72
What kinds of tool-call robustness can benchmarks measure?
Model answer
Robustness can be assessed by testing argument hallucinations and sensitivity to differences in tool-call formats.
Explanation
Robustness tests include hallucinated arguments and sensitivity to the tool-call format expected by a model or provider.
- 73
Why might the same model have different tool-call error rates when served by different providers?
Model answer
Tool-call error rates can differ across providers because they may use different inference implementations, decoding methods, or reliability practices.
Explanation
The same named model can produce different error rates across providers because serving implementations and decoding settings can differ.
- 74
How can differences in quantization contribute to different tool-call error rates?
Model answer
Quantization can affect tool-call accuracy; FP4 compresses more heavily and may produce more mistaken calls than FP8.
Explanation
Quantization changes how model weights are represented; heavier compression such as FP4 may cause worse tool-call performance than FP8.
- 75
How could speculative decoding affect tool-call reliability?
Model answer
Lossless speculative decoding should not change the model’s results, but lossy speculative decoding may change outputs and affect tool-call accuracy.
Explanation
Lossless speculative decoding should preserve the underlying model results; lossy speculative decoding can alter outputs and potentially affect tool calls.
- 76
How can differences in constrained decoding between providers affect tool-call errors?
Model answer
A provider using constrained decoding can restrict outputs to valid tool-call formats, while one without it may rely more heavily on the model’s unconstrained generation.
Explanation
Providers may differ in whether they implement grammar-based decoding that constrains generated calls to valid formats.
- 77
What is one provider-side cause of tool-call failure unrelated to the model’s reasoning?
Model answer
Provider outages or other service unreliability can cause tool-call failures independently of the model’s call quality.
Explanation
An inference service can fail or go offline, causing calls to fail even when the model generated an appropriate request.
- 78
Summarize the main stages in the layered tool-use system described in the lecture.
Model answer
Tool use is layered: tools add capabilities, schemas describe allowed calls, and the system validates and dispatches calls before matching results back to the conversation.
Explanation
Tool use forms a pipeline in which tools add capabilities, schemas guide calls, and the system validates, dispatches, and returns results.
- 79
Why are schemas and constrained decoding not sufficient by themselves to build a reliable tool-using agent?
Model answer
Schemas and constrained decoding help control call structure, while the agent system must still orchestrate execution, dependencies, concurrency, and evaluation.
Explanation
Schemas and grammar constraints control the structure of calls, but agents still need orchestration for dependencies, concurrency, and evaluation.

Ask anything
We've read this whole study set, so questions about it get the best answers.