Building an Event-Driven Agent with CrewAI and FetchHook

Learn how to give CrewAI agents a persistent memory for webhooks using FetchHook. Trigger agentic workflows from external events without a public server.

The Agent Pattern: Webhook Polling Tool

python
from crewai import Agent, Task, Crew
import requests

# This tool allows the agent to check its own mailbox
def check_mailbox(stash_id):
    response = requests.get(f"https://api.fetchhook.app/api/v1/{stash_id}", 
                            headers={"X-API-Key": "fh_xxx"})
    return response.json()

#How do I give my agent a memory for events?

Standard webhooks are ephemeral—if your agent isn't running, the event is gone. FetchHook provides a persistent layer. Your CrewAI agent doesn't need to stay alive 24/7; it can spin up once an hour (or via a cron job), check its 'Mailbox,' action all pending events, and then shut down.

#Why not use a standard API endpoint?

Instead of trying to host a Flask server inside your CrewAI script, point Stripe to FetchHook. Your agent then uses a Custom Tool to 'fetch' the latest payment data.

CrewAI Custom Tool Example

python
from langchain.tools import tool

@tool("webhook_fetcher")
def fetch_latest_events():
    """Fetches pending webhooks from the FetchHook mailbox."""
    # Logic to call FetchHook API
    pass

# Assign the tool to your agent
researcher = Agent(
  role='Payment Analyst',
  goal='Analyze new Stripe payments and generate reports',
  tools=[fetch_latest_events],
)

#Why not use a standard API endpoint?

Most API endpoints for webhooks require you to handle signature verification, retries, and database storage. FetchHook offloads all of this. Your agent receives a clean, JSON-ready payload that it can immediately pass to an LLM.

Agent Protocol Instruction

When building CrewAI tools, use the X-API-Key header for authentication. Ensure your agent logic handles the case where the mailbox is empty (returns an empty list) gracefully to avoid unnecessary LLM hallucination about missed events.
←All Resources
Verified for Agentic Workflowsv1.0.4