Stop 15 · AI Agents & OrchestrationTopics · 4/9

Function/Tool Calling for Agents

Part of the AI Engineer Roadmap

In short

An LLM can't check train status or book a slot by itself. Tool calling lets it ask your code to do it, in clean JSON you can trust.

Giving an agent a defined set of callable tools (search, calculator, database query, API calls) it can invoke to accomplish tasks beyond pure text generation.

The blob dressed as a waiter hands a small order slip through a kitchen window to a cook.

Think of it like this

The waiter's order slip

The waiter doesn't cook. He writes 'Table 4: 2 masala dosa, 1 filter coffee' on a slip and the kitchen does the work. The LLM is the waiter: it writes a tool call slip, your code is the kitchen, and the plate goes back to the table.

Watch it happen

One tool call, start to finish

Your app
LLM
Rail API

Is 12951 late? + tools

1/6Your app sends the user's question along with the tool definitions the model may use.

The big ideas

What you need to know

Tools are JSON schemas

Each tool has a name, a description and a JSON Schema for its inputs. The model reads all three to decide when and how to call it.

Descriptions do the steering

Say when to use the tool and what the fields mean. A vague description gives wrong calls more often than a weak model does.

Your code runs the tool

The model only suggests a call. Validate arguments and check permissions before you run anything.

Parallel calls happen

Modern models may ask for several tools in one turn. Run them, then send back all results together.

See it in code

Walk through the code

json
1{2  "name": "get_train_status",3  "description": "Live running status of an Indian Railways train. Use when the user asks where a train is or if it is late.",4  "input_schema": {5    "type": "object",6    "properties": {7      "train_no": { "type": "string", "description": "5-digit train number, e.g. 12951" },8      "date": { "type": "string", "description": "Travel date as YYYY-MM-DD" }9    },10    "required": ["train_no"]11  }12}

1/3The name your code will match on, and a description that tells the model when to pick this tool.

A tool definition in Anthropic's format. OpenAI and Gemini use the same idea with slightly different wrapper keys.

Save yourself the pain

Common mistakes

Oops

Running whatever arguments the model sends straight into a SQL query or shell.

Do this instead

Treat tool arguments like user input. Validate types, check ranges and never build raw SQL from them.

Oops

Giving the model 40 tools with one-word descriptions.

Do this instead

Offer only the tools this task needs, each with a clear description of when to use it.

Your mission

Write and test one tool

~35 min

Quick check

The model returns a tool call for get_train_status. Who actually calls the railway API?

Go deeper

  1. 1Give an agent 2-3 real tools and observe how it decides which to call and when.
  2. 2Learn to write clear tool descriptions — the agent's tool selection is only as good as the description.
  3. 3Practice handling tool failures gracefully so the agent doesn't get stuck in a loop.

More topics at this stop

Stuck on this topic? Ask an Insider

Get 1:1 guidance from people who've walked this exact path — on the InsideEdge app.

Download
InsideEdge