Skip to main content

๐Ÿ”ง Tool Usage in AI Agents

Tool usage means giving an AI agent access to external capabilities โ€” like web search, a calculator, code execution, or API calls โ€” so it can go beyond its own knowledge to solve problems.

Think of it like giving someone a toolbox. Without tools, they can only use their hands. With tools, they can build almost anything.


๐ŸŽฏ Why This Mattersโ€‹

LLMs have a knowledge cutoff date and cannot interact with the real world on their own. By describing tools in your prompts, you can:

  • Let the AI access up-to-date information via web search
  • Perform accurate calculations instead of guessing math
  • Execute code to validate solutions
  • Call APIs to fetch live data or trigger actions
  • Make the AI significantly more useful and reliable

๐Ÿ“– The Concept in Detailโ€‹

What Are Tools?โ€‹

Tools are functions or services that an AI agent can call to perform specific actions. Common tools include:

ToolWhat It DoesExample Use
Web SearchFinds current information online"Search for latest React 19 features"
CalculatorPerforms precise math"Calculate compound interest on $10,000"
Code ExecutorRuns code and returns results"Run this Python script and show output"
API CallerSends HTTP requests"Fetch current weather for New York"
File ReaderReads document contents"Read and summarize this PDF"
Database QueryQueries a database"Find all orders from last month"

How to Describe Tools in Promptsโ€‹

When prompting an AI to use tools, you need to:

  1. List available tools with clear descriptions
  2. Define the format for calling each tool
  3. Explain when to use each tool
  4. Show the expected output format from each tool

Tool Description Formatโ€‹

You have access to the following tools:

[Tool Name]: [Description of what it does]
- Input: [What the tool needs]
- Output: [What the tool returns]
- When to use: [Conditions for using this tool]

๐Ÿ’ก Prompt Examplesโ€‹

Basic Tool Usage Promptโ€‹

You are a helpful assistant with access to these tools:

1. SEARCH(query) โ€” Searches the web and returns top results
Use when: You need current information or facts you're unsure about

2. CALCULATE(expression) โ€” Evaluates a math expression
Use when: You need precise numerical calculations

3. RUN_CODE(language, code) โ€” Executes code and returns output
Use when: You need to test or demonstrate code

To use a tool, write:
ACTION: TOOL_NAME(parameters)

Then wait for the result before continuing.

User question: What is the current population of Tokyo, and what
percentage of Japan's total population does it represent?

Detailed Tool Descriptionโ€‹

You are a data analysis agent. You have access to these tools:

Tool 1: query_database
- Description: Runs SQL queries against the sales database
- Input: A valid SQL query string
- Output: Table of results in CSV format
- Rules: Only SELECT queries allowed. No DELETE or UPDATE.

Tool 2: create_chart
- Description: Creates a visual chart from data
- Input: Chart type (bar, line, pie), data, title
- Output: A chart image description
- Rules: Data must come from query_database first.

Tool 3: send_email
- Description: Sends an email with a report
- Input: recipient, subject, body, attachments
- Output: Confirmation message
- Rules: Always confirm with user before sending.

Process: Think about which tool to use, call it, observe the result,
then decide your next action.

โŒ Bad Exampleโ€‹

You can search the web and do math. Help me figure out if I should 
invest in Tesla stock.

Why it fails: The tools are vaguely mentioned with no format, no calling convention, and no structure. The AI won't know how to "use" the tools or show its tool usage clearly.


โœ… Improved Exampleโ€‹

You are a financial research agent with access to these tools:

1. SEARCH(query) โ€” Search the web for current financial data
2. CALCULATE(expression) โ€” Perform precise financial calculations
3. ANALYZE(data) โ€” Analyze trends from provided data

Format for using tools:
THOUGHT: [Why you need this tool]
ACTION: TOOL_NAME(parameters)
OBSERVATION: [Result from the tool]

Task: Research whether Tesla (TSLA) is a good investment right now.

Steps:
1. Use SEARCH to find Tesla's current stock price and recent performance
2. Use SEARCH to find Tesla's revenue and earnings data
3. Use CALCULATE to compute P/E ratio and growth rate
4. Use ANALYZE to evaluate the data
5. Give a final recommendation with reasoning

Begin with Step 1.

Why it works: Tools are clearly defined with a calling format. The Thought-Action-Observation pattern makes tool usage visible. Steps guide the agent through a logical workflow.


๐Ÿงช Try It Yourselfโ€‹

๐Ÿงช Try It Yourself

Edit the prompt and click Run to see the AI response.


๐Ÿ‹๏ธ Practice Challengeโ€‹

Challenge

Design a prompt for a customer support agent that has access to these tools:

  • LOOKUP_ORDER(order_id) โ€” Finds order details
  • CHECK_INVENTORY(product_id) โ€” Checks if a product is in stock
  • CREATE_TICKET(issue, priority) โ€” Creates a support ticket
  • SEND_EMAIL(to, subject, body) โ€” Sends an email to the customer

Include tool descriptions, calling format, and a sample customer inquiry to handle.


๐ŸŒ Real-World Scenarioโ€‹

Scenario: You're building a coding assistant that helps developers debug issues.

The agent needs these tools:

  • Search documentation to find relevant API references
  • Run code to reproduce and test fixes
  • Read error logs to understand what went wrong
  • Write files to apply the fix

Your prompt should describe each tool clearly, define when each should be used, and instruct the agent to follow a debug-fix-verify cycle using the tools.


๐ŸŽค Interview Questionโ€‹

Interview Question

Q: How do you describe tools in a prompt so the AI uses them correctly?

A: You describe tools with four key elements: a clear name, a description of what the tool does, the input format it expects, and the output format it returns. You also define when to use each tool and provide a calling convention (like ACTION: TOOL_NAME(params)). The Thought-Action-Observation pattern from ReAct prompting is a popular way to structure tool usage, making the AI's reasoning and tool calls explicit and traceable.


๐Ÿ“ Summaryโ€‹

Key Takeaways
  • Tool usage extends AI capabilities beyond its training data
  • Common tools include web search, calculators, code executors, and API callers
  • Always clearly describe each tool with name, description, input, and output
  • Define a calling format so the AI shows its tool usage explicitly
  • Use the Thought โ†’ Action โ†’ Observation pattern for structured tool calls
  • Guide the agent on when to use each tool to avoid unnecessary tool calls