image 44

Give Your AI Hands: A Guide to Claude 3’s Tool Use

The Genius in a Glass Box

Imagine you have a new team member, let’s call him Claude. He’s a certified genius. He can strategize, analyze complex documents, write perfect emails, and speak a dozen languages. There’s just one problem: he’s trapped in a soundproof glass box.

You can slide documents under the door, and he can write notes and press them against the glass for you to read. But he can’t pick up the phone. He can’t check your inventory system. He can’t log into the CRM. He has a brilliant mind, but no hands.

This is what working with a standard Large Language Model feels like. It can *tell* you what to do, but it can’t *do* anything. You’re stuck being the middleman, the person who reads Claude’s note and then goes to the computer to actually perform the task.

Today, we’re smashing the glass box. We’re going to give Claude a set of remote-controlled robotic hands. We’re going to teach him how to use your business’s real tools.

Why This Matters

The difference between a chatbot and an autonomous agent is one word: **action**. A chatbot can answer questions based on the data it was trained on. An agent can interact with the real, live world to get new data and perform tasks.

When an AI can use tools, it transforms from a clever search engine into an active participant in your business processes. It can become your automated sales development rep, your tier-one support agent, your financial data analyst. It stops being a text generator and starts being a workflow engine.

This workflow replaces: The human who has to copy-paste information between the AI and other software. It replaces the swivel-chair work of looking up an order in one system and typing the update into another. It replaces the delay between insight and action.

This is the leap from telling your intern what to do, to having your intern just do it.

What This Tool / Workflow Actually Is

We’ll be using a feature in the Anthropic Claude 3 API called Tool Use (you might also hear it called function calling in other ecosystems). It’s a structured way for Claude to request that we, the developers, run a specific function on its behalf.

Here’s the crucial part to understand: **Claude does not execute any code.** It can’t. It’s still in the box. Instead, it identifies that a user’s request requires a special tool and then formats a perfect, machine-readable “work order” for you. Your code receives this work order, runs the actual tool, and then passes the result back to Claude to complete the thought.

What it does:
  • Analyzes a user’s prompt to see if it matches any of the tools you’ve provided.
  • Intelligently figures out the necessary inputs (arguments) for that tool based on the user’s language.
  • Outputs a structured XML block telling your code exactly which tool to run and with what inputs.
What it does NOT do:
  • Execute code. It cannot access your database, your file system, or the internet on its own.
  • Magically know what your tools do. You have to provide a clear description and schema for each tool.
  • Guarantee a perfect outcome. Your tool might fail (e.g., an invalid order ID), and you have to handle that.

Think of it this way: The user asks Claude, “What’s the weather in Paris?” Claude can’t look out a window. Instead, it taps you on the shoulder and hands you a perfectly filled-out form that says: “Please run the tool `get_weather` with the parameter `city` set to `Paris`.” Your code does the work and hands back a note saying “72°F and sunny.” Claude then turns to the user and says, “The weather in Paris is 72°F and sunny.”

Prerequisites

This is easier than it sounds. You’ve got this.

  1. An Anthropic API Key. Go to console.anthropic.com, create an account, and get your API key. You’ll need to add a few dollars of credits to run these examples.
  2. A way to code in Python. We need to write the actual tools Claude will use. I’ll give you every line of code. You just need a place to run it.
  3. A basic idea of a ‘function’. In programming, a function is just a named chunk of code that does one specific thing, like `get_weather(city)`. We’re going to write a few of these.
Step-by-Step Tutorial

Let’s build a simple stock price checker. The AI will take a human question, use our tool to get the live price, and then give a natural language answer.

Step 1: Define Your Tool in Python

First, we need the actual tool. This is a simple Python function. For this example, it will just return a fake number, but you can imagine it calling a real stock market API.

# This is our real tool. The thing that does the work.
def get_stock_price(ticker_symbol):
  """Gets the current stock price for a given ticker symbol."""
  print(f"--- Executing tool: get_stock_price for {ticker_symbol} ---")
  if ticker_symbol.upper() == "GOOGL":
    return {"price": 175.50}
  elif ticker_symbol.upper() == "AAPL":
    return {"price": 214.29}
  else:
    return {"price": "N/A"}
Step 2: Describe the Tool for Claude

