Skip to main content

Overview

The CRM Agent is an AI-powered service that enables natural language interactions with CRM data. It understands queries like “Show me all tech companies with revenue over $10M” and translates them into database operations. Location: scripts/crm_agent.py (51KB, 1,300+ lines)

Capabilities

The CRM Agent can:
  • Search & Filter: Find companies, contacts, deals by any criteria
  • Create Records: Add new companies, contacts, deals from natural language
  • Update Records: Modify existing records based on descriptions
  • Analytics: Calculate metrics, trends, and insights
  • Relationships: Understand and query relationships between entities

Architecture

Key Components

Dependencies

  • Anthropic Claude: Natural language understanding
  • Supabase: Database operations
  • CRM Schema Intelligence: Understanding of CRM data model
  • Name Resolver: Fuzzy matching for entity names

Query Processing Flow

Example Queries

Search Queries

Create Operations

Analytics Queries

Relationship Queries

Schema Intelligence

CRM Schema Understanding

The agent has built-in knowledge of the CRM schema:

Intelligent Column Mapping

Maps natural language to database columns:

Name Resolution

Fuzzy Matching

Handles variations in entity names:

Confidence Scoring

API Integration

Via Prompts Router

Request/Response

Request:
Response:

Advanced Features

Multi-step Queries

Handles complex queries requiring multiple operations:

Context Awareness

Maintains context across queries:

Data Validation

Validates operations before execution:

Error Handling

Graceful Degradation

Query Clarification

Performance Optimization

Query Caching

Schema Caching

Batch Operations

Security

Firm-Level Isolation

All queries automatically filter by firm:

Permission Checks

SQL Injection Prevention

Uses parameterized queries:

Usage Examples

From Frontend

From Python Scripts

Configuration

Environment Variables

Monitoring

Logging

Metrics

Track key metrics:
  • Query success rate
  • Average execution time
  • Cache hit rate
  • Error rate by type

Future Enhancements

Support for “Change Acme Corp’s status to active”
“Archive all companies with no activity in 6 months”
“Compare Q4 2024 revenue to Q4 2023 by industry”
Voice-to-text query input for hands-free CRM

Troubleshooting

Solution: Rephrase query to be more specific, use exact column names
Solution: Check database indexes, use filters to reduce result set
Solution: Verify user role and firm_id, check RLS policies

Next Steps

Agentic Chat

Multi-agent system with CRM agent integration

API Reference

Direct CRM API endpoints

Database Schema

Understanding the CRM data model

Backend Overview

Complete backend architecture