AI Agents Engineering · Tool Use & Function Calling · Lesson 1 of 3
Function calling: the mechanism
A raw LLM only emits text. Function calling (aka tool use) lets it request an action: you describe tools (name, description, JSON parameter schema); the model emits a structured request to call one; your code executes it and returns the result; the model continues.
tools = [{
"name": "get_order_status",
"description": "Look up the status of a customer order by id",
"parameters": {
"type": "object",
"properties": {"order_id": {"type": "string"}},
"required": ["order_id"]
}
}]
# The model returns a tool call: get_order_status(order_id="A123")
# YOUR code runs it, returns the result, the model continues.The model never runs codeThe LLM only asks to call a tool — your runtime executes it. That is exactly where you enforce auth, validation, rate limits, and safety. Treat tool arguments as untrusted input.
Models can request parallel tool calls in one turn (e.g. three lookups at once) — your runtime executes them and returns all results before the next model turn.
◆ Lock it in
- Function calling = model emits a structured tool request; your code runs it and returns the result.
- Define tools with a JSON schema; the model picks the tool and arguments.
- Your executor is the security boundary — validate everything.
Feynman drill — say it out loudWalk through what happens, step by step, when an agent answers a question using a weather tool.
Step 1 rate your confidence · Step 2 pick your answer
In function calling, who executes the tool?
Step 1 — how sure are you?