Quick overview
Youtube Video: https://youtu.be/MTHAZzOZCnQ?si=0k_06-RgGYHtC08v
This workflow runs daily to score customer “relationship drift” from Postgres metrics, uses Google Gemini to generate a structured diagnosis for medium/high-risk accounts, stores the assessment back in Postgres, and posts actionable alerts to Slack.
How it works
- Runs on a daily 07:00 schedule (or manually) to start the drift check.
- Pulls customer drift feature data from a Postgres view and calculates a rule-based risk score, level, and supporting signals for each customer.
- Sends only customers above the configured threshold to Postgres to fetch recent support tickets and communications context.
- Uses Google Gemini (via a LangChain agent) to produce a structured drift diagnosis, evidence, and recommended next action, then validates that the AI output cites known rule signal IDs.
- Merges AI-diagnosed and non-AI results, builds a consolidated record (including Slack message text and CRM payloads), and assigns an urgency and due date.
- Writes each assessment to a Postgres drift_assessments table and posts a Slack alert for actionable medium/high drift cases.
Setup
- Configure Postgres credentials and ensure the required objects exist (v_customer_drift_features view, support_tickets and communications tables, and the drift_assessments table/columns used by the INSERT).
- Add a Google Gemini (Google PaLM) API credential for the LangChain chat model used to generate the drift diagnosis.
- Add a Slack credential and set the target channel ID for where drift alerts should be posted.
- Review or adjust the cron schedule (currently 07:00 daily) and the rule thresholds inside the drift scoring code if you need different sensitivity.