Let's talk

Agentic Architecture

How to Give an AI Agent Tools

To move from a chatbot to an agent, you must give the model the ability to act. This is done by wrapping the model in a loop with specific, structured tools.

By Divyaprakash JhaUpdated 6 min readTopic: Agentic AI

Photo for How to Give an AI Agent Tools

What are AI Agent Tools?

To move from a chatbot to an agent, you must give the model the ability to act. This is done by wrapping the model in a loop with specific, structured tools.

In a standard chatbot interaction, the model simply predicts the next word in a sentence to answer a question. An AI agent, however, is a program that takes a goal, not just a question. To achieve that goal, the agent needs "hands"—the ability to interact with the real world through tools.

Tools are essentially functions that the model can call. Instead of just talking about a task, the model can execute it. For example, instead of saying "I will check your invoices," the model triggers a function like search_invoices(gstin, month). Instead of saying "I'll send that message," it calls send_whatsapp(template_id, phone).

The process works in three distinct steps:

  • The Call: The model recognizes it needs information or needs to perform an action, so it emits a structured call (like a piece of code).
  • The Execution: Your actual application code sees that call, runs the real function (like querying a database or hitting an API), and gets a result.
  • The Feedback: The result of that function is fed back into the model's context, allowing the model to "see" the outcome and decide what to do next.

For a tool to be useful to an agent, it must be well-designed. A "bad" tool is vague or overwhelming. A "good" tool has a narrow scope, a clear and descriptive name, strictly typed parameters, and helpful error messages that tell the model exactly what went wrong if the call fails.

The Tool-Using Loop

An agent is not just a model; it is a model sitting inside an ordinary code loop. The model acts as the decision-maker, but the loop provides the structure that keeps the agent on track toward its goal.

This loop follows a continuous cycle often referred to as the "Reasoning and Acting" cycle. The pattern typically looks like this:

  1. Goal: The agent receives a task with a clear definition of what "done" looks like, including constraints and a budget.
  2. Plan: The model decides the next step or drafts a full plan for the task.
  3. Act: The model calls a tool (e.g., fetching a bank statement).
  4. Remember: The agent records what happened so it can use that information in the next step.
  5. Repeat or Stop: The agent continues the loop until the job is done, it hits a limit, or it needs to ask a human for help.

It is a common mistake to blame the AI model when an agent fails. In reality, most reliability problems in agents stem from the loop design. If the loop doesn't handle errors, doesn't manage memory, or doesn't have a way to stop, even the most powerful model will eventually fail or run out of money.

To understand the broader context of how these loops fit into a larger system, you should explore the principles of agentic architecture.

Designing Effective Tools

When building tools for an agent, you are designing the interface between "thought" and "action." If this interface is messy, the agent will struggle. Here are the three pillars of effective tool design:

1. Manage the Context Window

A common mistake is creating a tool that returns too much data. For example, if a tool for a retail business returns 40,000 rows of inventory data in a single call, it is a bug. That massive amount of text will exceed the model's context window, causing the system to crash or become incredibly expensive. Tools should return concise, summarized, or paginated data.

2. Use Deterministic Verifiers

You should not rely on the model's "judgment" to verify if a task was done correctly. Instead, use code. If an agent is tasked with calculating a total, use a deterministic verifier—a piece of standard code—to check if the sum of the line items actually matches the invoice total. If the math doesn't add up, the code should tell the agent, "The sum is incorrect," rather than letting the agent guess.

3. Implement External Guardrails

Never rely on the model to "promise" to stay within a budget or only use certain tools. Guardrails must be enforced by your code, outside the model's influence. This includes:

  • Spending Limits: Hard stops on how many tokens or API calls can be used.
  • Allowed Tool Lists: Ensuring the agent can only access specific, pre-approved functions.
  • Domain Filters: Preventing the agent from accessing unauthorized websites or sensitive data.

Common Tool-Calling Patterns

Depending on the complexity of your business process, you will likely use one of several established patterns. Choosing the wrong pattern can lead to high costs or unpredictable behavior.

Pattern How it Works Best Use Case
ReAct The agent reasons, calls a tool, observes the result, and reasons again in a loop. Open-ended tasks like research or troubleshooting.
Plan-and-Execute The model writes a full plan first, then an executor works through the steps. Structured tasks like "Migrate these 300 product listings."
Router A small model classifies the input and sends it to a specific toolset or path. Customer support where billing goes to one flow and appointments to another.

For more advanced setups, you might look into multi-agent systems, where different agents handle different parts of a complex workflow. However, for most businesses, starting with a single agent using a clear pattern is the most efficient path to production.

Safety and Governance

As agents move from "reading" to "writing" (e.g., sending money or updating a database), the risk increases. You must implement a governance framework to manage this risk.

Assign Risk Classes

Not all tools are created equal. You should categorize every tool by its risk level:

  • Read/Fetch: Low risk. The agent is only looking up information (e.g., checking a customer's address).
  • Write/Update: Medium risk. The agent is changing data (e.g., updating a shipping status).
  • External/Critical: High risk. The agent is interacting with the outside world or moving value (e.g., sending a WhatsApp message to a client or issuing a refund).

Human-in-the-Loop

For any tool classified as "Critical," you should implement a human-in-the-loop requirement. This creates a pause point where the agent must present its proposed action to a human manager. The agent waits for a "yes" or "no" before the code actually executes the tool. This is essential for high-stakes actions like processing large refunds or changing contract terms.

Audit Trails

Every single tool execution and every decision made by the model should be recorded in an audit trail. In a production-grade system, this should be a "hash-chained" log, meaning the records are cryptographically linked so they cannot be quietly edited or deleted after the fact. This ensures you have a perfect history of exactly why an agent took a specific action.

Frequently Asked Questions

What is the difference between a chatbot and an agent regarding tools?
A chatbot typically provides a reply to a question, whereas an agent uses tools to complete a goal, such as reconciling invoices or rebooking a patient.
Can I use a simple model for tool calling?
Yes. Many systems use a strong model for complex planning and a smaller, cheaper model for routine tasks like classifying messages or routine tool steps.
How do I prevent an agent from running forever when using tools?
You should implement bounded cycles, step budgets, and timeouts within the code that manages the agent loop.
What should I do if a tool returns too much data?
Ensure tool outputs are short enough to fit in the model's context window; returning massive datasets can cause errors and high costs.
How do I make tool usage safe?
Use guardrails enforced by your code, such as allowed tool lists and human approval points for critical or external actions.
Yellow robotic arm operating inside a glass enclosure with a monitor above.
Photo: Robot arm works on a small component in a lab setting by Shixart1985, CC BY 2.0

Questions people ask

What is the difference between a chatbot and an agent regarding tools?

A chatbot typically provides a reply to a question, whereas an agent uses tools to complete a goal, such as reconciling invoices or rebooking a patient.

Can I use a simple model for tool calling?

Yes. Many systems use a strong model for complex planning and a smaller, cheaper model for routine tasks like classifying messages or routine tool steps.

How do I prevent an agent from running forever when using tools?

You should implement bounded cycles, step budgets, and timeouts within the code that manages the agent loop.

What should I do if a tool returns too much data?

Ensure tool outputs are short enough to fit in the model's context window; returning massive datasets can cause errors and high costs.

How do I make tool usage safe?

Use guardrails enforced by your code, such as allowed tool lists and human approval points for critical or external actions.