How AI agents call tools: function calls, arguments and errors explained

Updated · 5 min read

The loop, step by step

Tool calling follows the same loop every time. Your software describes the available tools to the model, and the model decides, step by step, whether to use one. Your code stays in control of every action that reaches your systems.

  • You describe each tool to the model with a name, a plain-language description and a list of arguments.
  • The model reads the task and decides whether it needs a tool. If so, it returns a proposed call, such as a lookup by email address, with the arguments filled in.
  • Your code receives the proposal and does not run it blindly. It checks the tool name, validates the arguments and confirms the caller is allowed to use the tool.
  • Your code runs the function and sends back the result, or a clear error.
  • The model reads the result and either calls another tool or writes the answer.

Why tool descriptions matter

The model chooses tools by reading their names and descriptions. A vague description leads to the wrong tool, or to no tool at all. Write each description as you would brief a new employee: what the tool does, when to use it, what it returns, and what it must not be used for.

Compare two versions of the same tool. The first is weak, and the second gives the model what it needs to choose well.

  • Weak: get_data. Returns data.
  • Stronger: get_invoice_status. Looks up one invoice by its invoice number and returns the status, amount and due date. Use only when the user gives an invoice number. Do not use it to search by customer name.

Validate arguments before anything runs

Models can produce arguments that look plausible but are wrong: a date in the wrong format, a customer ID that does not exist, or an amount with the wrong sign. Validate every argument against a schema in your code, reject anything outside the allowed range, and never pass raw model output straight into a database query or a shell command.

  • Check types and required fields.
  • Check values against allowed lists and ranges.
  • Confirm the record belongs to the user making the request.
  • Require a person to confirm any write action above a limit you set.

Errors, retries and how the agent recovers

Tools fail. A service times out, a record is locked, or the arguments were rejected. Return errors as plain, structured text that says what failed and why, so the model can try a corrected call or stop and ask a person. An opaque error or a raw stack trace invites the model to guess.

Set a limit on retries and on total tool calls per task. Without a limit, an agent can repeat the same failing call until cost or time runs out. Repeating an identical request rarely helps, so the design should change the input or escalate to a person.

Permissions and the principle of least power

Give each tool the narrowest access it needs. A tool that reads order status should not also be able to change orders. Separate read tools from write tools, and keep high-impact writes behind an approval step outside the model. Log every call, its arguments, its result and which user or agent triggered it.

What non-engineers should ask their builder

You do not need to write the code to manage a tool-calling project well. You do need clear answers to a few questions before anything touches live records.

  • Which tools does the agent have, and which of them write to our systems?
  • How are arguments validated, and what happens when validation fails?
  • What is the retry limit, and what happens when it is reached?
  • Where is each tool call logged, and how long is that log kept?
  • Which tool calls need a person to approve them?

How Hundred Seas helps

Hundred Seas is a product studio in Taipei that builds AI agents and AI CRM systems on Claude and on OpenAI models. Tool design decides much of an agent's safety and reliability, so we treat the tools, their permissions and the checks around them as part of the build, alongside the model choice on cost, speed, quality and where the data must stay.

The scope step takes about one week at a fixed price and ends in a written plan, a clickable prototype and a firm quote. The build follows in two to four weeks of weekly releases, and a monthly run plan keeps the tools, the logs and the software up to date.

Questions

What is a function call in an AI model?
A function call is a structured request that a model produces to run a named function in your software, with specific arguments. The model does not execute it. Your code receives the request, decides whether to run it, runs the function and returns the result. Many providers support this, and their current documentation shows the exact format.
Does the model run my tools itself?
No. It proposes calls, and your application or an agent framework executes them. This means the tools can only do what your code allows. Treat the model's proposal as untrusted input, the same way you would treat a form submitted by a member of the public.
Why does my agent pick the wrong tool?
The usual causes are vague tool names and descriptions, overlapping tools that do similar things, or too many tools offered at once. Rename tools clearly, narrow the descriptions, merge duplicates and remove any tool the task does not need. Then test with real requests and read the logged choices.
Should an agent have access to every system we run?
No. Expose only the actions the task needs, each with the narrowest permissions. Every extra tool adds another way for an agent to make a mistake, and another thing to review. Start with read-only tools, and add write tools one at a time after the logs show reliable use.
How do I test tool calling before it touches live data?
Run the agent against a test environment or copies of records. Create test cases with normal requests, missing fields, wrong types and conflicting data. Check that invalid arguments are rejected, that errors are handled, and that write actions stop at the approval step. Repeat the tests after every change to a description or a permission.

Have a project in mind?

Tell us what you want to build. We reply with a plan, not a sales call.

AboutHow AI agents call tools: function calls, arguments and errors explained