Tools and Function Calling for Agents
An agent's environment is defined by its use case, such as a game, the internet, a kitchen, or a road system.
A Question to Ask About Any Agent
Suppose you are handed an AI agent and asked what it is able to do. Two questions come up almost immediately. The first is where it operates: what world does it perceive and affect? The second is what it can actually do inside that world. These two questions are linked. The world an agent works in shapes the things it could possibly do, and the things it is equipped to do shape how much of that world it can reach.
What do you think happens?
A model that only produces text is placed in a conversation. What is the full set of actions it can take in the world?
Reveal answer
It can only produce text, which is a small set of possible actions.
A model that only produces text has a small set of possible actions. Giving it tools adds to that set, which is the central idea of this article.
The Environment Follows the Use Case
An agent's environment is defined by its use case. The easiest way to see this is to ask, for each agent, what it is supposed to act upon. An agent built to play a game has that game as its environment. An agent that scrapes documents from the internet has the internet as its environment. A cooking robot works in a kitchen. A self-driving car works in the road system and the areas beside it.
The environment of an agent is the world it perceives and affects. It is fixed by the agent's use case: the job the agent was built to do determines which world it is working in.
Once the environment is fixed, it determines which tools an agent could potentially use. A chess game is a useful case. The only possible actions for an agent inside it are the legal chess moves. Nothing outside the rules of the game is available to it. The environment, in other words, sets the boundary of what actions even make sense.
How Tools Widen and Narrow the Agent's Reach
The relationship runs in both directions. The tool inventory an agent carries restricts which environments it can actually work in. Consider a robot whose only action is swimming. It is confined to a water environment, because on land it has nothing it can do. The tools fix the reachable world just as the world fixes the usable tools.
Tools also expand what an agent can do. A model that only produces text has a small set of possible actions, and each tool adds a new one. Many generative AI applications people use every day are agents with access to tools, although many of those tools are simple. ChatGPT can search the web, run Python code, and generate images. Each of these capabilities is an action that is unavailable to a model with no tools at all.
Retrieval-augmented generation (RAG) systems follow the same pattern. A RAG system can be viewed as an agent whose tools are a text retriever, an image retriever, and a SQL executor. Each tool is a specific capability the agent can call on.
A coding agent called SWE-agent, built on top of GPT-4, shows both ideas together. Its environment is a computer with a terminal and a file system. Its set of actions includes navigating a repository, searching files, viewing files, and editing lines. The environment supplies the places where those actions apply, and the actions are what let the agent change that environment.
The Loop of Calling a Tool
An agent is typically given a task by a user. It does not simply return one answer. It processes the task together with feedback from its environment, plans a sequence of actions, and decides when the task is finished. The diagram below shows the path a single tool call takes. The agent's decision goes out to a tool, the tool acts on the environment, and the result comes back to the agent so that it can make its next decision.
The key point in the diagram is the return arrow. The agent goes back to reasoning after every tool call. Its next move depends on what it just learned, not only on the original request.
Tracing a Multi-Step Sales Task
To see the loop in action, take a RAG system working with tabular sales data. It has three actions: generating a response, generating a SQL query, and executing a SQL query. Given the request to project sales revenue for a product over the next three months, the agent carries out a sequence of moves. Each move is a choice based on what the agent has just seen.
Tracing the Decisions in the Sales Run
The user asks the agent to project sales revenue for a product over the next three months. Trace what the agent does from the request to the final answer, identifying where it decides to stop and where it decides to keep going.
- 1Plan the first move
The agent reads the request and decides it needs historical sales figures. It generates a SQL query, which is one of its three actions.
- 2Execute and observe
The agent executes the SQL query. The database returns rows, and the agent receives this output as feedback from the environment.
- 3Judge sufficiency
The agent decides whether the rows are enough to make a projection. In this run, the first round of results is judged insufficient, so the loop continues instead of answering.
- 4Issue a second round of queries
The agent generates and executes further queries. This second round exists only because the first round's output was judged insufficient.
- 5Decide the task is complete
Once the agent judges that the information is enough, it generates the response with the projection and stops. The judgment about completion is part of the loop itself.
The agent reaches a projection through a chain of query, observation, and judgment moves. The number of moves is not fixed in advance; it depends on what each result reveals.
The sales run described in the source had seven reasoning-and-action moments. Each one is a place where the agent can go wrong. A query can be malformed, a result can be misread, or a plan can be poor. This is the reason the next part of the article matters.
The Agent Decides When It Is Done
Two details in the sales run are worth noticing. The first is that the agent judges its own progress. It decides when the information is enough and when the task is complete. The second is that this judgment is part of the loop, not an afterthought. The source describes this as the AI component deciding whether the task has been accomplished, which is what allows the agent to stop.
Compound Mistakes Across Steps
Because an agent needs many steps, its overall accuracy depends on how the individual steps combine, not only on how good any single step is. This is called the problem of compound mistakes. The diagram below shows the chain. Each step must succeed for the run to stay on track, so the chance of a fully correct run shrinks as the chain grows.
The source gives a concrete case. If a model is 95% accurate per step, then over 10 steps the overall accuracy drops to about 60%, and over 100 steps it falls to about 0.6%. The table below lays out those figures so you can see how quickly the trend bends downward.
| Number of steps | Per-step accuracy | Overall accuracy (approx.) |
|---|---|---|
| 1 | 95% | 95% |
| 10 | 95% | 60% |
| 100 | 95% | 0.6% |
Overall accuracy when each step is 95% accurate and the steps must all succeed
The pattern matches multiplying the 95% figure by itself once for each step: $0.95^{10} \approx 0.60$ and $0.95^{100} \approx 0.006$. A small per-step error rate, repeated over many steps, adds up to a large chance that something has gone wrong somewhere along the way.
The formula assumes each step succeeds or fails independently of the others. The source presents the compounding as the mechanism behind the drop in accuracy; it does not claim the same exact numbers apply to every agent or every task.
Why Agents Need Stronger Models
Compared with non-agent uses of a model, agents typically require more powerful models. The source gives two reasons. The first is the compound-mistake effect just described. The second is that agents with access to tools can perform more impactful tasks, but any failure could carry more severe consequences. A text answer that is wrong can be ignored. An action that is wrong may have already changed something in the environment.
Cost works in the other direction too. A task that requires many steps takes time and money to run. The source argues that this cost can still be worthwhile, because autonomous agents can save a great deal of human time. Whether an agent is worth deploying depends on weighing that saving against the expense of running many steps and the damage a failure could cause.
Common Mistakes When Reasoning About Agents
Common mistake Assuming an agent can do anything a capable model can do
What it looks likeA text-only model is asked to check today's stock price.
Why it failsA model with no tools has a small set of possible actions, so it cannot reach outside information on its own.
Do this insteadAsk which tools the agent carries. The tool inventory sets the actions it can really take.
Common mistake Treating the tools and the environment as independent
What it looks likeA robot with only a swimming action is assumed to be useful on land.
Why it failsThe tools restrict which environments the agent can operate in, so a tool that fits one environment may do nothing in another.
Do this insteadRead the relationship in both directions: the environment determines the usable tools, and the tools determine the reachable environment.
Common mistake Thinking an agent runs a fixed script
What it looks likeAssuming the sales run always uses exactly two queries.
Why it failsThe agent returns to reasoning after each tool call and decides for itself whether more queries are needed.
Do this insteadExpect the number of steps to depend on the results the agent observes.
Common mistake Judging each step's accuracy and assuming the run is as reliable
What it looks likeSeeing that each step is 95% accurate and concluding a 10-step run is 95% accurate.
Why it failsErrors compound across steps, so the overall accuracy is the product of the individual step accuracies.
Do this insteadCompute the overall chance of success across all steps, not just the chance for one step.
Practice Tracing an Agent Run
An agent's per-step accuracy is 90% rather than 95%, and a task needs 10 steps that must all succeed. Using the same logic as the 95% example, estimate the overall accuracy. Then explain in one sentence why a small drop in per-step accuracy matters so much.
Hints
- Multiply 0.90 by itself once for each step.
- Compare your result with the 60% figure for 95% per-step accuracy over 10 steps.
What do you think happens?
Before reading the answer, estimate: what is the overall accuracy of a 10-step run where each step is 90% accurate?
Reveal answer
About 35%, since 0.9 to the power 10 is about 0.349.
The overall accuracy is the per-step accuracy multiplied by itself once for each step. Dropping from 95% to 90% per step lowers the 10-step result from about 60% to about 35%, which shows how sensitive long chains are to small per-step errors.
Key Takeaways
- An agent's environment is defined by its use case, such as a game, the internet, a kitchen, or a road system, and that environment determines which tools the agent could potentially use.
- Tools expand the set of actions an agent can perform, and the tool inventory in turn restricts which environments the agent can operate in.
- An agent completes a task by processing feedback, planning a sequence of actions, returning to reasoning after each tool call, and judging when the task is finished.
- Per-step errors compound across a chain of steps, so overall accuracy falls as the number of steps grows, which is one reason agents tend to need more powerful models.