-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwriter.py
More file actions
298 lines (254 loc) · 12.7 KB
/
Copy pathwriter.py
File metadata and controls
298 lines (254 loc) · 12.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
"""
AROS Writer — generates situation-aware cold emails using Claude.
"""
import json
import sys
import os
import anthropic
from config import ANTHROPIC_API_KEY
# MemCollab — cross-agent shared memory
sys.path.insert(0, os.path.join(os.path.dirname(__file__), "memcollab"))
try:
from memcollab import build_memory_injection
MEMCOLLAB_AVAILABLE = True
except ImportError:
MEMCOLLAB_AVAILABLE = False
client = anthropic.Anthropic(api_key=ANTHROPIC_API_KEY)
SYSTEM_PROMPT = """You write cold outreach emails for Aonxi.
Aonxi sells an autonomous revenue agent that finds clients, books meetings, and runs outreach 24/7 with zero human involvement. Price: $1,000-$3,000/month.
Target buyers: home care agencies, senior care franchises, residential cleaning services. These owners are too busy running operations to do sales themselves. That is the pain.
RULES — follow every one:
1. Under 120 words. Hard limit.
2. First line references something specific about their business or situation today.
3. Never use: synergy, leverage, streamline, optimize, revolutionary, game-changing, cutting-edge, AI, automation, technology, autonomous, agent, software, platform.
4. Sell the outcome only: more clients, without the owner doing any sales work.
5. One CTA: reply to this email or book a 15-minute call at https://calendar.app.google/gZ6V9ry93SQizZye8
6. Always use the exact calendar link above — never use a placeholder like [calendar link].
7. Sound like a human who did research. Not a SaaS company.
8. Plain text only. No bullets. No headers.
9. Subject line: under 8 words, curiosity not clickbait.
10. Sign off with just "Anmol" or no signature at all — just end with the CTA line. Never use [Your name] or any placeholder."""
# ── Defense Profiling ─────────────────────────────────────────────
DEFENSE_PROFILES = {
"MOTIVE_INFERENCE": {
"title_signals": {"vp", "director", "partner", "founder"},
"bypass_strategy": "PURE_DATA",
"forbidden_phrases": [
"excited", "reach out", "love to", "synergy", "opportunity",
"quick call", "touching base", "circle back", "on your radar",
],
},
"TACTIC_RECOGNITION": {
"title_signals": {"founder", "co-founder", "serial entrepreneur"},
"bypass_strategy": "SIGNAL_HOOK",
"forbidden_phrases": [
"I noticed you", "I came across", "relevant to your work",
"fellow founder", "as a fellow", "I saw that you",
"your impressive", "your amazing",
],
},
"OVERLOAD_AVOIDANCE": {
"title_signals": {"ceo", "owner", "operator", "president", "managing director"},
"bypass_strategy": "PURE_DATA",
"forbidden_phrases": [
"just wanted to", "hope this finds you", "I know you're busy",
"when you get a chance", "at your convenience", "quick question",
],
},
"SOCIAL_PROOF_SKEPTICISM": {
"title_signals": {"cto", "engineer", "vp engineering", "technical", "data", "architect"},
"bypass_strategy": "CREDIBILITY_FIRST",
"forbidden_phrases": [
"industry-leading", "best-in-class", "proven", "trusted by",
"world-class", "top-tier", "leading provider", "market leader",
],
},
}
BYPASS_INSTRUCTIONS = {
"PURE_DATA": "Open with a concrete number. Never open with 'I'. Lead with verifiable data. No persuasion language — let the numbers do the work.",
"SIGNAL_HOOK": "Open by referencing something specific from the last 7 days — their post, their hire, their news. Prove you did real research, not a template merge.",
"CREDIBILITY_FIRST": "Open with exact numbers and a public-verifiable proof point (GitHub link, public metric). No round numbers. No unverifiable claims.",
}
def _detect_defense_mode(prospect: dict) -> str:
"""Detect primary defense mode from prospect profile."""
# For AROS prospects, infer title from business context
company = (prospect.get("Business Name") or "").lower()
situation = (prospect.get("situation") or "").upper()
tier = prospect.get("icp_tier", "B")
# SMB owners are almost always OVERLOAD_AVOIDANCE
# They don't have time — inbox is flooded, they're running ops
if tier == "A" and situation == "STRUGGLING":
return "OVERLOAD_AVOIDANCE"
if tier == "A" and situation == "EXPANDING":
return "OVERLOAD_AVOIDANCE"
# Franchise owners who've seen sales pitches → MOTIVE_INFERENCE
if any(kw in company for kw in ("franchise", "homecare", "home care", "senior care", "executive")):
return "MOTIVE_INFERENCE"
# Cleaning / trade businesses → OVERLOAD_AVOIDANCE
if any(kw in company for kw in ("cleaning", "pro", "services", "care")):
return "OVERLOAD_AVOIDANCE"
return "OVERLOAD_AVOIDANCE"
def profile_defenses(target: dict) -> dict:
"""
Profile a target's psychological defenses against cold outreach.
Returns awareness_score, defense_mode, bypass_strategy, forbidden_phrases.
"""
situation = (target.get("situation") or "STABLE").upper()
tier = target.get("icp_tier", "B")
company = (target.get("Business Name") or "").lower()
# Awareness score: 0-10
score = 2 # SMB baseline is lower than VC/investor
if tier == "A":
score += 1
if situation == "STRUGGLING":
score += 2 # Desperate but also skeptical
elif situation == "EXPANDING":
score += 1 # Getting more pitches as they grow
if any(kw in company for kw in ("franchise", "executive", "senior")):
score += 2 # Franchise owners get hammered by vendors
# Estimate inbox volume
estimated_volume = 30 if tier == "B" else 60
if any(kw in company for kw in ("franchise", "homecare", "home care")):
estimated_volume = 100
if estimated_volume >= 80:
score += 1
score = min(score, 10)
defense_mode = _detect_defense_mode(target)
profile = DEFENSE_PROFILES[defense_mode]
return {
"awareness_score": score,
"defense_mode": defense_mode,
"bypass_strategy": profile["bypass_strategy"],
"forbidden_phrases": profile["forbidden_phrases"],
"estimated_weekly_cold_emails": estimated_volume,
}
def write_email(prospect: dict, use_defense_profiling: bool = True) -> dict:
"""
Generate a cold email for a scored + harvested prospect.
When use_defense_profiling=True, applies defense-aware bypass strategy.
Returns dict with: subject, body, predicted_reply_tier, defense_profile
"""
first = prospect.get("First Name", "")
last = prospect.get("Last Name", "")
company = prospect.get("Business Name", "")
city = prospect.get("City", "")
state = prospect.get("State", "")
situation = prospect.get("situation", "STABLE")
hook = prospect.get("hook", "")
evidence = prospect.get("signal_evidence", [])
tier = prospect.get("icp_tier", "B")
# Defense profiling
defense = profile_defenses(prospect) if use_defense_profiling else None
# Build system prompt with defense layer
system = SYSTEM_PROMPT
if defense:
banned = ", ".join(f'"{p}"' for p in defense["forbidden_phrases"])
bypass_instruction = BYPASS_INSTRUCTIONS[defense["bypass_strategy"]]
system += f"""
DEFENSE PROFILE (awareness: {defense['awareness_score']}/10, mode: {defense['defense_mode']}):
BANNED WORDS — never use any of these phrases: {banned}
WRITING STRATEGY: {bypass_instruction}"""
# Enforce word limit for OVERLOAD_AVOIDANCE
if defense["defense_mode"] == "OVERLOAD_AVOIDANCE":
system += "\nHARD OVERRIDE: Under 60 words. One specific ask. Include a specific calendar slot, never 'let me know'."
# MemCollab: inject cross-agent learned patterns
if defense and MEMCOLLAB_AVAILABLE:
memory_ctx = build_memory_injection(defense["defense_mode"], vertical="home_care")
if memory_ctx:
system += memory_ctx
user_prompt = f"""Write a cold email to:
Name: {first} {last}
Company: {company}
City: {city} {state}
Situation: {situation}
Hook: {hook}
Signal evidence: {evidence}
Make it feel written for this specific person today. Not a template.
Return JSON only:
{{
"subject": "...",
"body": "..."
}}"""
response = client.messages.create(
model="claude-haiku-4-5-20251001",
max_tokens=512,
system=system,
messages=[{"role": "user", "content": user_prompt}],
)
raw = response.content[0].text.strip()
# Parse JSON — handle markdown code fences if present
if raw.startswith("```"):
raw = raw.split("\n", 1)[1]
raw = raw.rsplit("```", 1)[0]
raw = raw.strip()
data = json.loads(raw)
# Determine reply tier
if tier == "A" and situation == "STRUGGLING":
reply_tier = "HOT"
elif tier == "A" and situation in ("EXPANDING", "STABLE"):
reply_tier = "WARM"
else:
reply_tier = "COLD"
return {
"subject": data["subject"],
"body": data["body"],
"predicted_reply_tier": reply_tier,
"defense_profile": defense,
}
if __name__ == "__main__":
test_cases = [
{
"First Name": "Mark", "Last Name": "Gould",
"Business Name": "Synergy Homecare", "City": "Chicago", "State": "IL",
"situation": "EXPANDING", "icp_tier": "A",
"signal_evidence": ["Actively hiring caregivers"],
"hook": "Your growth is creating a client pipeline gap. Every new hire needs 3-5 clients to be profitable. We fill that gap autonomously.",
},
{
"First Name": "Emmah", "Last Name": "Muita",
"Business Name": "Executive Home Care", "City": "Hackensack", "State": "NJ",
"situation": "STRUGGLING", "icp_tier": "A",
"signal_evidence": ["Staffing issues in reviews", "Recent expansion news"],
"hook": "Every week without a full roster costs you roughly one caregiver's salary. Autonomous outreach fixes this in 30 days without you lifting a finger.",
},
{
"First Name": "Tony", "Last Name": "Gibbs",
"Business Name": "All Pro Cleaning", "City": "Dallas", "State": "TX",
"situation": "STABLE", "icp_tier": "A",
"signal_evidence": ["No strong signals detected — baseline stable"],
"hook": "The top home care agencies in your area are quietly automating client acquisition. Here is what that looks like and what it means for your territory.",
},
]
print("━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━")
print("DEFENSE PROFILING TEST — 3 AROS CUSTOMERS")
print("━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━")
for i, tc in enumerate(test_cases, 1):
print(f"\n{'='*50}")
print(f" PROSPECT {i}: {tc['First Name']} {tc['Last Name']} | {tc['Business Name']}")
print(f" Situation: {tc['situation']} | Tier: {tc['icp_tier']}")
print(f"{'='*50}")
# Defense profile
defense = profile_defenses(tc)
print(f"\n DEFENSE PROFILE:")
print(f" Awareness Score: {defense['awareness_score']}/10")
print(f" Defense Mode: {defense['defense_mode']}")
print(f" Bypass Strategy: {defense['bypass_strategy']}")
print(f" Est. Weekly Spam: ~{defense['estimated_weekly_cold_emails']} emails")
print(f" Forbidden: {defense['forbidden_phrases']}")
# Email WITHOUT defense profiling
print(f"\n ── EMAIL WITHOUT DEFENSE PROFILING ──")
result_naive = write_email(tc, use_defense_profiling=False)
print(f" SUBJECT: {result_naive['subject']}")
print(f" ─────────────────────────────────")
for line in result_naive["body"].split("\n"):
print(f" {line}")
# Email WITH defense profiling
print(f"\n ── EMAIL WITH DEFENSE PROFILING ──")
result_defense = write_email(tc, use_defense_profiling=True)
print(f" SUBJECT: {result_defense['subject']}")
print(f" Reply tier: {result_defense['predicted_reply_tier']}")
print(f" ─────────────────────────────────")
for line in result_defense["body"].split("\n"):
print(f" {line}")
print(f" ─────────────────────────────────")
print("\n━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━")