AI Agents and Coding Assistants

How AI Agents Call Tools, Search Files and Use Other Software

Follow a tool call from request to result, see how agents search your files and run other programs, and learn which checks keep those actions safe.

Key takeaways

  • A tool call is a formatted request from the model that other software checks and carries out.
  • The model chooses tools by reading their names, descriptions and expected inputs, so unclear descriptions cause wrong choices.
  • File search can match exact words, match meaning or browse folder by folder, and each method misses different things.
  • Results return as text or images that the model interprets, which means errors and planted instructions can slip in.
  • Permissions, input checks and approvals belong in the software around the model, where they can be enforced.

An AI agent uses other software by writing a structured request that names a tool and supplies its inputs. Ordinary code receives that request, runs the tool and sends the result back to the model, which reads it and decides what to do next. The model proposes, and the surrounding program performs.

This mechanism is called tool calling, or function calling. It is how a system that produces text can end up searching a folder, querying a calendar or running a calculation.

The tool menu

Before an agent can use anything, the program running it gives the model a list. Each entry has a name, a description of what it does and a definition of its inputs. A weather tool might require a city and accept an optional date.

You can think of it as a menu with order forms. The model cannot order what is not listed, and each form says which fields must be filled in.

Descriptions carry real weight. Two tools called "search" with thin descriptions invite confusion. A description that says "searches only this year's invoices" helps the model avoid asking it for something older. When an agent keeps choosing badly, the menu is a good place to look.

Some applications load tools through a shared standard such as the Model Context Protocol, which lets one connector serve many apps.

One call, step by step

Here is a hypothetical exchange, written in simplified form.

user:    How many orders did we ship on Monday?
model:   call count_orders(status = "shipped", date = Monday's date)
program: check inputs and permission        (allowed: read only)
program: run the query
tool:    result: 42
model:   "42 orders were marked shipped on Monday."

Notice what the final sentence depends on. The model must pick the right tool, translate "Monday" into the right date, and read the result correctly. The tool must count what you meant by "shipped". A wrong date gives a precise, confident and useless number.

A good answer states its assumptions, such as which Monday and which status, so you can catch a mismatch.

The life of a tool call
Return Result is added to the model's context Run Tool does the actual work Choose Model picks a tool from the menu Request Writes the inputs in a set format Check Software validates and may ask you 1 2 3 4 5 Choose Model picks a tool from the menu 1 Request Writes the inputs in a set format 2 Check Software validates and may ask you 3 Run Tool does the actual work 4 Return Result is added to the model's context 5

Chains of calls

Real tasks usually need several calls, each built on the last. To answer "which customers from last month have not been sent a follow-up?", an agent might query the orders, search sent mail and then compare the two lists.

Some calls are independent and can run at the same time. Others must wait: the agent cannot look up an order until it knows the order number. The model manages this order as it goes, and mistakes in an early link pass down the chain. That is why errors compound over many steps.

Matching records between two sources is a frequent weak spot. One system lists "J. Rivera Ltd" and another "Rivera, J." The agent has to judge whether they are the same. Where an identifier such as an account number exists, ask it to match on that and to list the pairs it was unsure about.

When a call fails, a good agent reads the error and adjusts. A weaker one repeats the identical request, or quietly works around the gap and presents a partial answer as complete.

How agents search files

Agents have several ways to find things, and they often combine them.

Browsing. The agent lists folders, reads names and opens likely files. This is transparent and slow, and it depends on sensible naming.

Exact-word search. The tool finds files containing a given word or pattern. It is fast and precise for names, codes and error messages. It misses synonyms: a search for "refund" will not find a document that only says "money back".

Meaning-based search. Documents are split into passages and converted into embeddings, numerical representations that let software compare meaning. This finds related wording but may rank a vaguely similar passage above the exact one.

Structured queries. For databases and spreadsheets, the agent writes a query that filters and totals records. Results can be exact, provided the query matches the question.

A search returning nothing does not prove nothing exists. The file may be in an unsearched location, an unreadable scan or a format the tool skips. Ask the agent what it searched and how.

Running programs and calculations

Many agents can write a short program and run it. This is a strong technique for arithmetic, data cleaning and file conversion, because a computer executes the steps exactly. Calculating with code is more reliable than having a model produce digits from memory.

Exact execution is not the same as correct logic. A program can faithfully add the wrong column or silently skip rows with blank cells. Ask for a row count, a total you can compare and a look at a few records.

Running code should happen in a restricted environment, often called a sandbox, that limits which files and networks the program can reach. Without that, a mistaken or manipulated command could damage the machine.

Talking to other services

To use an online service, a tool usually calls its application programming interface, or API, a defined way for programs to request data and actions. The tool holds a credential, such as an access token, that determines what is permitted.

Where a service offers no suitable interface, some agents operate the visible screen or web page instead. That approach works with more software and is more fragile, as explained in how computer-use agents work.

Services can fail in routine ways: a login expires, a limit on requests is reached, a record is locked. A well-built tool returns a clear error. A poorly built one returns an empty result that looks like an answer.

When results mislead

Everything a tool returns goes into the model's context. Several problems follow.

  • Too much output. A huge result may be cut off, and the agent may not realize it saw only the first part.
  • Stale data. A cached page or an old export looks like current fact.
  • Ambiguity. A number without a unit or currency gets interpreted by guess.
  • Planted instructions. A document may contain text such as a request to send files elsewhere. A model can mistake it for a real instruction.

The last is called prompt injection. No known filter removes the risk completely, so the defense has to include limits on what the agent can do after reading untrusted material.

Guardrails that belong around the tools

Because the program runs every call, it is the right place for firm rules.

Control What it does
Allow list Only named tools and locations are reachable
Input validation Rejects malformed or out-of-range requests
Read-only default Changes require a separate permission
Approval prompt Pauses before sending, paying or deleting
Rate and spend limits Bound the damage from loops
Logging Records each call and result for review

An instruction in a prompt, such as "do not touch the archive", is helpful. A tool that cannot reach the archive is dependable.

Reading versus changing

It helps to sort tools into three groups. Tools that read return information and leave the world as it was, though they can still expose private material. Tools that change something reversible, such as editing a versioned document, can be corrected. Tools that commit the world to something, such as sending, paying, publishing or permanently deleting, cannot reliably be taken back.

Many sensible setups allow the first group freely within a defined area, log the second, and require approval for the third. The approval should show the exact inputs, because "send email" is harmless or serious depending on the recipients and the text.

Watch for tools that cross groups without saying so. A general "run command" tool can read, change or destroy depending on what is typed into it. So can a tool that submits web forms. Give broad tools like these only inside a restricted environment, or replace them with narrow ones that do a single job.

A tool's name is not proof of its behavior. Read the description and the permission it requests, and test it on harmless data first.

What to check as a user

You do not need to build tools to supervise them. When an agent gives you a result, open its record of calls if one is available. Confirm that it used the source you expected, with the dates and filters you meant. Look for errors it passed over. Spot-check one item against the original.

When setting up a new connection, read what it asks permission to do. If a tool that is meant to summarize your calendar also asks to delete events and send mail, find a narrower option or decline.

Finally, phrase requests so that the right call is easy to make. "Total shipped orders for the week of the 3rd, from the sales database, excluding returns" leaves far less to guess than "how did we do last week?"

Written for 4ArtificialIntelligence with AI writing tools and not reviewed line by line by a person. Check anything you rely on against a textbook or primary source. Report an error.

Keep reading

All 46 articles in AI Agents and Coding Assistants →

Latest news on this topic