This is the instruction manual. We need to describe our tool to Claude in a specific JSON format so it knows what it is, what it does, and what inputs it needs.

# This is the 'instruction manual' for the tool that we show to Claude.
tool_spec = [
  {
    "name": "get_stock_price",
    "description": "Gets the current stock price for a given ticker symbol. Use this for any questions about stock prices.",
    "input_schema": {
      "type": "object",
      "properties": {
        "ticker_symbol": {
          "type": "string",
          "description": "The stock ticker symbol, e.g., GOOGL for Google."
        }
      },
      "required": ["ticker_symbol"]
    }
  }
]
Step 3: Make the First API Call

Now we send the user’s question to Claude, along with the tool’s instruction manual. Notice the `tools` parameter.

# You'll need to install the anthropic library:
# pip install anthropic

import anthropic

client = anthropic.Anthropic(api_key="YOUR_ANTHROPIC_API_KEY")
user_message = "What is the current stock price for Google?"

print(f"User: {user_message}")

# First call to Claude: give it the prompt and the tools
response = client.messages.create(
    model="claude-3-opus-20240229",
    max_tokens=1024,
    messages=[{"role": "user", "content": user_message}],
    tools=tool_spec
)

print(f"Claude's Response: \
{response.content}")
Step 4: Interpret Claude’s Response & Execute the Tool

Claude won’t give you an answer. It will give you the work order. The response content will look something like this: `[TextBlock(text=’Okay, let\\’s check that.’, type=’text’), ToolUseBlock(id=’toolu_01…’, name=’get_stock_price’, input={‘ticker_symbol’: ‘GOOGL’}, type=’tool_use’)]`

Our code needs to see this `ToolUseBlock`, run our Python function, and get the result.

Here’s how we’d process that:

# Find the tool use request in the response
tool_use_block = next((block for block in response.content if block.type == 'tool_use'), None)

if tool_use_block:
  tool_name = tool_use_block.name
  tool_input = tool_use_block.input
  tool_use_id = tool_use_block.id # Important for the next step!

  if tool_name == "get_stock_price":
    # Call our actual Python function
    tool_result = get_stock_price(tool_input.get("ticker_symbol"))
    print(f"Tool Result: {tool_result}")
else:
  # Handle cases where no tool was called
  print("Claude did not use a tool.")
Step 5: Send the Result Back to Claude

Now we make a *second* API call. This time, we include the entire conversation history: the user’s original question, Claude’s decision to use a tool, and a new message containing the result from our tool. This ‘closes the loop’ for the AI.

# Build the conversation history
messages = [
    {"role": "user", "content": user_message},
    {"role": "assistant", "content": response.content}, # Claude's first response (with the tool use block)
    {
        "role": "user",
        "content": [
            {
                "type": "tool_result",
                "tool_use_id": tool_use_id,
                "content": str(tool_result) # The result from our Python function
            }
        ]
    }
]

# Second call to Claude: give it the tool result
final_response = client.messages.create(
    model="claude-3-opus-20240229",
    max_tokens=1024,
    messages=messages,
    tools=tool_spec
)

print(f"\
Final Answer from Claude: {final_response.content[0].text}")

When you run this, Claude’s final answer will be a beautiful, natural language sentence: “The current stock price for GOOGL is $175.50.”

Complete Automation Example: A Simple Order Status Bot

Let’s build a support bot that can check a customer’s order status.

The Tools:

# Fake database of orders
ORDERS = {
  "123-456": {"status": "shipped", "tracking_number": "XYZ987"},
  "789-012": {"status": "processing"}
}

def get_order_status(order_id):
  """Looks up an order in the database and returns its status."""
  return ORDERS.get(order_id, {"status": "not_found"})

The Tool Spec (Instruction Manual for Claude):

order_tool_spec = [{
  "name": "get_order_status",
  "description": "Get the status of a customer's order using the order ID.",
  "input_schema": {
    "type": "object",
    "properties": {
      "order_id": {
        "type": "string",
        "description": "The unique ID for the order, e.g., '123-456'."
      }
    },
    "required": ["order_id"]
  }
}]

