Skip to main content
A debt collection agent that processes WhatsApp messages, categorizes conversation outcomes, and tracks collection metrics. This example is based on real production patterns and shows how to handle webhook input transformation, phone-based identification, and intelligent categorization.

Project Structure

Step 1: Configuration

Define your categories, priorities, and constants:
config/settings.ts

Step 2: Prompt

prompts/index.ts

Step 3: Categorization Tool

The main tool categorizes conversation outcomes and tracks metrics:
tools/finalize-conversation.ts
tools/index.ts

Step 4: Agent Definition

agent.ts

Step 5: Main Entry Point with Webhook Parsing

The main.ts handles input transformation from WhatsApp webhooks, user identification by phone, and response formatting:
main.ts

Key Patterns

Phone-Based Identification

In WhatsApp/phone integrations, the phone number is the natural user identifier. Memory persists across all conversations with the same number:

Webhook Input Transformation

Real integrations receive data in different formats (Zenvia, Twilio, custom APIs). Always normalize the input before processing:

Outcome Categorization

Using TypeScript enums for conversation outcomes keeps your code type-safe and makes it easy to build dashboards:

Next Steps

Customer Support with RAG

Support agent with knowledge base

Context Management

Learn about identify patterns

Observability

Track business metrics

Best Practices

Tips for effective agents