InterviewKata
AI engineering · Module 06 of 21 · Level 2: Working with AI

Tools and function calling: how a model gets things done

A model on its own can only write text. It can't read your files, query a database or send an email. Tools change that, and they're the foundation of every agent, MCP server and AI feature that does real work. The trick is simple once you see who does what.

1. The idea

In a restaurant, the waiter doesn't cook. They listen to you, write an order ticket ("table 4: one dal, no chilli"), hand it to the kitchen, and bring back what the kitchen makes. The ticket is precise because the kitchen can't guess. That's exactly how a model uses tools.

Tool use, also called function calling, works in four steps:

  1. You describe the tools. Each has a name, a description (what it does and when to use it), and an input schema: the arguments it takes, written as JSON Schema.
  2. The model decides to call one. Instead of answering in prose, it replies with a structured request: the tool's name and the arguments, as JSON. That's the order ticket.
  3. Your code runs it. The model never executes anything. Your program calls the real function, API or database, with all the usual checks.
  4. You send the result back, and the model continues: it answers, or asks for another tool.

Some tools run on the vendor's side instead (server tools such as web search or code execution): you switch them on, and the vendor runs them for you. Either way, the model only ever asks; something else does.

2. How it works

The round trip. The model's only output is text: either an answer or a structured tool request. Your code is the only thing that touches real systems.

Step through a real exchange with an order-status tool. The JSON uses the Claude API's field names; the other APIs use the same shape with different names (see the table below).

APITool definitionThe model asksYou answer with
Claude (Messages API)name, description, input_schematool_use block (with stop_reason: "tool_use")tool_result block with the matching tool_use_id
OpenAI (Responses API)type: "function", name, description, parametersfunction_call item with a call_idfunction_call_output with the same call_id
Gemini APIFunction declaration: name, description, parametersA function call with name and argumentsA function result for that call

All three can request several tools at once (parallel calls), let you force or forbid tool use (tool_choice or its equivalent), and offer a strict mode that guarantees the arguments match your schema.

3. Try it yourself: be the model

You're the model. The app gave you these four tools; for each request, choose what to do. Getting this right is exactly what the description text in a tool definition is for.

4. Why it matters at work

Whether you write tools for a product, build an MCP server (Module 16), or just choose which ones to connect, the same rules apply. Anthropic's engineers reported spending more time on their tools than on their prompts when building their coding agent.

  1. Write descriptions for the model. Say what the tool does, when to use it, and when not to: "Look up an order by its number. Use when the customer gives an order number; don't use for refunds."
  2. Few, sharp tools beat many vague ones. Every definition is sent with every request (it costs tokens) and every extra tool is another chance to pick the wrong one.
  3. Return small, structured results. Ten relevant rows, not the whole table. Paginate. Include a hint if the result is cut off.
  4. Return useful errors. "No order 4821; order numbers have 5 digits" lets the model recover; a stack trace doesn't.
  5. Enforce permissions in your code, never in the prompt. Check that this user may see this order inside the tool. The model can be talked into anything (Module 18).
  6. Mark irreversible tools and confirm them. "Creates a refund. Irreversible." Have your app ask a human before running it.
  7. Treat tool results as untrusted data. A web page or document a tool returns may contain text that tries to give the model new instructions. That's prompt injection, and it's why the rules above matter.

5. In your five tools

Coding agents are tool use in action: reading files, searching, editing and running commands are all tools. Every tool lets you see the calls and decide which ones need your approval. Checked October 2026.

ToolSee its tools and callsControl approvals
Claude CodeEach tool call appears in the session; /status lists the active tools; /mcp shows connected servers/permissions: allow, ask or deny per tool or command
Antigravity CLICtrl+O toggles the detailed trajectory of each step; /mcp, /skills/permissions: request-review, always-proceed or strict
GitHub Copilot (VS Code)Tool calls appear in the chat; the tools picker in the chat input shows and toggles available toolsConfirmation prompts per tool; auto-approve settings for trusted tools and terminal commands
CursorTool calls appear in the agent chatRun modes and an allowlist for commands that may run without asking
Codex CLIEach command and edit appears in the session; /mcp for servers/permissions: approval and sandbox settings

6. Remember it

Memory hook: "The model writes the order; your code cooks"The model only ever produces a precise request. Your code decides whether to run it, runs it, and brings back the result.
How this hook works: what “The model writes the order; your code cooks” means

What the slogan means, phrase by phrase

“The model writes the order”
A tool call is text: a name and JSON arguments, like an order ticket. Writing it changes nothing in the world.
“your code cooks”
Your program (or the vendor, for server tools) is the kitchen: it runs the real function, with real permissions, and decides whether to run it at all.
Implied: the dish comes back to the table
The result goes back into the conversation, and the model uses it to answer or to write the next order.

