GUIDES · AI AGENTS · 2026-10-13

Functions in AI agents: what they are, how to define them and why they fail

A function (also called a tool) is a specific action the agent can run: check a calendar, look up a product, create an invoice. The model does not execute anything by itself: it decides which function to call and with what data, and your system runs it. This is called function calling or tool calling.

How a function is defined

Every function has three parts. The agent decides using only what these three parts say, so every word counts.

PartWhat it isExample
NameShort, clear identifierbook_appointment
DescriptionWhen to use it and when not to"Books a confirmed appointment. Use it only when the customer already chose date and time."
ParametersThe data it needs, with type and formatdate (YYYY-MM-DD), time (HH:MM), service (closed list)

A full example in JSON Schema, the format Claude, OpenAI and MCP use:

{
  "name": "book_appointment",
  "description": "Books a confirmed appointment. Use it only when the customer already chose date, time and service. If any is missing, ask first.",
  "input_schema": {
    "type": "object",
    "properties": {
      "date": { "type": "string", "description": "Format YYYY-MM-DD" },
      "time": { "type": "string", "description": "Format HH:MM, 24 hours" },
      "service": { "type": "string", "enum": ["cleaning", "consultation", "checkup"] }
    },
    "required": ["date", "time", "service"]
  }
}

What happens when the agent calls a function

  1. The customer writes: "Do you have anything Thursday afternoon for a cleaning?"
  2. The agent decides to call check_availability with Thursday's date.
  3. Your system answers with the free slots.
  4. The agent offers options. It does not call book_appointment yet, because the customer has not chosen a time.
  5. The customer picks 17:00 and the agent calls book_appointment with all three fields.

If in step 4 the agent books without asking, you get an appointment nobody requested. That kind of error never shows up in a demo.

The 5 mistakes that break agents most

  1. Vague descriptions. "Manages appointments" does not tell the agent when to use it. Say when yes and when not.
  2. Look-alike functions. With create_appointment and book_appointment, the agent will mix them up. One function per action.
  3. Unspecified formats. "date" without a format yields "Thursday", "14/10" or "2026-10-14" at random.
  4. Free text where a list belongs. Use enum when the options are closed.
  5. Too many functions. Past 15 or 20, the agent chooses worse. Group them or split into specialized agents.

How to review your functions for free

AUN has a free schema review: it flags vague descriptions, parameters without a format and duplicate functions. To know how the agent behaves with real customers, the tool-call audit measures it on a hidden test and returns a fix that keeps names and parameters unchanged, so it does not break your integration.

Frequently asked questions

Are function, tool and tool call the same thing?

Yes. Each provider uses a different name, but it is the same idea: an action the agent can request.

What is MCP and how does it relate to functions?

MCP (Model Context Protocol) is a standard to publish functions once so any compatible agent can use them. See Security for skills and MCP.

How many functions should an agent have?

As few as possible for its job. Many customer-service agents work well with 4 to 8.

How do I know if my agent calls its functions correctly?

By measuring it with cases it has not seen. See Best tools to test AI agents.

Keep reading

Hire an agent → Measure my agent

Functions in AI agents (function calling) explained simply | AUN