MLGuerrillaStart M1 →
Free · in beta·intermediate·M18·58 min read·Prereq: The Model as a Component (M4). How LLMs Actually Run Things (M3) shows the tool-call round trip this module builds on. Data & State (M6) supplies the idempotency key, Harness & Reliability (M9) the retries and stop conditions, and AI Security & Guardrails (M10) the authorization and least-agency rules.

Tool Use

The capability

What tool use is

As you already know, a model can only output text, so it can't do things like look up an order or issue a refund by itself. Tool use is basically how it gets those things done. The model writes a request in a fixed format, where it names a tool and the arguments it wants to call it with. Then your code checks that request and runs the real function, and it sends the result back so the model can keep going.

Each request also carries an id, and your code uses that id to match each result to the request it answers when the model asks for several tools at the same time. Once the result comes back, the model can answer from it or ask for another tool, and if the result isn't enough to go on, it can ask the person a question.

M3 showed you the round trip in its simplest form, where a model asks for the weather in Paris and your code goes and fetches it. If you get the weather wrong, or fetch it twice, it doesn't cost anything. A refund is different, because a wrong amount or a second refund is real money, so a lot more has to happen between the model's request and the result. The refund in the figure goes through seven stages, and five of them run in your code.

A table of the seven stages of one tool call, with a column showing each stage on a refund and a column showing what the model gets back if that stage fails. Stage 1, request, belongs to the model and shows refund_invoice with id call_nm0uxo1b and arguments invoice_id in_3101, amount_rule unused_days, reason cancellation. Stages 2 to 6 are bracketed in terracotta as your code. Stage 2, parse and schema, checks that the JSON parses against the schema with both enums holding allowed values and no extra fields, and on failure returns invalid_argument with field amount_rule. Stage 3, meaning checks, confirms in_3101 exists and is this period's invoice and that sub_31 was already canceled now, and on failure returns subscription_still_active. Stage 4, authorize, checks the logged-in person is on the billing team and inside their refund limit, pointing to M10, and on failure returns not_permitted. Stage 5, execute, has code compute $150.00 and call the payment provider with the key refund-in_3101-unused_days, and on failure returns outcome_unknown, retryable true. Stage 6, result, sends ok true, refund_id re_001, amount $150.00 back paired to call_nm0uxo1b, and on failure sends the error as a result marked as an error. Stage 7, continue, belongs to the model, which reads the result and replies with the refund id while the harness caps the turns, and on failure the model reads the error and fixes the call or asks.
Stage 4 is the one this module leaves to M10. Sections 6 to 10 build the rest.

None of this makes the model understand your business. It picks a tool based on the name and description you wrote, and it fills in the arguments from whatever text happens to be in front of it. So if two tools have overlapping names, or an argument means something the description never mentions, even a strong model is going to call it wrong. Tool use doesn't make a call safe either. If a model gets refunds right 95% of the time, that's still one wrong refund in twenty, and whether that one costs money depends on the checks your code runs in stages 2 to 5, which the model never sees.

Why this is a capability of its own

M10 already decided who's allowed to call a tool and how much power each tool gets, and M9 already retries failed calls and caps how long a run can go. What neither of them covers is whether the model calls the right tool with the right arguments in the first place, and what it gets back when it doesn't. Getting those two things right is hard even for strong models. τ-bench is a benchmark where a model serves simulated customers of an airline and a retailer, and it does that with tools and a written policy. With function calling, gpt-4o succeeded on 61.2% of the retail tasks and 35.2% of the airline tasks, and the paper's abstract says agents "succeed on <50% of the tasks, and are quite inconsistent (pass^8 < 25% in retail)" (Yao et al., 2024). The airline tasks include cancelling reservations and giving refunds under the policy, which is pretty close to the example in this module. Those were mid-2024 models and newer ones may do better, but you should still take the inconsistency seriously, because it comes from the whole setup, tools and policy included, and a newer model doesn't change your tools.

Where it shows up

  • A coding agent that reads and edits files and runs the tests, like the one in M16 and M17.
  • An internal operations assistant that looks up accounts and changes them for a team, which is the example here.
  • A retrieval tool that searches a document store and returns passages, which M19 builds on.
  • An MCP server, which is a separate program that publishes tools any compatible agent can call, and that's how a lot of companies expose their product to agents now. Section 13 builds one for the billing tools.

The tools are different in each of these, but every one of them goes through the same seven stages.

Keep reading

The rest of this lesson is free with an account

Create a free account to read the remaining 18 sections. It takes about twenty seconds and there's nothing to pay. The same account opens the slide decks and CV reviews.

  1. 02The refund that came out $75 too high
  2. 03Call a tool when the answer needs data or an action the model doesn't have
  3. 04The model picks a tool from its definition and nothing else
  4. 05Draw each tool around one job the business already has a name for
  5. 06Schemas stop malformed calls, and your code checks what they can't express
  6. and 13 more

That's the last one written so far

Pick your next module from the board.

All modules →