1. Home
  2. Explore
  3. Computer Science
  4. Tool Use in Language Model Agents

Study methods

Flashcards
Quiz
Fill in the blanks
Written test
Lesson
Notes
Podcast
Content

Tool Use in Language Model Agents

  • 85Unfamiliar
  • 0Learning
  • 0Familiar
  • 0Mastered
Topic: Tool Foundations
  • spaceFlip card
  • KI knew it
  • DI didn't know it
  • ←Previous card
  • →Next card

What is a tool in the context of a language-model agent?

Tap to flipClick to flipspace

A tool is an interface through which a language model can invoke an external computer program.

Or swipe the card

85 cards

  1. What is a tool in the context of a language-model agent?

    A tool is an interface through which a language model can invoke an external computer program.

  2. Why can’t a language model use external tools without an agent system?

    A language model is fundamentally a token-predicting machine and cannot invoke external programs on its own.

  3. What can be standardized about tool calling, and what can still vary?

    The method for making tool calls can be standardized, while the actions performed downstream by different tools can vary widely.

  4. What does it mean for a tool to extend a language model’s abilities?

    Tools can extend a model’s abilities by enabling actions or access to information outside its own capabilities.

  5. What does it mean for a tool to facilitate a language model? Give an example.

    Tools can facilitate tasks the model could do itself, but can perform more quickly or conveniently. For example, a calculator can multiply large numbers faster than a language model reasoning through them.

  6. Why might a language model need a tool to report the current time or other recent information?

    A model with frozen parameters and no access to current information cannot know facts that changed after its training data; an external tool can retrieve them.

  7. How can web search improve the grounding of a language model’s answer?

    Searching for current information can provide fresh evidence that grounds the model’s answer.

  8. What are two ways tools can connect a language model to information or actions beyond its own text output?

    Tools can let a model access private or user-specific information and make changes to an external environment.

  9. What are two ways an agent can produce a final textual response?

    A finish tool can signal that the agent is done and should return text. Alternatively, the agent can end its loop by choosing not to call another tool.

  10. What agent-like behavior distinguishes a tool-using chat application from a text-only chat interface?

    An agent makes iterative tool calls as part of answering a query; an application that does this is more than a text-in/text-out chat interface.

  11. What is retrieval-augmented generation, and how does web search use it?

    Web search retrieves information that the model can use to generate an answer. This is retrieval-augmented generation (RAG).

  12. Why might RAG be described as widely used even when users do not notice it?

    RAG has become a common, often unobtrusive part of applications: they retrieve context and generate answers based on it.

  13. What is code execution useful for in an agent?

    Code execution runs code to perform calculations or other operations, often more reliably and quickly than having the model reason through them itself.

  14. What is distinctive about image-generation tools, and how might an agent prepare their input?

    An image-generation tool produces images rather than primarily interacting through text. The model may expand or rewrite the user’s prompt before sending it to the image generator.

  15. Why might an image generated by an agent reflect a prompt different from the user’s original words?

    The prompt sent to an image generator may differ from the user’s original wording because the model can elaborate on the request before calling the tool.

  16. How can a custom function connect a natural-language request to an external service?

    A custom function can connect a request such as buying groceries to an external service, for example creating a grocery cart through an API.

  17. Name several common categories of tools available to language-model agents.

    Common tool capabilities include textual responses, web search, code execution, image generation, and custom functions or APIs.

  18. How does calling a fixed list of APIs differ from using code as a tool?

    A fixed tool list exposes individual APIs, often with one tool call per step; parallel calls can invoke multiple APIs in a step. Code offers a more expressive way to combine tool operations.

  19. Why can code be considered a meta-tool?

    Code is a meta-tool: a program can compose many function calls, use loops and other control flow, and express a richer procedure than a sequence of isolated calls.

  20. How can a program represent a structured sequence of tool operations?

    A program can be viewed as a tree of function calls, with loops and other control-flow structures organizing those calls.

  21. How can libraries and custom utility functions expand an agent’s tool capabilities?

    Using an external library can make its functions available to the agent as additional tools; custom utility functions can provide further specialized operations.

  22. How can programmatic tool calling simplify a multi-step task such as comparing prices across countries?

    For a multi-step task, a program can combine lookups, conversions, and calculations into one procedure instead of requiring the agent to make many separate calls.

  23. What benefits did CodeAct report compared with separate tool calls?

    The reported CodeAct results included a higher success rate and fewer average interaction turns, including on tasks traditionally treated as ordinary tool-use tasks.

  24. What is one risk of giving an agent the ability to write loops in code?

    Expressive code can create risks such as infinite loops, which may require system safeguards to stop or contain them.

  25. Why can letting an agent use external libraries create cybersecurity risks?

    A compromised library can compromise the agent and potentially the broader system, so library use and dependencies require care.

  26. What are some costs of giving an agent a broad code-execution capability?

    Code’s broad action space makes behavior harder to constrain, validate, and predict; it can also consume substantial memory, disk, or CPU.

  27. Why should code-executing agents be run in a sandbox or other containment system?

    Programmatic execution should be contained with safeguards such as a sandbox, especially because generated code can have broad effects on system resources and actions.

  28. How does a tool continuation differ from a text continuation, and can both appear in one output?

    A normal text continuation produces user-facing text, while a tool continuation produces a structured tool call. A model output can include both.

  29. How can a ReAct-style completion combine a user-facing response with an action?

    In ReAct-style output, the model can provide text to the user and include a tool call in the same completion; the tool call is the action to execute.

  30. What three kinds of content might appear in a reasoning model’s output?

    A reasoning-model output may include verbose thinking not shown to the user, a less verbose user-facing message, and one or more tool calls.

  31. When are tool-call formats often introduced if they were not included in initial pretraining?

    Tool-call tokens need not be present during initial pretraining on broad internet data; they are often introduced during mid-training on data in the desired format.

  32. How are chat messages represented to a language model?

    Chat formats represent system, user, and assistant messages with message structure and special tokens, even if the application supplies them as JSON-like objects.

  33. What information does a tool definition typically specify?

    A tool definition specifies details such as the function name, parameters, parameter types, and required fields. This structure can be included in the prompt as a tool schema.

  34. What does a model’s tool-call output provide to the agent system?

    A model may emit a call naming a function and supplying arguments, such as a weather function with a city argument.

  35. Why can’t an agent assume that one model’s tool-call parser will work for every model?

    Models can use different tool-call formats, so parsing code for one model’s format may not work for another’s.

  36. What tool-call format should you use when fine-tuning an already-trained model?

    When fine-tuning an already-trained model, match the tool-call format it was trained to use rather than expecting it to produce a different format.

  37. What does a model-specific chat template do, and why must the correct one be applied?

    A chat-template function formats messages according to the model’s expected format; the correct template must be applied for the model being used.

  38. What are the main steps in processing a tool call?

    A typical tool lifecycle parses the call, resolves the tool name to a registered function, validates the arguments, executes the tool, and returns an observation.

  39. How do tool-call validation errors differ from execution errors?

    Validation errors occur when the tool call or its arguments are invalid. Execution errors occur when a call passes initial validation but fails when run, such as invalid Python code.

  40. Why do tool calls and their results use matching IDs?

    Each tool call can have an ID, and its result carries the matching call ID. This associates results with calls, especially when calls run in parallel.

  41. What can happen if an agent history includes a tool call but omits its result?

    Some systems reject a conversation history that contains a tool call without its corresponding tool result, treating it as invalid history.

  42. What is one common syntax problem in generated tool calls?

    A model may emit malformed JSON, such as an object missing a closing bracket, which can cause a JSON parser to fail.

  43. What are the differences between syntax, shape, and type constraints on a tool call?

    Syntax means the output is parseable, such as valid JSON; shape means required fields are present; types means values have the expected types and units.

  44. How can a schema specify valid tool-call arguments?

    A JSON schema or similar schema can describe machine-checkable constraints, such as a required city string and an allowed temperature unit.

  45. What kind of grammar underlies regular expressions, and what machine can parse it?

    A regular expression is based on a regular grammar, which can be parsed by a finite-state automaton.

  46. Why can JSON-schema validation require more than a regular grammar?

    JSON schemas can express constraints that require a context-free grammar, which is more expressive than a regular grammar.

  47. What does a pushdown automaton add to a finite-state automaton, and why is that useful for JSON?

    A pushdown automaton extends a finite-state approach with a stack, allowing it to parse context-free structures such as nested JSON.

  48. How does grammar-based constrained decoding guide a model’s output?

    Constrained decoding checks possible next tokens against a grammar during generation, allowing only tokens that keep the output on a valid path.

  49. How can constrained decoding prevent invalid next tokens from being generated?

    Invalid next-token logits can be set to negative infinity, then the remaining logits are renormalized so probability is assigned only to valid next tokens.

  50. How can grammar-based inference systems handle tokens that are always valid versus context-dependent?

    An inference system can precompute tokens that are always valid or invalid and check context-dependent validity during generation.

  51. What does grammar-based constrained decoding typically ensure about generated tool calls?

    With a suitable schema and constrained decoding enabled, generated tool calls are usually well-formed according to the enforced grammar.

  52. How can a token limit cause incomplete JSON even when grammar-based decoding is enabled?

    A generation limit can stop the model while it is still on a valid grammar path but before it reaches a complete output, leaving partial JSON.

  53. What important kind of correctness does constrained decoding not guarantee?

    Grammar-based decoding can ensure structural validity but cannot guarantee that the tool call is semantically correct, such as that generated code does the right thing.

  54. What is a limitation of exposing a local Python function through programmatic tool calling?

    Programmatic tool calling can expose functions in a Python program for the model to call through code execution, but this approach is not inherently a remotely callable REST API.

  55. What can FastAPI provide when turning a Python function into a web API?

    FastAPI can turn Python functions into web endpoints, support API-key validation, and provide a JSON schema that can describe the API to a model.

  56. How can an API key help protect a web service?

    An API key can restrict access to a service, for example allowing only callers with the appropriate key to access a backend.

  57. How can an agent with Bash access call a REST API from the command line?

    A coding agent with Bash access can use a command-line tool such as curl to call REST APIs directly.

  58. What is MCP, in broad terms?

    The Model Context Protocol (MCP) is a protocol for connecting an AI application to tools and other context-providing capabilities through MCP servers and clients.

  59. How can MCP reduce the risk of exposing an upstream API credential to an agent?

    MCP can add a security layer by giving the agent an MCP credential while keeping the more sensitive upstream credential, such as a GitHub token, on the MCP server.

  60. Which credentials are used by the agent and by the MCP server in a typical MCP setup?

    The agent uses an MCP API key to authenticate with the MCP server; the server uses the upstream API key to access the external service.

  61. Why is it safer for an agent to receive an MCP credential instead of a sensitive upstream API key?

    Keeping an upstream key off the agent limits the damage if the agent leaks its own credential; the MCP credential can be made less harmful than the upstream key.

  62. How do API and MCP approaches differ in tool discovery and invocation?

    An API integration may discover capabilities through an OpenAPI document and invoke them over HTTP; MCP provides a tool-listing mechanism and uses an MCP transport.

  63. Name two possible transports for MCP communication.

    MCP communication can use transports such as standard input/output or a socket.

  64. What is FastMCP, and what are some MCP capabilities beyond tools?

    FastMCP is a library for building MCP servers; MCP can also offer resources, prompts, and extensions in addition to tools.

  65. What is the main benefit of parallel tool calling?

    Independent calls can run at the same time, reducing the delay of a sequence of tool calls that do not depend on one another.

  66. How can an agent request several tool calls in parallel?

    An agent can include multiple tool-call blocks in one response to request multiple calls at once.

  67. What condition must hold before tool calls can safely be parallelized?

    Calls can be parallelized only when they do not depend on one another. For example, looking up weather, a calendar, and flight status may be independent.

  68. Why can’t dependent steps such as finding an order and then refunding it all run in parallel?

    A workflow that must find a customer ID before fetching that customer’s orders, or select an order before refunding it, has dependencies that prevent those steps from all running in parallel.

  69. What Python mechanism can run independent asynchronous tool calls concurrently and collect their results?

    In Python, asynchronous calls can be collected with a mechanism such as asyncio.gather so they run concurrently and their results can be gathered.

  70. How can a more expensive language model be cheaper on a task-by-task basis?

    More capable models can sometimes cost less per completed task because they solve tasks more efficiently, including by making appropriate parallel calls.

  71. How can reinforcement learning encourage a model to make more parallel tool calls?

    Reinforcement learning that strongly rewards finishing tasks quickly can encourage parallel tool calling, because independent calls can be made together.

  72. How did the Berkeley Function Calling Leaderboard’s evaluation scope evolve?

    The Berkeley Function Calling Leaderboard (BFCL) evaluates tool calling across versions, evolving from single-turn evaluation to include multi-turn and agentic tool calling.

  73. What kinds of robustness does BFCL evaluate?

    BFCL includes tool-calling robustness measures such as hallucinated arguments and sensitivity to tool-call formats.

  74. What does tool-selection accuracy measure?

    Tool-selection evaluation checks whether the model chose a tool capable of carrying out the task.

  75. What does argument accuracy measure in tool calling?

    Argument evaluation checks whether the model supplied the correct values for a selected tool’s parameters.

  76. What additional aspects can be evaluated for agentic tool calling?

    For agentic tool calling, evaluation can check whether tools were used in the correct order and whether the overall task was completed correctly.

  77. What are common measures of tool-use efficiency?

    Efficiency can be measured through task completion speed, token use, and cost.

  78. What behaviors can be tested when evaluating tool-use reliability?

    Reliability evaluation can check whether the agent retries after a timeout or chooses an alternative when a tool is unavailable.

  79. How can tool-use safety be evaluated?

    Safety evaluation can test whether an agent resists adversarial requests to use a tool in an inappropriate way.

  80. Why might the same language model have different tool-call error rates across providers?

    Tool-call error rates can vary substantially for the same model depending on which provider serves it.

  81. How can quantization affect a model’s tool-call accuracy?

    Serving choices such as quantization can affect tool-call reliability. The lecture noted that FP8 models often make fewer tool-call mistakes than heavily compressed FP4 models.

  82. How can lossless and lossy speculative decoding differ in their effect on tool-call results?

    Lossless speculative decoding should preserve the underlying model’s results; lossy speculative decoding may change outputs and therefore affect tool-call errors.

  83. How can differences in constraint decoding across providers affect tool-call reliability?

    Providers may use different constraint-decoding systems; if grammar-based decoding is absent, successful tool calls depend more heavily on the model producing the correct format unaided.

  84. Why might two providers support different constrained-decoding behavior for the same model?

    Inference providers may implement their own systems or use open-source engines, and those systems may support different grammar-based decoding methods.

  85. What is a non-model reason that a tool call may fail?

    A provider outage or other inference-service failure can cause a tool call to fail even if its format and intended arguments are correct.

Card 1 of 85
Card 1 of 85

Ask anything

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

FlashcardsQuizFill in the blanksWritten testLessonNotesPodcastContent