Tools allow an agent to read live information or request actions that an LLM cannot perform by generating text alone.

Examples:

Tools make an agent useful

Without tools:

User: What is the status of order 123?
LLM: I do not have access to your order system.

With a tool:

LLM requests getOrderStatus(123)
Backend executes it
Tool returns "shipped"
LLM explains the result to the user

Agent tool loop

sequenceDiagram
    participant U as User
    participant A as Agent
    participant B as Backend
    participant T as Tool
    U->>A: Find my pending orders
    A->>B: Request listOrders(status=pending)
    B->>T: Validate and execute
    T-->>B: Two pending orders
    B-->>A: Tool result
    A->>B: Request another tool or finish
    A-->>U: You have two pending orders.

The agent may call multiple tools because each result can influence the next decision.

Defining a good tool

A tool needs:

const tool = {
  name: "getOrderStatus",
  description: "Return the status of one order owned by the current user",
  parameters: {
    type: "object",
    properties: {
      orderId: { type: "integer" }
    },
    required: ["orderId"]
  }
};

Good descriptions matter because the model uses them to decide which tool fits the task.

The backend executes the tool

The model may return:

{
  "tool": "getOrderStatus",
  "arguments": {
    "orderId": 123
  }
}

Your backend must then:

  1. Validate the arguments.
  2. Authenticate the user.
  3. Check order ownership.
  4. Execute the real function.
  5. Return the result to the agent.

The model does not bypass backend security.

Read tools vs action tools

Read tools

These usually have lower risk.

Action tools

These require stricter permissions and may require user confirmation.

Agent proposes cancellation
        ↓
User confirms exact order
        ↓
Backend rechecks permissions and state
        ↓
Cancellation tool executes

Prevent repeated actions

An agent or retry may request the same action twice.

Use:

This prevents duplicate emails, orders, or payments.

Keep tools narrow

Risky:

executeAnySQL(query)

Safer:

getOrderStatus(orderId)
listPendingOrders(userId)
cancelOwnedOrder(orderId)

Narrow tools are easier to validate, authorize, and audit.

Common mistakes

The agent may request a tool. Only trusted backend code can approve and execute it.