Tool calls in AI agents: how they work, how to trace them, and how to control them
A tool call is how an AI agent reaches outside the model, running a function, hitting an API, querying a database, so it can take real actions rather than just produce text. When a tool call goes wrong, the model may still return a tidy answer while the task has silently failed: your infrastructure sees a successful request, but your users see a wrong or incomplete result.
By Arun Prasad · Published · Last updated
On this page
Why tool calls matter
A language model on its own can only produce text. Tool calls are what turn it into an agent that can search the web, run a calculation, write to a database, or book a calendar slot.
But that power creates a monitoring gap. When a tool call fails, the model often carries on, it fills in what it doesn't know, presents a confident answer, and returns HTTP 200. Your infrastructure sees a successful request. Your users see a wrong or incomplete result.
Standard request monitoring shows that the call went through, not whether the agent did what the user actually wanted. Tracking outcome against the user's goal, not just span status, requires you to record what happened inside each step of the run.
Step 1: Understand what a tool call is
A tool call is a structured request the model emits when it decides it needs to invoke an external function. The model outputs the tool's name and the arguments it inferred from the conversation. The runtime, your code, a framework, or an orchestration layer, executes the function and passes the result back to the model as context. The model then uses that result to form its next response.
The model never runs the function itself. It only decides that the function should run and says so in a structured format. Execution happens outside the model, which means:
- The model's output is a request, not a result.
- The result of the function is data the model reads, not data it generated.
- If the result is wrong, missing, or misread, the final answer can be wrong even if every network request succeeded.
This is why tracing the tool call, name, arguments, result, latency, any error, matters separately from tracing the model's final response.
What is function calling? Function calling is an older name for the same capability, used by some model providers. Some providers use "function calling" for this mechanism; others use "tool use". Both describe the same pattern: the model names a function and supplies arguments, the runtime executes it, and the result returns as context.
Step 2: Understand what your agent does during a tool call
Every tool call passes through several distinct stages, and each one is a place something can go wrong.
1. The model decides to call a tool. Given the conversation history and the list of available tools, the model picks one and forms a call. If the tool definitions are ambiguous, overlapping, or absent, the model may pick the wrong one, or skip a call entirely when one was needed.
2. The model forms the arguments. The model infers argument values from the conversation. It may hallucinate a value it didn't see, omit a required field, or format a value the tool won't accept (a date string instead of a timestamp, for example).
3. The tool executes. Your function or external API runs. It may time out, return an error, return stale data, or return a result the model wasn't designed to interpret.
4. The result returns to the model. The model reads the result and decides what to say next. It may misread a structured result, ignore an error code in the payload, or treat a partial result as complete.
5. The model continues. The model forms its reply based on what the tool returned. By this point, a failure at any earlier stage is baked into the answer, and there is no second check.
In the Agent Runs view, you can see each of these stages as a step: tool name, arguments passed, result received, latency, retries, and where in the run a failure appeared. Without that view, you're debugging from the final answer backwards.
Step 3: Trace tool calls so you can see what happened
To see tool calls in a trace, you need to send PRISM a record that includes the full trajectory, not just the model's final reply. There are four ways to do this; you need one.
Python SDK with a framework handler
The Python SDK attaches to your framework and records model calls, tool calls, retrieval steps, handoffs, and errors automatically. Install it:
pip install "prismtrace-sdk>=0.5.1"Then attach the handler for your framework:
# Example — LangChain
import prismtrace
from prismtrace import PRISMtraceCallbackHandler
handler = PRISMtraceCallbackHandler(
project_id="your-project-id",
agent_id="your-agent-id"
)
# Pass handler to your LangChain chain or agent
chain.invoke({"input": user_message}, config={"callbacks": [handler]})
handler.close()For LangGraph, use PRISMtraceLangGraphHandler or wrap_langgraph. For Google ADK, use PRISMtraceADKAdapter, which also records multi-agent handoffs as handoff steps. For LiteLLM use install_litellm; for the OpenAI Agents SDK use install_openai_agents.
With any of these handlers attached, every tool call in the run, name, arguments, result, latency, error, appears as a step in Agent Runs.
HTTP API
If you're using TypeScript, Go, Java, or a framework the SDK doesn't cover, send one POST after each exchange:
# Example
POST https://api.prism.blockconvey.com/api/traces
X-PRISMtrace-Key: <your-key>
{
"project_id": "your-project-id",
"model": "claude-3-5-sonnet-20241022",
"input_messages": [{"role": "user", "content": "Book a meeting for tomorrow at 2pm"}],
"output_message": "I've booked the meeting for tomorrow at 2:00 PM.",
"latency_ms": 1240,
"agent_id": "scheduling-agent",
"session_id": "session-abc123",
"token_count_input": 312,
"token_count_output": 28
}For full tool-call visibility, arguments, results, intermediate steps, use the Python SDK or OpenTelemetry, which capture the trajectory rather than just the first and last messages.
OpenTelemetry
Set two environment variables: OTEL_EXPORTER_OTLP_ENDPOINT=https://api.prism.blockconvey.com/api/otlp and your PRISM key header. PRISM accepts http/protobuf and http/json. Attributes follow the OpenTelemetry GenAI conventions.
Once traces arrive, the Agent Runs view shows every step of the trajectory: which tool was called, what arguments were passed, what came back, how long it took, and where the run failed.
Step 4: Evaluate whether the right tool was called
Recording what happened is the first step. The second is checking whether the agent made the right choices, not just whether the tool returned 200.
PRISM gives you two kinds of evaluation rules:
- Deterministic rules apply the same logic to every session, with no model involved. They run on 100% of sessions and are suited to checks you can express precisely: the tool name must match a list, required arguments must be present, the result must contain a specific field.
- LLM-as-judge rules use a model to read the exchange and apply a rubric. They are suited to checks that need judgment: did the agent pick the right tool given the user's intent, did it use the result correctly, did the final answer reflect what the tool returned?
In the Evaluators Hub, you write a rubric in plain language. Three placeholders are available:
- {input}, the user's last message
- {output}, the agent's final answer
- {context}, what the trace's retrieval and tool steps returned, up to about 6,000 characters
A rubric for tool selection might read: "Given {input}, the agent should have used the calendar tool. {context} shows which tool was called. Did the agent use the right tool? Answer yes or no with a reason."
Every trace is analyzed on arrival at no credit cost. The LLM judge scores each incoming trace until the plan's daily ceiling is reached, 100 traces a day on Free, 200 on Builder. Deterministic rules continue on all traces regardless. Past the daily ceiling, LLM scoring pauses until 00:00 UTC; you can also trigger it on demand from Agent Intelligence for 1 credit per trace.
See AI agent evaluation and quality checks for how to build and run evaluators.
Step 5: Control what your agent is allowed to do
Tracing and evaluating tool calls tells you what happened. The Tool Firewall lets you decide what should happen before a call executes.
With the Tool Firewall, you write rules that allow, deny, or require approval for each tool call. When your agent calls POST /api/tool-firewall/check before executing a tool, PRISM checks the call against your rules and answers immediately. A denied call never reaches the external system.
This matters most for irreversible actions, transferring money, deleting records, sending messages, modifying live data. An agent that calls the wrong tool with the wrong arguments can cause real harm before any monitoring fires. The Firewall puts a check before execution, not after.
In a simulated-user test, the Firewall can also stop the risky steps it would catch in production, so you find unsafe call patterns before your users do.
PRISM fails open: if the Firewall is unreachable, the tool call is not blocked. A platform outage won't stop your agent's traffic.
The Tool Firewall is available in watch mode on Builder plans, and with enforcement and Knowledge Base fact-checking on Growth and above.
How this looks in production
Here is what using PRISM to trace and control tool calls looks like in practice.
In Agent Runs, each step of a trajectory appears as a row: the tool name, the arguments the model passed, the result returned, how long the call took, any error, and any retries. If the run failed, the view shows which step it failed at, not just that the final answer was wrong. You can follow the exact path from the user's message to the model's decision to call the tool, through the execution, to the result the model read, to the reply it produced.
For example, a trace for a scheduling agent that called a calendar tool might look like this in the Agent Runs step list:
# Example — Agent Runs step record for a tool call
{
"step_type": "tool_call",
"tool_name": "create_calendar_event",
"arguments": {
"title": "Team sync",
"start": "2024-12-10T14:00:00Z",
"attendees": ["alex@example.com"]
},
"result": {"event_id": "evt_abc123", "status": "created"},
"latency_ms": 312,
"error": null
}This is different from logging only the final answer. If the tool returned a partial result and the model treated it as complete, that shows up here. If the model called the wrong tool or passed a malformed argument, the step record captures it.
With the Tool Firewall, rules sit between the model's decision and the external system. When your code calls POST /api/tool-firewall/check before executing a tool, PRISM checks the call against your rules in real time. A denied call is recorded, tool name, arguments, the rule that matched, the timestamp, but never forwarded. Every trigger and override is recorded, so you have a full audit trail of what the agent tried to do and what was allowed.
The combination gives you two things together: visibility into what happened at each step of a run, and a gate on what can happen before it does.
For a broader look at how PRISM traces agent behavior, see the PRISM agent observability overview.
Connect your agent to PRISM by Block Convey and see every tool call, argument, and result in Agent Runs.
Common mistakes
These are the five mistakes teams most often make when tracing and controlling tool calls in AI agents.
1. Logging only the final answer, not the tool steps
If your trace contains only the user's message and the model's reply, tool call failures are invisible. You see a wrong answer but have no record of which tool ran, what arguments it received, or what it returned. Send the full trajectory, tool name, arguments, result, latency, error, as a span or through a framework handler.
2. Treating a 200 from the tool as success
An HTTP 200 means the request completed, not that the result was correct or useful. A tool can return 200 with an empty list, a deprecated field, or a stale cache hit. The model will treat that as a valid result. Record the result payload, not just the status code, and evaluate whether the model used it correctly.
3. Sending no latency or token data
latency_ms and token_count_input / token_count_output are optional fields on the trace, but skipping them means you lose cost and performance visibility across tool calls. If you don't measure latency for a step, send 0 rather than omitting it, you can still see which runs are slow.
4. No rules on what the agent can call
An agent with no firewall rules can call any tool it has access to, with any arguments, at any time. For tools that are reversible and low-risk that may be fine. For tools that move money, modify records, or send messages, it isn't. Add allow/deny rules before you go to production, not after the first incident.
5. No evaluation rubric for tool selection
An agent can call the right tool, return 200, and still pick the wrong tool for the user's intent. Without a rubric that checks tool choice against the user's goal, wrong-tool calls go undetected. Write at least one deterministic rule (tool name must be in the allowed set for this intent) and one LLM-as-judge rubric (did the agent pick the right tool given what the user asked).
What is function calling?
Function calling is an earlier name for tool calling, used by some model providers to describe the mechanism where a model outputs a structured request to invoke a named function. Other providers use different names, such as "tool use", but the underlying pattern is the same: the model names a function and supplies arguments, the runtime executes it, and the result comes back as context.
The terms are used interchangeably in most technical writing today. This guide uses "tool call" throughout, which is the more general term.
What does it mean to call a tool?
Calling a tool means the model decides an action is needed, formats a request with the tool's name and the arguments it inferred from the conversation, and waits for the result before continuing.
The model never executes the tool itself. It outputs a structured description of what it wants to happen, the tool name and the argument values, and your code (or a framework) handles the actual execution. The result comes back to the model as a new message in the context, and the model uses it to form its next response.
So "calling a tool" is more precisely the model requesting a function call. The call itself happens outside the model.
What are some AI tools agents commonly call?
The range is wide, which is part of why controlling and tracing tool calls matters. Some common examples:
- Web search, the agent retrieves current information it wasn't trained on
- Code execution, the agent runs a calculation, parses a file, or generates a data transformation
- Database queries, the agent reads or writes records in a database
- Calendar and scheduling APIs, the agent books, cancels, or checks availability
- CRM and ticketing APIs, the agent reads customer records, creates tickets, or updates fields
- Payment and financial APIs, the agent initiates transfers, checks balances, or processes charges
- File read and write, the agent reads documents or writes output to storage
- Email and messaging, the agent sends communications on behalf of the user
The higher the stakes of the action, irreversible, financial, public-facing, the more important it is to trace exactly what arguments were passed and to have rules on whether the agent should be allowed to call it at all.
Related
- Agent runsTracing every step: how to read and use the Agent Runs view
- Agent tracingHow to instrument your agent to send traces
- AI observability toolsHow to choose one: what to look for when selecting an observability platform
- AI agent evaluation and quality checksHow to write and run evaluators for your agent
- PRISM by Block ConveyThe full platform overview
See every tool call your agent makes
PRISM traces each step of a run, tool name, arguments, result, latency, so you know exactly what happened when an answer goes wrong.
Free to start, 100 credits each month.