CourseAgentic AI for Business
ModuleBuilding agents
Duration11 min
Progress0/12
Course material0/12 · 0%
  1. 1How a language model actually works10 min
  2. 2Prompting: turning intent into reliable instructions11 min
  3. 3Choosing your model9 min
  4. 4From chatbot to agent: the reasoning-action loop9 min
  5. 5Tools and function calling11 min
  6. 6Agent design patterns: beyond a single loop11 min
  7. 7Memory and knowledge: grounding agents with RAG11 min
  8. 8Building a knowledge base that retrieves well12 min
  9. 9Connecting to your systems: APIs, webhooks, and MCP10 min
  10. 10Guardrails, evaluation, and cost10 min
  11. 11Deploying an agent on a real workflow10 min
  12. 12Choosing what to automate: an ROI framework10 min

Lesson 5 / 12 · 11 min

Tools and function calling

How a model calls a function, how to design tools that are safe and reliable, and structured output.

Function calling is the mechanism behind every useful agent. You describe the tools available as structured definitions, the model decides when to use one and produces the arguments as data, and your code runs the actual function. Let us look at how that handshake works.

User asks
Modelemits tool call
Your codevalidate + run
Resultback to model
Modelanswers
The model never runs code; your system executes every call
The model never runs code. It emits a structured tool call, your code validates and executes it, and the result goes back to the model.

A tool is a typed contract

You give the model a name, a description, and a schema of the parameters (usually JSON Schema). The description matters as much as the code, it is how the model decides when this tool is the right one. Be specific about what the tool does and when to use it.

{
  "name": "create_lead",
  "description": "Save a new sales lead to the CRM. Use only after the
                  customer has shared a name and a contact number.",
  "parameters": {
    "type": "object",
    "properties": {
      "name":    { "type": "string" },
      "phone":   { "type": "string", "description": "E.164, e.g. +62812..." },
      "interest":{ "type": "string", "enum": ["website","ai","software"] },
      "budget":  { "type": "integer", "description": "IDR, optional" }
    },
    "required": ["name", "phone", "interest"]
  }
}
A tool definition. The model fills these fields with typed values; your code runs the real insert.

When the model decides to use it, it does not run anything, it returns a structured request like create_lead({ name: "Sari", phone: "+62812...", interest: "website" }). Your application validates those arguments, runs the database insert, and returns a result the model can read on the next turn.

Designing tools that do not break

  • One job per tool. A tool that does three things confuses the model about when to call it.
  • Validate everything the model sends. Treat its arguments like untrusted user input, because effectively they are.
  • Make dangerous actions explicit and gated. Refunds, deletes, payments should require a confirmation step or a human.
  • Return clear results, including errors. "out_of_stock" teaches the model more than a generic failure.
  • Keep the list short. Five sharp tools beat twenty overlapping ones.

Structured output

Sometimes you do not want a conversation, you want data. Most models can be constrained to return strict JSON matching a schema. This is how you turn free text into something a system can use: extract the order details from a chat, classify a message as complaint or inquiry, pull fields from an invoice. Structured output is the bridge between language and your databases.

What you take away

  • A tool is a name, a description, and a typed parameter schema
  • The model returns a structured call; your code validates and executes it
  • One job per tool, validate inputs, gate dangerous actions, return clear errors
  • Structured output turns free text into schema-clean data for your systems

Curated sources

Hand-picked references for going deeper, reviewed by our team.

Related Etzal serviceAutopilot: AI that runs your operationsPrefer it done for you? See how we help.
Tools and function calling - Agentic AI for Business | Etzal Academy | Etzal Group