Autonomous FutureModule 2

2.3Custom Tooling for Agentic Research

45 min 3 code blocks Practice Lab Homework Quiz (5Q)

Custom Tooling for Agentic Research: The API Bridge

Agents are only as powerful as the tools they can access. In this lesson, we learn how to build and expose Custom Tools (Python functions) to your agent swarms, allowing them to perform real-world actions like database lookups, API calls, and local file manipulation.

🏗️ The Tooling Interface

A custom tool requires 3 components:

  1. The Logic: The raw Python function.
  2. The Metadata: A description telling the agent when and how to use the tool.
  3. The Error Handling: Ensuring the agent can recover if the tool fails.
Technical Snippet

Technical Snippet: Building a 'PSI Auditor' Tool for CrewAI

python
from crewai_tools import tool
import requests

@tool("psi_auditor")
def psi_auditor(url: str) -> str:
    """Performs a Google PageSpeed Insights audit and returns the LCP score."""
    api_url = f"https://www.googleapis.com/pagespeedonline/v5/runPagespeed?url={url}&category=PERFORMANCE"
    response = requests.get(api_url).json()
    lcp = response['lighthouseResult']['audits']['largest-contentful-paint']['displayValue']
    return f"Technical Audit for {url}: LCP is {lcp}."
Key Insight

Nuance: Semantic Tool Descriptions

The agent doesn't see your code; it only sees the Docstring. If your description is vague (e.g., "Fetches data"), the agent will use it incorrectly. A high-status description is precise: "Use this tool ONLY when you need to identify the Largest Contentful Paint (LCP) for a specific website URL."

Practice Lab

Practice Lab: The Tool Bridge

  1. Build: Create a Python function that takes a JSON string and returns the character count.
  2. Describe: Write a 2-sentence metadata description for an agent.
  3. Test: Ask an agent to "Count the characters in this JSON: {...}." Verify it chooses your tool instead of guessing.

🇵🇰 Pakistan Project: The WhatsApp Lead Qualifier Tool

Pakistani businesses live on WhatsApp. Build a custom tool for your agent:

python
@tool("whatsapp_lead_qualifier")
def qualify_lead_whatsapp(phone: str, business_name: str) -> str:
    """Checks if a Pakistani business has an active WhatsApp Business account
    and returns their profile status. Use this tool when you need to verify
    if a lead can be reached via WhatsApp before sending a pitch."""

    # Format PK number
    clean_phone = phone.replace(" ", "").replace("-", "")
    if clean_phone.startswith("0"):
        clean_phone = "+92" + clean_phone[1:]

    # Check via WATI or WhatsApp Business API
    # Returns: "ACTIVE" / "PERSONAL" / "NOT_FOUND"
    return f"WhatsApp status for {business_name} ({clean_phone}): ACTIVE"

Why this tool is gold: In Pakistan, email open rates are 15-20%. WhatsApp open rates are 90%+. An agent that can check WhatsApp status before deciding the outreach channel will always outperform one that defaults to email.

📺 Recommended Videos & Resources

  • CrewAI Tools Documentation — Building and registering custom tools for agents

    • Type: Documentation
    • Link description: Visit docs.crewai.com, search "tools" section
  • Python Tool Decorators @tool — Syntax for wrapping functions as agent tools

    • Type: Documentation
    • Link description: Look for "@tool decorator" in CrewAI docs
  • Building Custom LangChain Tools — Lower-level tool patterns

    • Type: Documentation
    • Link description: Visit python.langchain.com for tool examples
  • API Bridge Patterns — How to expose databases, APIs as tools to agents

    • Type: YouTube
    • Link description: Search YouTube for "agent tool integration tutorial 2025"
  • WhatsApp Business API Integration — Official WhatsApp tool documentation for agents

    • Type: Documentation
    • Link description: Visit developers.facebook.com for WhatsApp integration

🎯 Mini-Challenge

Build a 30-Second Custom Tool (5 minutes)

Your mission: Create a simple Python tool function that agents can use.

Example: "Calculate Discount Tool" that takes a base price and discount percentage, returns final price.

Then:

  1. Add proper docstring describing when agents should use it
  2. Register it with a dummy agent prompt
  3. Ask the agent: "If a restaurant charges PKR 5,000/month and we offer 20% discount, what's the new price?"
  4. Watch the agent choose your tool automatically

Output: Print when the agent invokes your custom tool + the result.

🖼️ Visual Reference

code
📊 Custom Tool Architecture

┌─────────────────────────────────────┐
│ AGENT ORCHESTRATOR                  │
│ (CrewAI / AutoGen)                  │
└────────────┬────────────────────────┘
             │
    ┌────────┴────────┐
    │                 │
    ↓                 ↓
┌──────────┐     ┌──────────────────┐
│ Reasoning│     │ Tool Registry    │
│ Engine   │     │ ┌──────────────┐ │
└──────────┘     │ │@tool("psi")  │ │
                 │ │@tool("whatsapp")
                 │ │@tool("csv")  │ │
                 │ └──────────────┘ │
                 │                  │
                 │ Agent selects:   │
                 │ "I need whatsapp_│
                 │ _lead_qualifier" │
                 └────────┬─────────┘
                          │
                          ↓
                   ┌─────────────────┐
                   │ Python Function │
                   │ (Actual Logic)  │
                   └────────┬────────┘
                            │
                            ↓
                   Return result to Agent
Homework

Homework: The CRM Writer Tool

Build a custom tool that takes a {lead_phone, lead_name, city, score} object and appends it to a local CSV file formatted for the WhatsApp Outreach Bot. Register this tool with a CrewAI agent and verify the agent can write to the CSV autonomously.

Lesson Summary

Includes hands-on practice labHomework assignment included3 runnable code examples5-question knowledge check below

Quiz: Custom Tooling for Agentic Research

5 questions to test your understanding. Score 60% or higher to pass.