🔑
Idempotency Gate (WF-01)
Every incoming event gets a deterministic SHA-256 key computed from its identity fields. Duplicates (same lead seen again within the scan window) are silently dropped before any enrichment or outreach runs.
def make_event_key(event_data, key_fields=None):
fields = key_fields or ["id", "source", "url", "company", "email"]
parts = [str(event_data.get(f, "")) for f in fields]
raw = "|".join(parts).encode("utf-8")
return hashlib.sha256(raw).hexdigest()[:16]
make_event_key({"source": "intent_radar", "company": "Acme Technologies",
"email": "alex@acme.example.com"})
🌡️
Warmth Decay Formula (WF-06)
Lead "temperature" decays 10% per inactive day. A recent reply boosts warmth by +30 (capped at 100). Warmth bucket drives nurture cadence: hot = immediate, cold = re-activation sequence.
def apply_warmth_decay(warmth, days_inactive, has_recent_reply=False):
decayed = warmth * math.pow(0.9, max(0.0, days_inactive))
result = round(decayed)
if has_recent_reply:
result = min(100, result + 30)
return result
apply_warmth_decay(60, days_inactive=1)
apply_warmth_decay(60, days_inactive=7)
apply_warmth_decay(60, days_inactive=1,
has_recent_reply=True)
🗳️
Multi-LLM Consensus (WF-03)
Three models score the lead independently. Weighted average gives the consensus score. If max−min > 0.3 (30% divergence), the lead is escalated to Human Review rather than auto-approved.
def compute_consensus_score(scores, weights=None):
w = weights or [1.0] * len(scores)
consensus = sum(s*wt for s,wt in zip(scores,w)) / sum(w)
divergence = max(scores) - min(scores)
return {"score": round(consensus,3),
"agreement": divergence <= 0.3,
"divergence": round(divergence,3)}
compute_consensus_score([0.82, 0.75, 0.79],
weights=[1.0, 0.9, 1.1])
⚠️
Error Classification + Retry Policy (WF-10)
All workflow failures route to the Global Error Handler. Severity is classified by first regex match. Critical errors page immediately; warnings batch to Slack digest; info is logged only.
def classify_error_severity(error_message):
if re.search(r"timeout|ECONNREFUSED|401|403|5\d\d|fatal", msg):
return "CRITICAL"
if re.search(r"rate|retry|warn|429", msg):
return "WARNING"
return "INFO"
👤
Human-in-the-Loop Design (WF-04)
Two stop-points keep humans in control: (1) before first outreach for all high-value leads, (2) when multi-LLM divergence exceeds 30%. Slack interactive buttons allow approve / edit / reject without leaving the chat.
if consensus["agreement"] == False:
→ Human review (mandatory)
if lead["enrichment_score"] >= 0.75:
→ Human review (standard)
🔬
Shadow Mode Validation (WF-09)
Before promoting a new workflow version to production, it runs in shadow mode on real leads. Results are compared against production output without affecting real outreach. Delta score decides promotion.
1. New WF version runs in parallel → shadow draft
2. AI compares shadow vs production draft quality
3. compute delta_score = shadow_score - prod_score
4. if delta_score > 0.05:
Slack alert → manual promotion decision
elif delta_score < -0.05:
Slack alert → block promotion
else:
Log "no significant diff" → auto-promote option