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.
Idle on a full backlog of unusable prospects, and say why
Ethanc21277688074
diff --git a/harvey/cli.py b/harvey/cli.pyindex 7caf06b..c494f88 100644--- a/harvey/cli.py+++ b/harvey/cli.py@@ -203,6 +203,8 @@ def cmd_status(args):print("\n Harvey Pipeline Status")print(" " + "=" * 40)print(f" Prospects: {summary['prospects']}")+ print(f" Ready to write for: {summary.get('writable_prospects', 0)} "+ "(new, with a verified or catch-all email)")print(f" Draft campaigns: {summary['draft_campaigns']}")print(f" Active campaigns: {summary['active_campaigns']}")print(f" Open conversations: {summary['open_conversations']}")@@ -216,6 +218,12 @@ def cmd_status(args):# Status must still print when harvey.yaml is broken; that's# when people run it. The --check path reports config errors.notice = ""+ from harvey.main import unusable_backlog_notice+ backlog = unusable_backlog_notice(summary)+ if backlog:+ print(" Prospecting: PAUSED")+ print(textwrap.fill(backlog, width=72, initial_indent=" ",+ subsequent_indent=" "))if notice:print(" Sending: HELD")print(textwrap.fill(notice, width=72, initial_indent=" ",diff --git a/harvey/main.py b/harvey/main.pyindex 762e946..c1b2be1 100644--- a/harvey/main.py+++ b/harvey/main.py@@ -75,6 +75,36 @@ def seconds_until_quiet_hours_end(config: HarveyConfig) -> int:return max(int(delta.total_seconds()), 60)+# Stop prospecting once this many 'new' prospects are waiting. Past it, more+# leads only add to a backlog the Writer can't work through, or (when none+# has a usable email) spend search and verifier credits on people Harvey+# can never email.+PROSPECT_BACKLOG = 20+++def _new_counts(summary: dict) -> tuple[int, int]:+ """(all 'new' prospects, the ones the Writer can draft for)."""+ prospects = summary.get("prospects") or {}+ new = (prospects.get("new", 0) if isinstance(prospects, dict) else 0) or 0+ # A summary built without the writable count keeps the old rule.+ writable = summary.get("writable_prospects", new) or 0+ return new, writable+++def unusable_backlog_notice(summary: dict) -> str:+ """Why Harvey is idling on a full backlog of unusable prospects, or ""."""+ new, writable = _new_counts(summary)+ if writable or new < PROSPECT_BACKLOG:+ return ""+ return (+ f"{new} new prospects are waiting, but none has a verified or catch-all "+ "email, so Harvey has stopped prospecting to save search and verifier "+ "credits. Add an email verifier key (REOON_API_KEY, ZEROBOUNCE_API_KEY or "+ "HUNTER_API_KEY in .env) or check it still has credits, or export the list "+ "with `harvey export --all`."+ )++async def decide_next_action(brain: Brain,state: StateManager,@@ -91,11 +121,9 @@ async def decide_next_action(if summary is None:summary = await state.get_state_summary()- prospects = summary.get("prospects") or {}- new_prospects = prospects.get("new", 0) if isinstance(prospects, dict) else 0- # Only prospects the Writer can draft for count: one with a guessed email- # stays 'new' for good, and counting it starved Scout forever.- new_prospects = summary.get("writable_prospects", new_prospects) or 0+ # Only prospects the Writer can draft for trigger writing: one with a+ # guessed email stays 'new' for good, and counting it starved Scout.+ new_prospects, writable = _new_counts(summary)draft_campaigns = summary.get("draft_campaigns", 0) or 0open_conversations = summary.get("open_conversations", 0) or 0@@ -107,12 +135,15 @@ async def decide_next_action(action, reason = "handle_replies", f"{open_conversations} open conversation(s) waiting"elif deployable > 0:action, reason = "send_campaign", f"{draft_campaigns} draft campaign(s) ready to deploy"- elif new_prospects > 0:- action, reason = "write_campaign", f"{new_prospects} new prospect(s) with no drafts ready"- elif new_prospects < 20:+ elif writable > 0:+ action, reason = "write_campaign", f"{writable} new prospect(s) with no drafts ready"+ elif new_prospects < PROSPECT_BACKLOG:action, reason = "prospect", f"only {new_prospects} new prospect(s); pipeline needs leads"else:- action, reason = "idle", "pipeline is healthy; running analysis"+ action, reason = "idle", "backlog full; running analysis"+ notice = unusable_backlog_notice(summary)+ if notice:+ logger.warning(notice)logger.info(f"Decision: {action} ({reason})")return actiondiff --git a/tests/test_prospecting_stall.py b/tests/test_prospecting_stall.pyindex f7d38f1..3b3957c 100644--- a/tests/test_prospecting_stall.py+++ b/tests/test_prospecting_stall.py@@ -54,12 +54,28 @@ async def test_guessed_emails_alone_lead_back_to_prospecting(state):@pytest.mark.asyncio-async def test_many_guessed_emails_still_lead_back_to_prospecting(state):- # 20+ unusable prospects must not tip Harvey into idle either.- for n in range(25):+async def test_a_backlog_of_unusable_prospects_stops_spending_and_says_why(state):+ # With no usable email at all (say, no verifier key), prospecting every+ # cycle would burn search and verifier credits on people Harvey can+ # never email. At the backlog cap it idles, and status explains why.+ from harvey.main import PROSPECT_BACKLOG, unusable_backlog_notice+ for n in range(PROSPECT_BACKLOG):await add(state, n, f"p{n}@co{n}.test", "guess")summary = await state.get_state_summary()- assert await decide_next_action(None, state, CONFIG, summary=summary) == "prospect"+ assert await decide_next_action(None, state, CONFIG, summary=summary) == "idle"+ notice = unusable_backlog_notice(summary)+ assert str(PROSPECT_BACKLOG) in notice and "verifier" in notice+++async def test_no_backlog_notice_while_things_are_moving(state):+ from harvey.main import unusable_backlog_notice+ await add(state, 1, "[email protected]", "guess")+ assert unusable_backlog_notice(await state.get_state_summary()) == ""+ await add(state, 2, "[email protected]", "verified")+ for n in range(3, 30):+ await add(state, n, f"p{n}@co{n}.test", "guess")+ assert unusable_backlog_notice(await state.get_state_summary()) == ""@pytest.mark.asyncio