The Workflow in Action:

  1. User asks: “Hey can you check on my order #123-456?”
  2. Your code sends this to Claude with the `order_tool_spec`.
  3. Claude responds with a work order: It sends back a `ToolUseBlock` with `name=’get_order_status’` and `input={‘order_id’: ‘123-456’}`.
  4. Your code executes the tool: It calls your `get_order_status(‘123-456’)` function, which returns `{“status”: “shipped”, “tracking_number”: “XYZ987”}`.
  5. Your code sends the result back to Claude: It makes the second API call, including the conversation history and the tool result.
  6. Claude gives the final answer: “I’ve looked up your order #123-456. It has been shipped and the tracking number is XYZ987.”

This entire loop happens in seconds, providing an instant, accurate answer without a human support agent ever getting involved.

Real Business Use Cases (MINIMUM 5)
  1. SaaS Onboarding: A bot with tools like `create_new_project(user_name)` and `invite_teammate(email)` can guide new users through setup interactively.
  2. E-commerce Inventory Manager: An internal tool for employees that can use `check_inventory(sku)` and `place_purchase_order(supplier_id, sku, quantity)` to manage stock levels conversationally.
  3. Sales Lead Qualifier: A bot on your website can ask a visitor questions, then use `create_crm_lead(name, email, company_size)` to put qualified leads directly into Salesforce, and `schedule_sales_call(lead_id)` to book a demo.
  4. Travel Booker: An agent with tools for `find_flights(origin, destination, date)` and `check_hotel_prices(city, dates)` can help users plan a trip by interacting with multiple APIs.
  5. Internal Database Query: An analyst can ask, “How many users signed up last week?” The AI uses a tool `run_sql_query(query)` that executes a safe, read-only SQL query against the company database to get the answer.
Common Mistakes & Gotchas
  • Lazy Tool Descriptions: The quality of your tool description is EVERYTHING. If it’s vague, Claude won’t know when to use it. Be explicit. Instead of “gets customer data,” write “retrieves a customer’s full name and shipping address using their email address.”
  • Forgetting to Handle Errors: What if a user gives a non-existent order ID? Your `get_order_status` function will return `{“status”: “not_found”}`. You must pass this result back to Claude! It’s smart enough to see the error and respond, “I’m sorry, I couldn’t find an order with that ID.”
  • Mishandling Conversation History: You MUST include the *entire* chain of messages in the second API call. The user’s prompt, the assistant’s first reply (with the tool request), and the tool result. If you don’t, Claude has amnesia and won’t know why you’re sending it a random tool result.
  • One Tool to Rule Them All: Don’t create one massive tool that does 10 things. Create small, single-purpose tools. It’s much easier for Claude to reason about `get_customer_email` and `update_customer_address` than one giant `manage_customer` tool.
How This Fits Into a Bigger Automation System

Tool use isn’t just a feature; it’s the central nervous system of a modern automation stack. It’s how the AI brain connects to the robotic arms of your business.

  • Voice Agents: Connect this to a voice transcription and text-to-speech service. A customer calls, their speech becomes text, Claude processes it, uses a tool to query your database, forms a text response, and the text-to-speech service speaks the answer. You’ve just built an AI phone agent.
  • CRM Automation: The tools you build can be direct API calls to HubSpot, Salesforce, or your own internal CRM. “Claude, find all leads in California and add them to the ‘West Coast Q3’ campaign.”
  • Multi-Agent Systems: This is the foundation for complex agents. One “manager” agent could receive a high-level task like “Onboard new client XYZ Corp.” It then uses tools that delegate sub-tasks to other, more specialized agents: one to provision software, one to schedule meetings, and one to draft a welcome email.
What to Learn Next

You’ve done it. You smashed the glass box and gave your AI hands. It can now interact with the controlled, predictable environment of your own tools and databases. This is a massive leap.

But what about the messy, unpredictable world outside your company? What if a customer asks a question your database can’t answer? What if you need to research a competitor or find the latest news on a topic?

Our agent has hands, but it’s still stuck inside our building. In the next lesson, we’re going to give it a key to the front door and a library card. We’re going to build tools like `google_search(query)` and `browse_website(url)` to create a true research agent that can learn and reason about information from the live internet.

Get ready to let your agent out into the world.

“,
“seo_tags”: “Claude 3, Tool Use, Function Calling, AI Agents, Business Automation, Anthropic API, AI Workflow”,
“suggested_category”: “AI Automation Courses

Leave a Comment

Your email address will not be published. Required fields are marked *