In the Subscription and SaaS world, churn is the silent killer. Most companies rely on standard structured metrics to predict it: Monthly Recurring Revenue (MRR), contract length, and login frequency. While these are useful, they are often lagging indicators. By the time a user’s login frequency drops by 50%, they have already mentally checked out. To build a truly predictive churn model, we must look beyond the database rows. The biggest impact on classification performance comes from behavioral and semantic feature engineering. Specifically, three categories of features consistently drive accuracy:
Velocity & Acceleration Metrics: It’s not just about how many times a user logged in; it’s about the rate of change. A drop from 10 logins/week to 8 is less concerning than a drop from 8 to 2.
Support Sentiment & Topic Clustering: Using NLP to extract the "emotional velocity" of support tickets. A user who moves from "How-to" questions to "Billing/Complaint" topics is a high-risk signal.
Feature Adoption Breadth vs. Depth: A user who uses one feature heavily is "sticky," but a user who uses five different modules is "embedded." A reduction in this breadth is a leading indicator of churn.
Here is an end-to-end guide on how to build a multi-agent predictive workflow that engineers these features in real-time using LangGraph, RAG, and persistent memory.
The Use Case: Proactive Retention for an Enterprise Project Management SaaS
The Scenario: "TaskFlow," a B2B project management platform, has 5,000 enterprise seats. The Customer Success (CS) team is overwhelmed and can only manually review accounts with MRR over $5k/month.
The Problem: High-value mid-market accounts ($1k-$5k MRR) are churning unexpectedly. The structured data shows they are still logging in, so the traditional "low usage" alerts never trigger.
The Predictive RAG Solution: A multi-agent system continuously monitors user behavior. It doesn't just count logins; it engineers complex behavioral features by combining structured usage logs with unstructured support ticket sentiment. When it detects a "Silent Churn" pattern (stable logins but declining feature breadth and negative support sentiment), it proactively alerts the CS team with a specific retention playbook.

The Multi-Agent Workflow
We use LangGraph to orchestrate three agents, focusing on the transformation of raw data into high-signal features.
The Behavioral Engineer (Feature Extraction Agent): Ingests raw structured logs. It calculates velocity, acceleration, and feature adoption breadth/depth metrics.
The Sentiment Analyst (RAG Agent): Retrieves recent support tickets and community forum posts. It uses an LLM to extract semantic topics and sentiment scores, converting unstructured text into structured "Emotional Velocity" features.
The Churn Oracle (Classification & Memory Agent): Takes the engineered features and queries long-term memory for historical churn patterns. It runs a classification logic (simulated via LLM reasoning) to output a Churn Probability Score and a recommended retention action.
Code Implementation
Below is the complete Python implementation using LangGraph.
1. Setup and State Definition
from typing import TypedDict, List, Dict, Any, Optional
from langgraph.graph import StateGraph, END
from langgraph.checkpoint.memory import MemorySaver
from langchain_core.messages import HumanMessage, AIMessage
# Define the shared state for the SaaS predictive workflow
class SaaSState(TypedDict):
account_id: str
plan_tier: str
# Raw Structured Inputs
current_mrr: float
login_count_last_30d: int
login_count_prev_30d: int
feature_modules_used: List[str]
# Engineered Features (The "Hidden Signals")
login_velocity_change: float # % change in logins
feature_breadth_score: int # Number of unique modules used
support_sentiment_score: float # -1.0 (Negative) to 1.0 (Positive)
dominant_support_topic: str
# Classification Outputs
churn_probability: float
risk_category: str # Low, Medium, High, Critical
# Action Outputs
retention_playbook: str
# Memory context
historical_churn_patterns: str
messages: List[Any]
2. Mock Tools for Feature Engineering and RAG
def calculate_behavioral_features(state: SaaSState) -> Dict[str, Any]:
"""Agent 1: Engineers velocity and adoption features from raw logs."""
current_logins = state["login_count_last_30d"]
prev_logins = state["login_count_prev_30d"]
modules = state["feature_modules_used"]
# Feature 1: Login Velocity Change
if prev_logins > 0:
velocity_change = ((current_logins - prev_logins) / prev_logins) * 100
else:
velocity_change = 0.0
# Feature 2: Feature Breadth Score
breadth_score = len(modules)
print(f"[Engineer] Calculated Velocity Change: {velocity_change:.2f}%, Breadth Score: {breadth_score}")
return {
"login_velocity_change": velocity_change,
"feature_breadth_score": breadth_score
}
def retrieve_and_analyze_sentiment(account_id: str) -> Dict[str, Any]:
"""Agent 2: RAG-based extraction of sentiment and topics from support tickets."""
# In production: Vector DB search for recent tickets + LLM sentiment analysis
# Mocking a scenario where a user is frustrated with a specific feature
return {
"support_sentiment_score": -0.65, # Negative sentiment
"dominant_support_topic": "Integration Failures"
}
def retrieve_historical_patterns(plan_tier: str, topic: str) -> str:
"""Mock retrieval of past churn reasons from long-term memory."""
return f"MEMORY: In the '{plan_tier}' tier, accounts showing '{topic}' combined with a velocity drop > 20% had an 85% churn rate within 60 days. Successful retention involved offering a dedicated integration specialist."

Join the conversation! Your thoughts help the community grow.