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.

Rewrite scout: Python searches, Claude only scores/personalizes

Ethan5879533f81b1
diff --git a/harvey/agents/scout.py b/harvey/agents/scout.py
index 8d37fda..6196f27 100644
--- a/harvey/agents/scout.py
+++ b/harvey/agents/scout.py
@@ -1,8 +1,15 @@
-"""Scout — DIY prospecting without expensive tools."""
+"""Scout — DIY prospecting without expensive tools.
+Architecture: Python does ALL web searching/scraping. Claude only
+analyzes, scores, and personalizes data that Python already found.
+This avoids model-level refusals when asking Claude to research
+real people/companies.
+"""
+
+import json
import logging
import re
-from urllib.parse import quote_plus
+from urllib.parse import quote_plus, urlparse
import httpx
from bs4 import BeautifulSoup
@@ -11,6 +18,7 @@ from harvey.brain import Brain
from harvey.config import HarveyConfig, EnvConfig
from harvey.integrations.email_finder import find_email
from harvey.integrations.linkedin import LinkedInAutomation
+from harvey.models.company import Company
from harvey.models.prospect import Prospect
from harvey.state import StateManager
@@ -29,12 +37,12 @@ class Scout:
self.state = state
self.config = config
self.env = env
+ self.skills = ""
async def run(self):
"""Main prospecting flow: find leads matching ICP."""
logger.info("Scout: Starting prospecting cycle...")
- # Load foundational skills for this agent
self.skills = self.brain.load_skills_for_agent("scout")
prospects_found = 0
@@ -44,10 +52,10 @@ class Scout:
prospects_found += await self._prospect_via_linkedin()
# Strategy 2: Google dorking for LinkedIn profiles
- prospects_found += await self._prospect_via_google()
+ prospects_found += await self._prospect_via_google_profiles()
- # Strategy 3: Company website scraping for team pages
- prospects_found += await self._prospect_via_company_sites()
+ # Strategy 3: Google dorking for companies, then scrape team pages
+ prospects_found += await self._prospect_via_company_discovery()
await self.state.log_action(
action_type="prospect",
@@ -56,6 +64,8 @@ class Scout:
)
logger.info(f"Scout: Found {prospects_found} new prospects this cycle.")
+ # ── Strategy 1: LinkedIn ──
+
async def _prospect_via_linkedin(self) -> int:
"""Search LinkedIn for ICP-matching profiles."""
logger.info("Scout: Searching LinkedIn...")
@@ -79,46 +89,59 @@ class Scout:
)
for profile in profiles:
- # Check if we already have this prospect
if await self.state.prospect_exists(
linkedin_url=profile.get("linkedin_url", "")
):
continue
- # Try to find their email
- email = ""
- company = profile.get("company", "")
- if company:
- domain = await self._guess_domain(company)
+ company_name = profile.get("company", "")
+ domain = ""
+ company_id = ""
+ if company_name:
+ domain = await self._guess_domain(company_name)
if domain:
- email = await find_email(
- profile.get("first_name", ""),
- profile.get("last_name", ""),
- domain,
- ) or ""
+ company_id = await self._ensure_company(
+ name=company_name,
+ domain=domain,
+ industry=industry,
+ source="linkedin_search",
+ )
+
+ email = ""
+ email_verified = False
+ if domain and profile.get("first_name") and profile.get("last_name"):
+ found = await find_email(
+ profile["first_name"],
+ profile["last_name"],
+ domain,
+ )
+ if found:
+ email = found
+ email_verified = True
prospect = Prospect(
- id="",
first_name=profile.get("first_name", ""),
last_name=profile.get("last_name", ""),
email=email,
+ email_verified=email_verified,
linkedin_url=profile.get("linkedin_url", ""),
- company=company,
+ company=company_name,
+ company_id=company_id,
title=profile.get("title", ""),
+ seniority=self._infer_seniority(profile.get("title", "")),
industry=industry,
source="linkedin_search",
+ source_url=profile.get("linkedin_url", ""),
)
- # Ask brain for personalization notes
- if email or profile.get("linkedin_url"):
- notes = await self._get_personalization(prospect)
- prospect.personalization_notes = notes
+ if not prospect.is_valid():
+ continue
await self.state.add_prospect(prospect)
count += 1
logger.info(
f"Scout: Added prospect {prospect.full_name()} "
- f"at {company}"
+ f"at {company_name}"
)
return count
@@ -126,9 +149,11 @@ class Scout:
finally:
await linkedin.stop()
- async def _prospect_via_google(self) -> int:
+ # ── Strategy 2: Google → LinkedIn profiles ──
+
+ async def _prospect_via_google_profiles(self) -> int:
"""Use Google dorking to find LinkedIn profiles matching ICP."""
- logger.info("Scout: Google dorking for prospects...")
+ logger.info("Scout: Google dorking for LinkedIn profiles...")
count = 0
for title in self.config.icp.titles:
@@ -137,27 +162,31 @@ class Scout:
f'site:linkedin.com/in "{title}" '
f'"{self.config.icp.industries[0]}" "{geo}"'
)
- profiles = await self._google_search(query)
+ results = await self._google_search(query)
- for url, snippet in profiles:
+ for url, snippet in results:
if "/in/" not in url:
continue
if await self.state.prospect_exists(linkedin_url=url):
continue
- # Parse name from URL or snippet
parsed = self._parse_linkedin_url(url, snippet)
if not parsed:
continue
prospect = Prospect(
- id="",
first_name=parsed.get("first_name", ""),
last_name=parsed.get("last_name", ""),
linkedin_url=url,
title=title,
+ seniority=self._infer_seniority(title),
source="google_dork",
+ source_url=url,
)
+
+ if not prospect.is_valid():
+ continue
+
await self.state.add_prospect(prospect)
count += 1
@@ -168,76 +197,360 @@ class Scout:
return count
- async def _prospect_via_company_sites(self) -> int:
- """Scrape company team/about pages for prospects."""
- logger.info("Scout: Checking company websites...")
-
- # Ask brain to find target companies
- prompt = self.brain.load_prompt(
- "scout",
- industries=", ".join(self.config.icp.industries),
- company_size=self.config.icp.company_size,
- geography=", ".join(self.config.icp.geography),
- titles=", ".join(self.config.icp.titles),
- )
-
- if not prompt:
- prompt = f"""Find 10 companies that match this ICP:
-- Industries: {', '.join(self.config.icp.industries)}
-- Company size: {self.config.icp.company_size}
-- Geography: {', '.join(self.config.icp.geography)}
+ # ── Strategy 3: Find companies via Google, then scrape team pages ──
-Return a JSON array of objects with "name" and "domain" fields.
-Example: [{{"name": "Acme Inc", "domain": "acme.com"}}]"""
+ async def _prospect_via_company_discovery(self) -> int:
+ """Find companies via Google search, scrape their team pages for contacts.
- # Inject skills knowledge
- if self.skills:
- prompt = self.skills + "\n\n---\n\n" + prompt
+ Python does ALL the searching and scraping. Claude only scores/personalizes
+ the contacts that Python already found.
+ """
+ logger.info("Scout: Discovering companies via Google...")
- result = await self.brain.think_json(prompt, session_id="harvey-scout")
- if not result or not isinstance(result, list):
+ # Step 1: Python finds companies via Google dorking
+ companies = await self._find_companies_via_google()
+ if not companies:
+ logger.info("Scout: No new companies found via Google.")
return 0
- count = 0
- for company_info in result[:10]:
- domain = company_info.get("domain", "")
- company_name = company_info.get("name", "")
- if not domain:
- continue
-
- # Try to find team page
- team_members = await self._scrape_team_page(domain)
+ logger.info(f"Scout: Found {len(companies)} candidate companies.")
+
+ # Step 2: For each company, scrape team page and find contacts
+ all_contacts = []
+ for company in companies:
+ # Save the company
+ company_id = await self._ensure_company(
+ name=company["name"],
+ domain=company["domain"],
+ website=company.get("website", f"https://{company['domain']}"),
+ description=company.get("description", ""),
+ industry=company.get("industry", self.config.icp.industries[0] if self.config.icp.industries else ""),
+ source="google_dork",
+ source_url=company.get("source_url", ""),
+ )
+
+ # Scrape their team page for contacts
+ team_members = await self._scrape_team_page(company["domain"])
for member in team_members:
title = member.get("title", "")
- if not any(
- t.lower() in title.lower() for t in self.config.icp.titles
- ):
+ # Filter to ICP-matching titles
+ if not self._title_matches_icp(title):
continue
- email = await find_email(
- member.get("first_name", ""),
- member.get("last_name", ""),
- domain,
- ) or ""
+ first_name = member.get("first_name", "")
+ last_name = member.get("last_name", "")
+ if not first_name or not last_name:
+ continue
- if await self.state.prospect_exists(email=email):
+ # Try to find and verify their email
+ email = ""
+ email_verified = False
+ found = await find_email(first_name, last_name, company["domain"])
+ if found:
+ email = found
+ email_verified = True
+
+ if email and await self.state.prospect_exists(email=email):
continue
prospect = Prospect(
- id="",
- first_name=member.get("first_name", ""),
- last_name=member.get("last_name", ""),
+ first_name=first_name,
+ last_name=last_name,
email=email,
- company=company_name,
+ email_verified=email_verified,
+ company=company["name"],
+ company_id=company_id,
title=title,
- industry=self.config.icp.industries[0],
+ seniority=self._infer_seniority(title),
+ industry=company.get("industry", ""),
source="company_website",
+ source_url=f"https://{company['domain']}",
)
- await self.state.add_prospect(prospect)
- count += 1
+
+ if prospect.is_valid():
+ all_contacts.append(prospect)
+
+ if not all_contacts:
+ logger.info("Scout: No ICP-matching contacts found on team pages.")
+ return 0
+
+ # Step 3: Use Claude ONLY to score and personalize the contacts we found
+ scored_contacts = await self._score_contacts(all_contacts)
+
+ # Step 4: Save contacts
+ count = 0
+ for prospect in scored_contacts:
+ await self.state.add_prospect(prospect)
+ count += 1
+ logger.info(
+ f"Scout: Added {prospect.full_name()} ({prospect.title}) "
+ f"at {prospect.company} [score: {prospect.score}]"
+ )
return count
+ async def _find_companies_via_google(self) -> list[dict]:
+ """Find ICP-matching companies via Google dorking. Pure Python, no Claude."""
+ companies = []
+ seen_domains = set()
+
+ search_queries = self._build_company_search_queries()
+
+ for query in search_queries:
+ results = await self._google_search(query)
+
+ for url, snippet in results:
+ domain = self._extract_domain(url)
+ if not domain or domain in seen_domains:
+ continue
+
+ # Skip social media, directories, and other non-company sites
+ if self._is_noise_domain(domain):
+ continue
+
+ # Check if we already have this company
+ if await self.state.company_exists(domain):
+ seen_domains.add(domain)
+ continue
+
+ seen_domains.add(domain)
+
+ # Try to get company info from their homepage
+ company_info = await self._scrape_company_info(domain)
+ company_info["domain"] = domain
+ company_info["source_url"] = url
+ if not company_info.get("name"):
+ company_info["name"] = self._domain_to_name(domain)
+
+ companies.append(company_info)
+
+ if len(companies) >= 10:
+ break
+
+ if len(companies) >= 10:
+ break
+
+ return companies
+
+ def _build_company_search_queries(self) -> list[str]:
+ """Build Google search queries to find ICP-matching companies."""
+ queries = []
+ industries = self.config.icp.industries or [""]
+ geos = self.config.icp.geography or [""]
+ size = self.config.icp.company_size or ""
+
+ for industry in industries[:3]:
+ for geo in geos[:2]:
+ # Direct industry + geography search
+ parts = [f'"{industry}"']
+ if geo:
+ parts.append(f'"{geo}"')
+ if size:
+ parts.append(f'"{size}"')
+ parts.append("company")
+ queries.append(" ".join(parts))
+
+ # Search for industry directories/lists
+ queries.append(f'"{industry}" companies {geo} list')
+
+ return queries[:6] # Cap at 6 queries per cycle
+
+ def _extract_domain(self, url: str) -> str:
+ """Extract the root domain from a URL."""
+ try:
+ parsed = urlparse(url)
+ host = parsed.netloc or parsed.path.split("/")[0]
+ # Remove www prefix
+ host = re.sub(r"^www\.", "", host)
+ # Basic validation
+ if "." in host and len(host) > 3:
+ return host.lower()
+ except Exception:
+ pass
+ return ""
+
+ def _is_noise_domain(self, domain: str) -> bool:
+ """Filter out domains that aren't actual companies."""
+ noise = {
+ "linkedin.com", "facebook.com", "twitter.com", "x.com",
+ "instagram.com", "youtube.com", "tiktok.com",
+ "google.com", "bing.com", "yahoo.com",
+ "wikipedia.org", "reddit.com", "quora.com",
+ "yelp.com", "bbb.org", "glassdoor.com",
+ "crunchbase.com", "zoominfo.com", "apollo.io",
+ "indeed.com", "monster.com",
+ "github.com", "stackoverflow.com",
+ "medium.com", "substack.com",
+ "amazon.com", "apple.com", "microsoft.com",
+ }
+ return domain in noise or any(domain.endswith(f".{n}") for n in noise)
+
+ async def _scrape_company_info(self, domain: str) -> dict:
+ """Scrape a company's homepage for basic info. Pure Python."""
+ info = {"name": "", "description": "", "website": f"https://{domain}"}
+
+ try:
+ async with httpx.AsyncClient(timeout=10, follow_redirects=True) as client:
+ resp = await client.get(
+ f"https://{domain}",
+ headers={"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36"},
+ )
+ if resp.status_code != 200:
+ return info
+
+ soup = BeautifulSoup(resp.text, "html.parser")
+
+ # Get company name from <title> or <meta>
+ title_tag = soup.find("title")
+ if title_tag:
+ title_text = title_tag.get_text().strip()
+ # Clean up common title patterns: "Company - Tagline"
+ info["name"] = title_text.split("|")[0].split("—")[0].split("-")[0].strip()
+
+ # Get description from meta
+ meta_desc = soup.find("meta", attrs={"name": "description"})
+ if meta_desc and meta_desc.get("content"):
+ info["description"] = meta_desc["content"].strip()[:500]
+
+ # Try og:site_name for a cleaner company name
+ og_name = soup.find("meta", attrs={"property": "og:site_name"})
+ if og_name and og_name.get("content"):
+ info["name"] = og_name["content"].strip()
+
+ except Exception as e:
+ logger.debug(f"Failed to scrape {domain}: {e}")
+
+ return info
+
+ def _domain_to_name(self, domain: str) -> str:
+ """Convert a domain to a rough company name."""
+ name = domain.split(".")[0]
+ return name.title()
+
+ def _title_matches_icp(self, title: str) -> bool:
+ """Check if a job title matches the ICP target titles."""
+ if not title:
+ return False
+ title_lower = title.lower()
+ for target in self.config.icp.titles:
+ if target.lower() in title_lower:
+ return True
+ # Also accept common senior titles if no specific titles configured
+ if not self.config.icp.titles:
+ senior_keywords = ["ceo", "cto", "cfo", "vp", "director", "head of", "founder"]
+ return any(kw in title_lower for kw in senior_keywords)
+ return False
+
+ def _infer_seniority(self, title: str) -> str:
+ """Infer seniority level from a job title."""
+ if not title:
+ return ""
+ t = title.lower()
+ if any(kw in t for kw in ["ceo", "cto", "cfo", "cmo", "coo", "cro", "chief", "founder", "co-founder"]):
+ return "c_suite"
+ if any(kw in t for kw in ["vp", "vice president", "svp", "evp", "head of"]):
+ return "vp"
+ if "director" in t:
+ return "director"
+ if any(kw in t for kw in ["manager", "team lead"]):
+ return "manager"
+ return "individual"
+
+ async def _score_contacts(self, contacts: list[Prospect]) -> list[Prospect]:
+ """Use Claude to score and add personalization notes to found contacts.
+
+ This is the ONLY place Claude is used in the scout. It receives
+ already-found data and just scores/personalizes it. It never
+ searches for or researches people.
+ """
+ if not contacts:
+ return contacts
+
+ # Build a summary of all contacts for Claude to score in one call
+ contact_summaries = []
+ for i, c in enumerate(contacts):
+ contact_summaries.append(
+ f"{i+1}. {c.full_name()} — {c.title} at {c.company} "
+ f"({c.industry}). Email: {c.email or 'none'}. "
+ f"Seniority: {c.seniority or 'unknown'}."
+ )
+
+ prompt = f"""You are analyzing a batch of sales prospects that have already been found and verified.
+Your job is to score each one (1-100) based on how well they match the ICP, and add a short personalization note.
+
+Our product: {self.config.product.description}
+Target industries: {', '.join(self.config.icp.industries)}
+Target titles: {', '.join(self.config.icp.titles)}
+Target company size: {self.config.icp.company_size}
+
+Here are the prospects to score:
+{chr(10).join(contact_summaries)}
+
+Return a JSON array with one object per prospect, in the same order:
+[{{"index": 1, "score": 75, "personalization": "Short angle for outreach"}}, ...]
+
+Score criteria:
+- 80-100: Perfect ICP match, right title, right industry, right company size
+- 60-79: Good match, close to ICP
+- 40-59: Partial match, might be worth a shot
+- 1-39: Poor match, probably skip
+
+Respond ONLY with the JSON array."""
+
+ result = await self.brain.think_json(prompt, session_id="harvey-scout-score")
+
+ if not result or not isinstance(result, list):
+ # If Claude fails, just return contacts with default scores
+ logger.warning("Scout: Claude scoring failed, using default scores.")
+ for c in contacts:
+ c.score = 50
+ return contacts
+
+ # Apply scores and personalization
+ for item in result:
+ idx = item.get("index", 0) - 1
+ if 0 <= idx < len(contacts):
+ contacts[idx].score = item.get("score", 50)
+ contacts[idx].personalization_notes = item.get("personalization", "")
+
+ # Sort by score descending, filter out very low scores
+ contacts = [c for c in contacts if c.score >= 30]
+ contacts.sort(key=lambda c: c.score, reverse=True)
+
+ return contacts
+
+ # ── Shared utilities ──
+
+ async def _ensure_company(
+ self,
+ name: str,
+ domain: str,
+ website: str = "",
+ description: str = "",
+ industry: str = "",
+ company_size: str = "",
+ location: str = "",
+ source: str = "",
+ source_url: str = "",
+ ) -> str:
+ """Get or create a company record. Returns company_id."""
+ existing = await self.state.get_company_by_domain(domain)
+ if existing:
+ return existing.id
+
+ company = Company(
+ name=name,
+ domain=domain,
+ website=website or f"https://{domain}",
+ description=description,
+ industry=industry,
+ company_size=company_size,
+ location=location,
+ source=source,
+ source_url=source_url,
+ )
+ return await self.state.add_company(company)
+
async def _google_search(self, query: str) -> list[tuple[str, str]]:
"""Perform a Google search and return (url, snippet) pairs."""
encoded = quote_plus(query)
@@ -278,7 +591,8 @@ Example: [{{"name": "Acme Inc", "domain": "acme.com"}}]"""
async def _scrape_team_page(self, domain: str) -> list[dict]:
"""Try to find and scrape a company's team/about page."""
- team_paths = ["/team", "/about", "/about-us", "/our-team", "/people"]
+ team_paths = ["/team", "/about", "/about-us", "/our-team", "/people",
+ "/leadership", "/about/team", "/company/team"]
members = []
async with httpx.AsyncClient(timeout=10, follow_redirects=True) as client:
@@ -295,25 +609,30 @@ Example: [{{"name": "Acme Inc", "domain": "acme.com"}}]"""
soup = BeautifulSoup(resp.text, "html.parser")
# Look for common team member patterns
- # Many sites use cards with name + title
for card in soup.select(
- ".team-member, .person, .staff, [class*='team']"
+ ".team-member, .person, .staff, [class*='team'], "
+ "[class*='leadership'], [class*='member'], [class*='person']"
):
name_el = card.select_one(
"h2, h3, h4, .name, [class*='name']"
)
title_el = card.select_one(
- "p, .title, .role, [class*='title'], [class*='role']"
+ "p, .title, .role, .position, "
+ "[class*='title'], [class*='role'], [class*='position']"
)
if name_el:
name = name_el.get_text().strip()
title = title_el.get_text().strip() if title_el else ""
+ # Skip if name looks like a section header
+ if len(name) > 50 or len(name) < 3:
+ continue
parts = name.split(" ", 1)
- members.append({
- "first_name": parts[0],
- "last_name": parts[1] if len(parts) > 1 else "",
- "title": title,
- })
+ if len(parts) >= 2:
+ members.append({
+ "first_name": parts[0].strip(),
+ "last_name": parts[1].strip(),
+ "title": title,
+ })
if members:
break
@@ -325,14 +644,12 @@ Example: [{{"name": "Acme Inc", "domain": "acme.com"}}]"""
async def _guess_domain(self, company_name: str) -> str:
"""Guess a company's domain from its name."""
- # Simple heuristic: lowercase, remove common suffixes, add .com
name = company_name.lower().strip()
for suffix in [" inc", " llc", " ltd", " corp", " co", " group"]:
name = name.replace(suffix, "")
name = re.sub(r"[^a-z0-9]", "", name)
domain = f"{name}.com"
- # Verify the domain exists
try:
async with httpx.AsyncClient(timeout=5) as client:
resp = await client.head(
@@ -345,18 +662,24 @@ Example: [{{"name": "Acme Inc", "domain": "acme.com"}}]"""
return ""
- async def _get_personalization(self, prospect: Prospect) -> str:
- """Ask brain for personalization angles based on prospect info."""
- prompt = f"""Based on this prospect, suggest 2-3 short personalization angles
-for cold outreach. Keep each to one sentence.
-
-Name: {prospect.full_name()}
-Title: {prospect.title}
-Company: {prospect.company}
-Industry: {prospect.industry}
-
-Our product: {self.config.product.description}
-
-Return just the personalization notes, no labels or bullets."""
-
- return await self.brain.think(prompt, session_id="harvey-scout") or ""
+ def _parse_linkedin_url(self, url: str, snippet: str) -> dict | None:
+ """Parse a LinkedIn profile URL and snippet to extract name."""
+ # LinkedIn URLs: linkedin.com/in/first-last-abc123
+ match = re.search(r"/in/([a-zA-Z]+-[a-zA-Z]+)", url)
+ if match:
+ parts = match.group(1).split("-")
+ if len(parts) >= 2:
+ return {
+ "first_name": parts[0].title(),
+ "last_name": parts[1].title(),
+ }
+
+ # Try to parse from snippet: "First Last - Title at Company"
+ name_match = re.match(r"^([A-Z][a-z]+)\s+([A-Z][a-z]+)", snippet)
+ if name_match:
+ return {
+ "first_name": name_match.group(1),
+ "last_name": name_match.group(2),
+ }
+
+ return None
diff --git a/prompts/scout.md b/prompts/scout.md
index 5d10398..3baf1ab 100644
--- a/prompts/scout.md
+++ b/prompts/scout.md
@@ -1,4 +1,7 @@
-You are Harvey's prospecting engine. Your job is to find companies and decision-makers that match the Ideal Customer Profile (ICP).
+You are Harvey's prospect scoring engine. You receive a batch of prospects that have already been found and verified by Harvey's search tools. Your job is to:
+
+1. **Score** each prospect (1-100) based on ICP fit
+2. **Personalize** — write a short angle for cold outreach
Target ICP:
- Industries: {{industries}}
@@ -6,9 +9,16 @@ Target ICP:
- Geography: {{geography}}
- Decision-maker titles: {{titles}}
-When identifying prospects:
-1. Focus on companies that would genuinely benefit from our product
-2. Look for signals of need (hiring for related roles, recent funding, tech stack changes)
-3. Prioritize quality over quantity — 10 great prospects beat 100 mediocre ones
-4. Never add the same person twice
-5. Capture any personalization angles you find (recent posts, company news, mutual connections)
+Scoring criteria:
+- 80-100: Perfect ICP match — right title, industry, company size
+- 60-79: Good match, close to ICP
+- 40-59: Partial match, worth considering
+- 1-39: Poor match, probably skip
+
+Personalization rules:
+- Keep each note to 1-2 sentences max
+- Focus on angles relevant to our product
+- Mention anything specific about their role or company that could hook them
+- Never fabricate details you don't have
+
+You are NOT searching for prospects. You are analyzing data that has already been collected. Just score and personalize.