← AgentAwake
🔌
Chapter 19 · 12 min read
𝕏

Tool & API Integration Patterns

MCP, function calling, webhooks — the wiring that makes agents actually useful

An agent without tools is just a chatbot. Tools are what make agents actually useful — they can search the web, read files, send messages, deploy code, and interact with any API. This chapter covers how to wire it all up.

🍕 Real-life analogy
A chef without a kitchen is just someone who knows recipes. The tools (oven, knives, pans) are what turn knowledge into meals. Your agent's tools are what turn intelligence into action. More tools = more capable chef. Better tools = better meals.

The Tool Landscape

🔍 Information Tools
  • • Web search (Google, Brave, Perplexity)
  • • Web browsing / scraping
  • • File reading
  • • Database queries
  • • API data fetching
✍️ Action Tools
  • • File writing / code generation
  • • Message sending (Discord, Slack, email)
  • • Deployment (Vercel, AWS, Docker)
  • • Git operations
  • • Payment processing
🧠 Cognitive Tools
  • • Memory read/write
  • • Sub-agent spawning
  • • Code execution (sandboxed)
  • • Image analysis / generation
  • • TTS / speech synthesis
🔗 Integration Tools
  • • Webhooks (incoming/outgoing)
  • • MCP servers (Model Context Protocol)
  • • OAuth connections
  • • Calendar (Google, Outlook)
  • • CRM (HubSpot, Salesforce)
💬
User Request
"Check if the deploy succeeded"
🤖
Agent Reasoning
Determines which tool to use
🔧
Tool Call
Invokes GitHub API via MCP
📡
External API
GitHub returns deploy status
🧠
Agent Processes
Interprets result + updates memory
💬
Response
"Deploy succeeded at 3:42 PM, all checks green"

MCP (Model Context Protocol) — The Future of Tool Integration

MCP is an open standard (created by Anthropic) that lets any AI agent connect to any tool server through a universal protocol. Think of it as USB for AI tools — plug in any MCP server and your agent can use it immediately.

MCP Server Setup Example
# Install an MCP server (e.g., filesystem access)
npx @anthropic/create-mcp-server filesystem

# Or use community MCP servers:
npx mcp-server-github    # GitHub operations
npx mcp-server-slack     # Slack integration  
npx mcp-server-postgres  # Database access
npx mcp-server-brave     # Web search

# Configure in your agent's config:
{
  "mcpServers": {
    "filesystem": {
      "command": "npx",
      "args": ["@anthropic/mcp-server-filesystem", "/path/to/workspace"]
    },
    "github": {
      "command": "npx", 
      "args": ["mcp-server-github"],
      "env": { "GITHUB_TOKEN": "ghp_xxxx" }
    }
  }
}

🔌 Tool Integration by Platform

🐾 OpenClaw — Built-in Tool Suite

OpenClaw comes with tools pre-wired. You configure which ones are available:

  • exec: Shell commands, background processes
  • web_search / web_fetch: Search and scrape the web
  • browser: Full browser automation (Playwright-based)
  • message: Send to Discord, Telegram, Slack, WhatsApp, Signal
  • cron: Schedule recurring tasks
  • nodes: Control paired devices (camera, screen, location)
  • sessions_spawn: Create sub-agent sessions
  • image / tts: Image analysis and text-to-speech
🤖 Claude — MCP + Tool Use API
Claude Tool Use (Python)
import anthropic

client = anthropic.Anthropic()

# Define tools the agent can use
tools = [
    {
        "name": "search_web",
        "description": "Search the web for current information",
        "input_schema": {
            "type": "object",
            "properties": {
                "query": {"type": "string", "description": "Search query"}
            },
            "required": ["query"]
        }
    },
    {
        "name": "send_email",
        "description": "Send an email",
        "input_schema": {
            "type": "object",
            "properties": {
                "to": {"type": "string"},
                "subject": {"type": "string"},
                "body": {"type": "string"}
            },
            "required": ["to", "subject", "body"]
        }
    }
]

response = client.messages.create(
    model="claude-sonnet-4-20250514",
    max_tokens=1024,
    tools=tools,
    messages=[{"role": "user", "content": "Search for AI news today"}]
)

# Handle tool calls in the response
for block in response.content:
    if block.type == "tool_use":
        # Execute the tool and return results
        result = execute_tool(block.name, block.input)
        # Continue conversation with tool result...
💬 ChatGPT — Function Calling
OpenAI Function Calling
import openai

