Skip to content

Autonomous AI sales agent powered by Claude Code or Codex. Finds prospects, writes cold emails, sends campaigns, handles replies, books meetings. No API keys needed — runs on your Claude or Codex subscriptions.

Harden #29: no double contact, catch-all inboxes stay risky, Humanizer opt-in

Ethan9fccd6991604
diff --git a/README.md b/README.md
index e544bea..dfbb969 100644
--- a/README.md
+++ b/README.md
@@ -226,6 +226,8 @@ Agency detection is the compounding one. Almost every agency credits itself in t
Free public registries first. Name plus title from the team page, confirmed against an authoritative registry where one exists — which also filters out your own parsing artifacts, because a "person" who matches nothing usually wasn't one.
+When a company's site names nobody and Harvey has no contact there yet — common for small trades — it falls back to a general address the company prints on its own homepage or contact page (`owner@`, `office@`, `info@` preferred; `careers@`, `noreply@` and similar skipped). It is never guessed, it is verified like any other address, and those emails greet the company's team instead of a first name.
+
### 4. VERIFY — can you reach them
Harvey learns each company's **address pattern** and verifies one candidate, rather than brute-forcing name variations. Raw SMTP probing is not viable from a laptop — outbound port 25 is usually blocked, and Google Workspace and Microsoft 365 accept everything from an unknown IP.
@@ -404,6 +406,7 @@ channels:
send_to_risky, max_bounce_rate }
usage: { max_daily_claude_percent, heartbeat_interval_minutes, quiet_hours }
brain: { provider: claude | codex, model, reasoning_effort } # optional; claude by default
+writer: { humanizer } # optional; true adds one editing pass per batch using ~/.claude/skills/humanizer/SKILL.md
```
`max_daily_claude_percent` caps whichever subscription `brain.provider` uses (the name predates Codex support).
diff --git a/harvey/agents/handler.py b/harvey/agents/handler.py
index 8f2b168..bf31dcb 100644
--- a/harvey/agents/handler.py
+++ b/harvey/agents/handler.py
@@ -12,7 +12,7 @@ from datetime import datetime, timezone
from harvey.brain import Brain, BrainUnavailable
from harvey.config import HarveyConfig, EnvConfig
-from harvey.humanize import humanize
+from harvey.humanize import humanize, humanizer_enabled
from harvey.integrations.instantly import InstantlyClient
from harvey.integrations.mail_provider import NATIVE_PROVIDERS, get_mail_provider
from harvey.models.conversation import Conversation, Message
@@ -670,5 +670,8 @@ Write a reply that:"""
if response.lower().startswith(("i can't", "i cannot", "as an ai", "sorry,")):
logger.warning("Handler: Model returned meta-text instead of an email. Discarding.")
return ""
- polished = await humanize(self.brain, [{"subject": "", "body": response}], agent="handler")
+ polished = await humanize(
+ self.brain, [{"subject": "", "body": response}], agent="handler",
+ enabled=humanizer_enabled(self.config),
+ )
return polished[0]["body"]
diff --git a/harvey/agents/scout.py b/harvey/agents/scout.py
index d437d34..7c94139 100644
--- a/harvey/agents/scout.py
+++ b/harvey/agents/scout.py
@@ -1421,6 +1421,7 @@ Respond ONLY with the JSON array."""
return []
contacts: list[Prospect] = []
+ named_on_site = False
for member in team_members:
title = member.get("title", "")
if not self._title_matches_icp(title):
@@ -1430,6 +1431,7 @@ Respond ONLY with the JSON array."""
last_name = member.get("last_name", "")
if not first_name or not last_name:
continue
+ named_on_site = True
email, email_status = await self._resolve_email(
first_name, last_name, domain
@@ -1459,7 +1461,11 @@ Respond ONLY with the JSON array."""
self._remember_prospect(prospect)
contacts.append(prospect)
- if not contacts:
+ # The inbox is a last resort for a company nobody at Harvey has a
+ # contact for. A named person found here (even one skipped as a
+ # duplicate on a revisit) or already on file from another source
+ # means the company is covered: never email it a second time.
+ if not contacts and not named_on_site and await self._company_uncontacted(company_id):
inbox = await self._company_inbox_prospect(
company_id, domain, company_name, industry, signal_note,
)
@@ -1467,6 +1473,16 @@ Respond ONLY with the JSON array."""
contacts.append(inbox)
return contacts
+ async def _company_uncontacted(self, company_id: str) -> bool:
+ """True only when the company is on file and has no prospects yet."""
+ if not company_id:
+ return False
+ try:
+ return not await self.state.get_contacts_for_company(company_id)
+ except Exception as e:
+ logger.debug(f"Contact lookup failed for company {company_id}: {e}")
+ return False
+
async def _company_inbox_prospect(
self, company_id: str, domain: str, company_name: str,
industry: str, signal_note: str = "",
diff --git a/harvey/agents/writer.py b/harvey/agents/writer.py
index 637954f..564832c 100644
--- a/harvey/agents/writer.py
+++ b/harvey/agents/writer.py
@@ -15,7 +15,7 @@ from datetime import datetime, timezone
from harvey.brain import Brain
from harvey.config import HarveyConfig
-from harvey.humanize import humanize
+from harvey.humanize import humanize, humanizer_enabled
from harvey.integrations.mail_provider import NATIVE_PROVIDERS
from harvey.models.campaign import Campaign, EmailStep
from harvey.state import StateManager
@@ -151,7 +151,10 @@ class Writer:
pending.append((prospect, draft))
# One Humanizer pass over the whole batch before anything is staged.
- polished = await humanize(self.brain, [d for _, d in pending], agent="writer")
+ polished = await humanize(
+ self.brain, [d for _, d in pending], agent="writer",
+ enabled=humanizer_enabled(self.config),
+ )
drafted = 0
for (prospect, _), draft in zip(pending, polished):
@@ -331,7 +334,7 @@ Return ONLY a JSON array (no markdown fences, no commentary):
steps = self._parse_sequence(result)
polished = await humanize(
self.brain, [{"subject": s.subject, "body": s.body} for s in steps],
- agent="writer",
+ agent="writer", enabled=humanizer_enabled(self.config),
)
for step, draft in zip(steps, polished):
step.subject, step.body = draft["subject"], draft["body"]
diff --git a/harvey/config.py b/harvey/config.py
index 36d866f..642eb7d 100644
--- a/harvey/config.py
+++ b/harvey/config.py
@@ -257,6 +257,14 @@ class BrainConfig(BaseModel):
return v
+class WriterConfig(BaseModel):
+ # Run every draft through one extra editing-only brain call using the
+ # Humanizer skill's instructions (~/.claude/skills/humanizer/SKILL.md,
+ # or HARVEY_HUMANIZER_SKILL). Off by default: installing the skill for
+ # your own Claude Code use never changes what Harvey sends on its own.
+ humanizer: bool = False
+
+
class HarveyConfig(BaseModel):
persona: PersonaConfig
product: ProductConfig
@@ -265,6 +273,7 @@ class HarveyConfig(BaseModel):
usage: UsageConfig = UsageConfig()
brain: BrainConfig = BrainConfig()
compliance: ComplianceConfig = ComplianceConfig()
+ writer: WriterConfig = WriterConfig()
class EnvConfig(BaseModel):
diff --git a/harvey/humanize.py b/harvey/humanize.py
index d04deaa..0b96510 100644
--- a/harvey/humanize.py
+++ b/harvey/humanize.py
@@ -5,8 +5,12 @@ Claude Code skill can't be invoked directly. Instead the skill's
instructions are read from the operator's skills folder and sent as a
second, editing-only call over drafts that are already written.
+Off unless ``writer.humanizer: true`` is set in harvey.yaml; the skill
+being installed is not enough on its own.
+
Fails open: no skill file, a failed call, or a rewrite that breaks a rule
-(lost merge variable, new em dash, much longer) keeps the original draft.
+(lost merge variable, new em dash, much longer, meta-text) keeps the
+original draft.
Every draft still passes the deterministic pre-send gate afterwards.
"""
@@ -26,6 +30,13 @@ SKILL_PATH = Path(
)
MERGE_VAR = re.compile(r"\{\{\s*\w+\s*\}\}")
MAX_GROWTH = 1.2 # a rewrite may not be more than 20% longer than the draft
+# A rewrite that talks about itself instead of being the email.
+META_PREFIXES = ("i can't", "i cannot", "as an ai", "sorry,", "here is", "here's")
+
+
+def humanizer_enabled(config) -> bool:
+ """True only when the operator turned the pass on in harvey.yaml."""
+ return bool(getattr(getattr(config, "writer", None), "humanizer", False))
def load_skill(path: Path | None = None) -> str:
@@ -48,6 +59,8 @@ def _acceptable(original: dict, rewrite) -> bool:
subject = str(rewrite.get("subject") or "").strip()
if not body or (original.get("subject") and not subject):
return False
+ if body.lower().startswith(META_PREFIXES):
+ return False
before = original.get("subject", "") + original["body"]
after = subject + body
if sorted(MERGE_VAR.findall(before)) != sorted(MERGE_VAR.findall(after)):
@@ -57,14 +70,21 @@ def _acceptable(original: dict, rewrite) -> bool:
return len(body.split()) <= len(original["body"].split()) * MAX_GROWTH + 2
-async def humanize(brain, drafts: list[dict], agent: str, path: Path | None = None) -> list[dict]:
+async def humanize(
+ brain, drafts: list[dict], agent: str,
+ path: Path | None = None, enabled: bool = False,
+) -> list[dict]:
"""Return ``drafts`` ({"subject", "body"} dicts) rewritten by the skill.
+ A no-op unless ``enabled`` (see ``humanizer_enabled``).
+
One brain call for the whole list. Any draft whose rewrite fails a check
comes back unchanged, so the result always has the same length and order.
"""
+ if not enabled or not drafts:
+ return drafts
skill = load_skill(path)
- if not drafts or not skill:
+ if not skill:
return drafts
payload = [{"subject": d.get("subject", ""), "body": d["body"]} for d in drafts]
diff --git a/harvey/integrations/email_finder.py b/harvey/integrations/email_finder.py
index f6a3baf..b36d936 100644
--- a/harvey/integrations/email_finder.py
+++ b/harvey/integrations/email_finder.py
@@ -557,10 +557,10 @@ async def _verify_candidate(email: str, mx_type: str, env) -> tuple[Optional[str
async def verify_published_address(email: str, env=None) -> str:
"""Grade an address the company publishes on its own website.
- Unlike a pattern guess, a published address is known to be used, so a
- catch-all verdict (the domain accepts every address) doesn't make it
- risky: it counts as verified. A verifier's invalid verdict still wins,
- and an inconclusive check stays an honest guess that is never sent.
+ Graded like any other address: a catch-all verdict stays "risky", so
+ ``send_to_risky`` still decides whether it is sent (a published address
+ can be stale). A verifier's invalid verdict wins, and an inconclusive
+ check stays an honest guess that is never sent.
"""
email = (email or "").strip().lower()
domain = email.partition("@")[2]
@@ -570,8 +570,6 @@ async def verify_published_address(email: str, env=None) -> str:
if not mx_host:
return "invalid"
status, _ = await _verify_candidate(email, classify_mx(mx_host), env)
- if status == "risky":
- return "verified"
return status or "guess"
diff --git a/tests/test_company_inbox.py b/tests/test_company_inbox.py
index 1c0379f..49af1e8 100644
--- a/tests/test_company_inbox.py
+++ b/tests/test_company_inbox.py
@@ -53,7 +53,7 @@ def test_reoon_verdicts(verdict, expected):
@pytest.mark.parametrize("graded, expected", [
("verified", "verified"),
- ("risky", "verified"), # published on their site, so catch-all is fine
+ ("risky", "risky"), # catch-all stays risky: send_to_risky decides
("invalid", "invalid"),
(None, "guess"), # inconclusive stays a guess: never sent
])
@@ -131,6 +131,75 @@ async def test_inbox_prospect_carries_its_verification(monkeypatch):
assert p.is_company_inbox and p.company_id == "c1"
+# ── fallback only when the company has nobody ──
+
+def fallback_scout(team, existing=(), duplicate=False):
+ """A Scout whose team page, email resolution and DB are stand-ins."""
+ scout = Scout.__new__(Scout)
+ scout._seen_prospect_keys = set()
+ scout.inbox_calls = 0
+
+ async def scrape(domain):
+ return team
+
+ async def resolve(first, last, domain):
+ return f"{first.lower()}@acme.com", "verified"
+
+ async def is_dup(prospect):
+ return duplicate
+
+ async def existing_contacts(company_id):
+ return list(existing)
+
+ async def inbox_prospect(*args, **kw):
+ scout.inbox_calls += 1
+ return inbox()
+
+ scout._scrape_team_page = scrape
+ scout._title_matches_icp = lambda title: True
+ scout._resolve_email = resolve
+ scout._infer_seniority = lambda title: ""
+ scout._is_duplicate_prospect = is_dup
+ scout._company_inbox_prospect = inbox_prospect
+ scout.state = SimpleNamespace(get_contacts_for_company=existing_contacts)
+ return scout
+
+
+OWNER = [{"first_name": "Jo", "last_name": "Li", "title": "Owner"}]
+
+
+async def test_inbox_used_when_the_site_names_nobody():
+ scout = fallback_scout(team=[])
+ contacts = await scout._contacts_from_company("c1", "acme.com", "Acme", "Roofing")
+ assert [p.is_company_inbox for p in contacts] == [True]
+
+
+async def test_no_inbox_when_the_named_owner_is_already_a_prospect():
+ # A revisit: the owner is skipped as a duplicate, but the company must
+ # not be emailed a second time through info@.
+ scout = fallback_scout(team=OWNER, duplicate=True)
+ assert await scout._contacts_from_company("c1", "acme.com", "Acme", "Roofing") == []
+ assert scout.inbox_calls == 0
+
+
+async def test_no_inbox_when_the_company_already_has_a_contact():
+ # Someone at the company came from another source (LinkedIn, a job board).
+ known = Prospect(first_name="Jo", last_name="Li", title="Owner", email="[email protected]")
+ scout = fallback_scout(team=[], existing=[known])
+ assert await scout._contacts_from_company("c1", "acme.com", "Acme", "Roofing") == []
+ assert scout.inbox_calls == 0
+
+
+async def test_no_inbox_without_a_company_record():
+ scout = fallback_scout(team=[])
+ assert await scout._contacts_from_company("", "acme.com", "Acme", "Roofing") == []
+ assert scout.inbox_calls == 0
+
+
# ── writer ──
def test_inbox_prospects_get_their_own_campaign():
diff --git a/tests/test_humanize.py b/tests/test_humanize.py
index 98ee2b9..a53f4df 100644
--- a/tests/test_humanize.py
+++ b/tests/test_humanize.py
@@ -2,7 +2,8 @@
import pytest
-from harvey.humanize import humanize, load_skill
+from harvey.config import HarveyConfig
+from harvey.humanize import humanize, humanizer_enabled, load_skill
class FakeBrain:
@@ -38,7 +39,7 @@ def test_missing_skill_is_a_no_op(tmp_path):
@pytest.mark.asyncio
async def test_no_skill_makes_no_call(tmp_path):
brain = FakeBrain([])
- assert await humanize(brain, [DRAFT], "writer", path=tmp_path / "nope.md") == [DRAFT]
+ assert await humanize(brain, [DRAFT], "writer", path=tmp_path / "nope.md", enabled=True) == [DRAFT]
assert brain.prompts == []
@@ -46,7 +47,7 @@ async def test_no_skill_makes_no_call(tmp_path):
async def test_good_rewrite_is_used(skill):
rewrite = {"subject": "after five", "body": "Hi {{first_name}}, who picks up the phone after five?"}
brain = FakeBrain([rewrite])
- out = await humanize(brain, [DRAFT], "writer", path=skill)
+ out = await humanize(brain, [DRAFT], "writer", path=skill, enabled=True)
assert out == [rewrite]
assert "Cut the tells." in brain.prompts[0]
@@ -56,23 +57,59 @@ async def test_good_rewrite_is_used(skill):
{"subject": "after five", "body": "Hi {{first_name}} — who picks up after five?"}, # new em dash
{"subject": "", "body": "Hi {{first_name}}, who picks up after five?"}, # dropped subject
{"subject": "after five", "body": "Hi {{first_name}}, " + "word " * 40}, # much longer
+ {"subject": "after five", "body": "As an AI, I rewrote it: Hi {{first_name}}, who picks up?"}, # meta-text
"not a dict",
])
@pytest.mark.asyncio
async def test_bad_rewrite_keeps_original(skill, bad):
- out = await humanize(FakeBrain([bad]), [DRAFT], "writer", path=skill)
+ out = await humanize(FakeBrain([bad]), [DRAFT], "writer", path=skill, enabled=True)
assert out == [DRAFT]
@pytest.mark.asyncio
async def test_wrong_shape_or_failure_keeps_all(skill):
- assert await humanize(FakeBrain([]), [DRAFT], "writer", path=skill) == [DRAFT]
- assert await humanize(FakeBrain(None), [DRAFT], "writer", path=skill) == [DRAFT]
- assert await humanize(FakeBrain(RuntimeError("down")), [DRAFT], "writer", path=skill) == [DRAFT]
+ assert await humanize(FakeBrain([]), [DRAFT], "writer", path=skill, enabled=True) == [DRAFT]
+ assert await humanize(FakeBrain(None), [DRAFT], "writer", path=skill, enabled=True) == [DRAFT]
+ assert await humanize(FakeBrain(RuntimeError("down")), [DRAFT], "writer", path=skill, enabled=True) == [DRAFT]
@pytest.mark.asyncio
async def test_reply_without_subject(skill):
reply = {"subject": "", "body": "Sure, Thursday works. What time suits you?"}
- out = await humanize(FakeBrain([reply]), [{"subject": "", "body": "Sure! Thursday works for me. What time suits you best?"}], "handler", path=skill)
+ out = await humanize(FakeBrain([reply]), [{"subject": "", "body": "Sure! Thursday works for me. What time suits you best?"}], "handler", path=skill, enabled=True)
assert out == [reply]
+
+
+async def test_installed_skill_alone_does_not_turn_it_on(skill):
+ # Installing the skill for Claude Code must not change what Harvey sends.
+ brain = FakeBrain([{"subject": "after five", "body": "Hi {{first_name}}, who picks up?"}])
+ assert await humanize(brain, [DRAFT], "writer", path=skill) == [DRAFT]
+ assert brain.prompts == []
+
+
+def _config(**extra):
+ base = {
+ "persona": {
+ "name": "H", "company": "A", "role": "B",
+ "email": "[email protected]", "linkedin": "", "tone": "casual",
+ },
+ "product": {
+ "name": "P", "description": "D", "pricing": "$1",
+ "key_benefits": ["x"], "objection_responses": {},
+ },
+ "icp": {
+ "industries": ["SaaS"], "company_size": "10-50",
+ "titles": ["CEO"], "geography": ["US"],
+ },
+ }
+ return HarveyConfig(**{**base, **extra})
+
+
+def test_humanizer_is_off_by_default():
+ assert humanizer_enabled(_config()) is False
+ assert humanizer_enabled(None) is False
+
+
+def test_humanizer_opt_in_from_config():
+ assert humanizer_enabled(_config(writer={"humanizer": True})) is True