AI Systems · CRM · LLM ·

AI Agent for Customer Retention
& Campaign Automation

A decision-making CRM agent that starts with raw customer metrics, infers lifecycle context, selects the right marketing objective, and uses the OpenAI API to generate complete three-email campaign sequences ready for retention, win-back, or loyalty use cases.

AI Agents CRM Strategy Lifecycle Marketing OpenAI API
View on GitHub Back

Input

Starts with raw customer behavior

Uses transactional signals like recency, frequency, spend, and tenure as the starting point for CRM decisions.

Decision

Infers the right lifecycle objective

Transforms customer metrics into marketing logic such as churn risk, lifecycle stage, and campaign goal before writing.

Output

Generates complete campaign sequences

Delivers structured three-email CRM flows that connect analytical insight directly to execution-ready messaging.

From Customer Data to Campaign Execution

Customer data already tells a story: who is active, who is drifting away, and who drives most of the value. The challenge is not understanding the data, but knowing what to do next.

Translating these signals into clear lifecycle decisions, and then into actual campaigns, is often a fragmented and manual process.

This project explores how that gap can be reduced by connecting data, decision-making, and execution in a single flow.

An AI Agent That Makes Marketing Decisions Before It Writes

Instead of generating campaigns directly from raw data, the system introduces an intermediate decision step.

Customer behavior is first translated into actionable signals, which are used to define the campaign objective and context.

The generation layer then produces a campaign sequence that is consistent with that strategy, not just fluent, but purposeful.

Step 01

Load Transactional Inputs

Reads customer-level metrics from a structured dataset and prepares a reproducible working sample.

Step 02

Derive CRM Signals

Builds lifecycle, value, and engagement attributes from the raw behavior patterns.

Step 03

Infer Strategy

Chooses the marketing objective and customer brief before any campaign text is generated.

Step 04

Generate Email Sequence

Creates three coordinated lifecycle emails aligned to the selected objective and tone.

From One Customer Profile to Three Generated Emails

Real generated example: Customer 12677, an at-risk high-value buyer

This example uses one of the actual sampled customers from the generated output. The panel on the left shows the customer metrics and the derived CRM strategy, while the emails on the right show exactly how those signals were translated into a win-back sequence.

Customer Metrics
182
Recency Days
2
Purchases
$197.55
Avg. Order Value
$395.10
Total Revenue
111
Tenure Days
111
Avg. Days Between Orders
Derived CRM Logic
Segment Customer 12677 - At-Risk High-Value Buyer
Goal Win-back
Churn Risk High
Discount Sensitivity Medium
Timing Day 1 / Day 5 / Day 10
Why this sequence The customer has been inactive for 182 days, which is well beyond their usual 111-day gap, so the system escalates from a soft re-entry offer to a stronger time-bound incentive.

The Marketing Attributes Derived by the Agent

The most important part of the system is not the final copy. It is the intermediate marketing logic that reframes raw transactions into strategy-ready features the model can act on.

Why This Matters

1

Turns analytics into action

The agent closes the gap between customer-level metrics and ready-to-run lifecycle communication.

2

Standardizes campaign logic

Because the decision layer is explicit, CRM strategy becomes more consistent across use cases and operators.

3

Improves scalability

The workflow shows how a small set of interpretable customer signals can support repeatable personalization at scale.

4

Stays operational when generation fails

The fallback path means campaign creation can continue even when a live API call is unavailable.

Tools Used

The workflow is built in Python and organized as a modular CRM generation pipeline. It combines customer logic, prompt construction, campaign generation, and OpenAI API integration, while exporting usable outputs in JSON and CSV. The overall design emphasizes reproducibility, explainability, and graceful fallback behavior.