Why this picture fits: it makes the most important safety fact obvious. A waiter can write a silly order; a good kitchen refuses it. All the control (permissions, validation, confirmation) lives in the kitchen, never in the waiter's good intentions.

The story → the concept

In the restaurantIn tool use
The menuTool definitions: names, descriptions, input schemas
The order ticketThe tool call: a name plus JSON arguments
A ticket the kitchen can't readArguments that don't match the schema (strict mode prevents these)
The kitchenYour code (client tools) or the vendor (server tools)
"Sorry, we're out of that"An error result the model can recover from
The manager approves a large orderHuman confirmation for irreversible tools
Bringing the dish backThe tool result, sent back to the model

Watch it on an example

A customer writes: "Refund order 48213, it arrived broken."

  1. The model writes an order: get_order(order_id="48213"). Your code checks this customer owns that order, then looks it up.
  2. The result comes back: delivered 2 days ago, £24.
  3. The model writes the next order: create_refund(order_id="48213", reason="damaged").
  4. Your code sees a tool marked irreversible and asks a support agent to approve it. The model never had the power to refund anything on its own.

The trap it saves you from

Thinking "the AI did it", and putting the guard rails in the prompt ("never refund over £100"). Prompts can be argued with; the kitchen's rules can't. Put the check in the tool.

It still works when…

You meet MCP (Module 10): it's a standard menu format, so any app can read any kitchen's menu. And agents (Module 07) are simply many orders in a row: order, dish, order, dish, until the job is done.

7. Common mistakes

Authorisation in the prompt instead of the tool"Only show the user their own orders" in a prompt is a suggestion. The tool must check the caller's permissions itself.
Vague names and descriptionsprocess(data) gives the model nothing to choose by. Name the action, say when to use it, and give an example input.
Dumping huge resultsA 5,000-row result fills the context and buries what matters. Filter, paginate and summarise in the tool.
Too many toolsDozens of overlapping tools confuse selection and cost tokens on every request. Merge, remove or load them on demand.
Unconfirmed irreversible actionsPayments, deletions, emails and deploys need a human approval step in your app.

8. Hands-on lab (30 minutes)

  1. Read a trajectory. Give a coding agent a small task and open its detailed view (expand the tool calls; Ctrl+O in Antigravity CLI). List every tool it called and why.
  2. Approvals. Open the permissions settings in two tools. Which tools run without asking, and which ask first? Would you change any?
  3. Write a tool definition. For one real action in your product, write the name, the description (when to use it, when not to) and the input schema. Run it through the "be the model" test: would a newcomer pick it correctly?
  4. Optional, with an API key: run the round trip yourself with the short example below, then add a second tool and ask a question that needs both.
import anthropic, json

client = anthropic.Anthropic()          # reads ANTHROPIC_API_KEY
tools = [{
    "name": "get_order",
    "description": "Look up one order by its 5-digit number. Use when the user gives an order number.",
    "input_schema": {"type": "object",
                     "properties": {"order_id": {"type": "string"}},
                     "required": ["order_id"]},
}]
messages = [{"role": "user", "content": "Where is order 48213?"}]
reply = client.messages.create(model="claude-sonnet-5-5", max_tokens=1024, tools=tools, messages=messages)

call = next(b for b in reply.content if b.type == "tool_use")         # the order ticket
result = {"status": "shipped", "eta": "2026-10-15"}                    # your code cooks (a real lookup goes here)
messages += [{"role": "assistant", "content": reply.content},
             {"role": "user", "content": [{"type": "tool_result", "tool_use_id": call.id,
                                           "content": json.dumps(result)}]}]
final = client.messages.create(model="claude-sonnet-5-5", max_tokens=1024, tools=tools, messages=messages)
print(final.content[0].text)                                           # "It shipped and should arrive on 15 October."

9. Self-check quiz

Who actually runs a client tool's function?

The model only writes the request. Your code executes it (or the vendor does, for server tools).

What does the model mainly use to decide which tool to call?

The model never sees your code. Names, descriptions and schemas are all it has.

Where should "users may only see their own orders" be enforced?

Prompts can be manipulated; the tool's own permission check can't be argued with.

Your tool keeps receiving arguments in the wrong shape. Which feature helps?

All three APIs offer a strict or validated mode that guarantees tool arguments match your JSON schema.

10. Go deeper

ResourceTimeWhy
Tool use with Claude (Anthropic)20 minThe round trip, client vs server tools, strict mode and pricing.
Function calling (OpenAI)20 minThe same ideas in the Responses API, plus built-in tools.
Function calling (Gemini)20 minParallel and compositional calling and calling modes.
Writing effective tools for agents (Anthropic)20 minHow to design, evaluate and improve tools an agent will use.