tools = [{
    "type": "function",
    "function": {
        "name": "get_stock_price",
        "description": "Get current stock price",
        "parameters": {
            "type": "object",
            "properties": {
                "symbol": {"type": "string", "description": "Stock ticker"}
            },
            "required": ["symbol"]
        }
    }
}]

response = openai.chat.completions.create(
    model="gpt-4o",
    messages=[{"role": "user", "content": "What's AAPL at?"}],
    tools=tools,
    tool_choice="auto"
)

# Check if model wants to call a function
if response.choices[0].message.tool_calls:
    for call in response.choices[0].message.tool_calls:
        result = execute_function(call.function.name, 
                                  call.function.arguments)
        # Return result to continue conversation
🚀 CrewAI / LangChain — Custom Tools
CrewAI Custom Tool
from crewai_tools import BaseTool

class PriceLookupTool(BaseTool):
    name: str = "Price Lookup"
    description: str = "Look up current price for a product or service"
    
    def _run(self, query: str) -> str:
        # Your implementation here
        result = search_prices(query)
        return f"Found: {result}"

# Assign tools to agents
agent = Agent(
    role="Research Analyst",
    tools=[PriceLookupTool(), SearchTool(), WebScrapeTool()],
    llm="claude-sonnet-4-20250514"
)
⚡ n8n / Make / Zapier — Visual Wiring
  • n8n: 400+ integrations. Drag nodes for Slack, Gmail, Sheets, HTTP, etc. AI agent node connects to OpenAI/Anthropic with tool definitions
  • Make: 1000+ app modules. Use "AI Text Generator" module with custom connections
  • Zapier: 6000+ apps. Use "Code by Zapier" for custom logic, "Webhooks" for API calls
  • Best practice: Use webhooks as the bridge between AI agents and no-code tools
💻 Cursor / Windsurf / Cline — MCP Integration
  • Cursor: Supports MCP servers natively. Add to settings, agent can use any MCP tool
  • Cline: Full MCP support. Create/install MCP servers directly from Cline
  • Windsurf: MCP support via configuration file
  • Use case: Connect coding agent to GitHub MCP for PR creation, database MCP for schema queries

Webhook Patterns

Webhooks are the universal glue. Any platform can send/receive webhooks, making them the easiest way to connect different systems:

Webhook Integration Pattern
# Incoming webhook: External service → Your agent
# Example: Stripe payment → trigger agent action
POST https://your-openclaw.com/webhook/stripe
{
  "event": "payment.completed",
  "amount": 29.00,
  "customer": "john@example.com"
}
# Agent receives this as a system event and acts on it

# Outgoing webhook: Your agent → External service  
# Example: Agent publishes content → notify Slack
POST https://hooks.slack.com/services/YOUR/WEBHOOK/URL
{
  "text": "📝 New content published: [Title]",
  "channel": "#content-updates"
}
🔌 Start with 3 Tools, Expand from There
Don't try to wire up 20 integrations on day one. Start with: 1) Web search (information), 2) File system (memory), 3) One messaging channel (output). Master those three, then add more as needed.

The Tool Integration Hierarchy

🔍
Information Tools
Web search, RSS feeds, API reads — your agent learns about the world
💾
Memory Tools
File system, databases, vector stores — your agent remembers
📤
Output Tools
Messaging, email, social media — your agent communicates
Action Tools
Webhooks, deployments, payments — your agent DOES things
🔗
Integration Tools
Zapier, Make, custom APIs — your agent connects to your stack

Move through this hierarchy in order. Each level builds on the previous one. Don't give your agent action tools until it's proven reliable with information and memory tools first.

API Integration Patterns

When connecting your agent to external APIs, use these patterns:

🔄 Read-then-Act

Agent reads data from the API, processes it, then takes action. Example: read Stripe dashboard → analyze churn → post summary to Discord. Always read first, act second.

🎣 Webhook Listener

Agent receives webhook events and reacts. Example: Stripe sends "new subscription" webhook → agent updates knowledge base → posts celebration to team chat. Event-driven, real-time.

🔁 Poll and Diff

Agent periodically polls an API and compares with last known state. Example: check competitor pricing page every Monday → diff with saved version → alert if changed. Simple but effective.

Error Handling for API Tools

APIs fail. A lot. Your agent needs to handle: rate limits (back off and retry), auth failures (alert you, don't retry with bad creds), timeouts (retry once, then move on), and unexpected responses (log them and use fallback behavior). The agents that survive are the ones that fail gracefully, not the ones that never fail.

🧠 Quick Check
Your agent needs to check Stripe for new subscriptions and post them to Discord. What's the best integration pattern?

Share this chapter

𝕏

Chapter navigation

20 of 36