When you ask an AI agent to “find recent news about Tesla and email me a summary,” the agent doesn’t just generate text. It searches the web, reads the results, composes a summary, and sends an email. Each of those steps involves calling an external tool.

But how does the agent know which tools exist? How does it decide which one to use? And what happens when the tool call fails? The mechanics of tool use are central to how modern AI agents work, and understanding them helps you build better agents.

Step 1: Discovery

Before an agent can use a tool, it needs to know the tool exists. This is the discovery phase.

In most tool-use systems, discovery works through a catalog. The agent (or its runtime) queries an endpoint that returns a list of available tools. Each entry includes:

  • Name and slug. A human-readable name and a machine-friendly identifier.
  • Description. A plain-language explanation of what the tool does. This is what the LLM reads to decide whether the tool is relevant.
  • Input schema. A JSON Schema defining what parameters the tool accepts, their types, and which ones are required.
  • Output schema. A description of what the tool returns.
  • Pricing. How much the tool costs per call (if applicable).

The quality of these descriptions matters more than you might expect. The LLM uses the description and schema to decide whether to call a tool, so vague or misleading descriptions lead to poor tool selection.

Some systems expose all tools at once. Others support search, so the agent can query for tools by keyword (like “web search” or “email”) and get a filtered list. Search-based discovery is important when the catalog is large: an agent shouldn’t need to load descriptions for 500 tools when it only needs two.

Step 2: Selection

Once the agent has a list of candidate tools, the LLM decides which one to call. This decision happens inside the model’s reasoning process.

The model reads the tool descriptions and schemas, considers the current task, and picks the tool that best fits. If the user asked to “search for recent AI funding rounds,” the model looks for a tool whose description mentions web search or news search, checks that it accepts a query string as input, and selects it.

Selection can involve multiple tools. For the “find news and email a summary” example, the agent might select a news search tool and an email-sending tool, planning to call them in sequence.

The model can also decide not to use any tool. If the task can be answered from the model’s training data, or if no available tool fits, the agent responds directly.

Step 3: Parameter Construction

After selecting a tool, the agent constructs the input parameters. The model generates a JSON object matching the tool’s input schema.

For a Google search tool, this might look like:

{
  "query": "AI funding rounds 2026",
  "num_results": 10
}

The model infers parameter values from the conversation context. If the user said “search for recent AI funding rounds,” the model maps “recent AI funding rounds” to the query parameter and picks a reasonable default for num_results.

This step is where schema quality pays off. Clear parameter names, sensible defaults, and good descriptions in the schema help the model construct valid input on the first try. Ambiguous schemas lead to malformed requests and wasted calls.

Step 4: Execution

The agent’s runtime sends the request to the tool endpoint. For a platform like AgentPatch, the flow is:

  1. The runtime sends a POST request with the tool slug and input parameters.
  2. The platform validates the request, checks the caller’s credit balance, and deducts the tool’s cost.
  3. The request is forwarded to the tool’s backend.
  4. The tool processes the request and returns a structured JSON response.
  5. The platform wraps the result with metadata (job ID, credits used, credits remaining) and returns it to the agent.

Some tools respond synchronously, returning results in the same HTTP response. Others are asynchronous: the initial response is a job ID, and the agent polls a status endpoint until the result is ready. Image generation and long-running data queries often work this way.

Step 5: Response Processing

The tool’s output goes back into the LLM’s context. The model reads the structured response and decides what to do next.

If the task is complete (say, the agent was asked to search and got results), it formats the output for the user. If the task has more steps (search, then email), the agent moves to the next tool call with the previous output informing its parameters.

This is where the “agent loop” happens. The cycle of select, call, read, decide repeats until the agent determines the task is done or it runs out of steps.

Step 6: Error Handling

Tool calls fail. Servers go down, rate limits get hit, input parameters are wrong. Good agents handle these cases gracefully.

Common error patterns:

  • Bad input (400). The agent sent parameters that don’t match the schema. The agent can read the error message, fix the parameters, and retry.
  • Rate limiting (429). Too many requests in a short window. The agent should wait and retry, or fall back to a different tool.
  • Server error (500). The tool’s backend failed. Retrying after a short delay sometimes works. If not, the agent should inform the user.
  • Timeout. The tool took too long. For synchronous calls, this means the request timed out. For async calls, the job may have been marked as failed.

Well-designed platforms refund credits for errors the caller didn’t cause (server errors, timeouts). This matters when agents are making many calls per task, as failures shouldn’t drain a user’s balance.

Putting It Together

The full loop, discovery through execution and error handling, runs in seconds. A well-configured agent can search the web, process results, and take action in a single conversation turn.

Understanding this flow helps you build agents that use tools reliably. Write clear tool descriptions. Define strict input schemas. Handle errors with retries and fallbacks. And give your agent access to a broad enough catalog that it can find the right tool for whatever task comes up.