An AI-powered B2B lead generation tool that discovers company employees on LinkedIn and automatically crafts personalized sales outreach messages using a large language model.
Lead Generator automates the top-of-funnel sales process by:
- Resolving a company's LinkedIn presence to fetch its employee roster
- Filtering employees by job title keywords (e.g., "Manager", "Director")
- Scraping each lead's public LinkedIn profile
- Passing the profile data to a GPT-powered LangChain agent that writes a targeted sales pitch
The built-in prompt is tuned for ERP software sales, but the pipeline is generic and can be adapted to any product vertical.
main.py
│
├── utils.py # LinkedIn API wrappers (RapidAPI)
│ ├── get_company_id() # Resolve company name → LinkedIn ID
│ ├── get_company_employees() # Fetch paginated employee list
│ ├── fiter_employees() # Filter by job title keyword
│ └── scrape_linkedin_profile() # Fetch individual profile data
│
├── agents/
│ └── linkedin_lookup_agent.py # LangChain agent: name → LinkedIn URL
│
└── tools/
└── search_tool.py # Custom SerpAPI wrapper for Google search
Company Name + Search Term
│
▼
get_company_id() ← RapidAPI LinkedIn API
│
▼
get_company_employees() ← RapidAPI LinkedIn API
│
▼
fiter_employees() ← keyword match on job title
│
▼
scrape_linkedin_profile() ← RapidAPI LinkedIn API
│
▼
LangChain + GPT-3.5 ← OpenAI API
│
▼
Personalized Sales Pitch
| Component | Technology |
|---|---|
| Language | Python 3.10+ |
| LLM Orchestration | LangChain |
| Language Model | OpenAI GPT-3.5-turbo |
| LinkedIn Data | RapidAPI — linkedin-api8.p.rapidapi.com |
| Profile URL Lookup | SerpAPI (Google Search) |
| Environment Config | python-dotenv |
- Python 3.10 or higher
- A RapidAPI account with access to the LinkedIn API (
linkedin-api8) - An OpenAI API key
- A SerpAPI API key (used by the LinkedIn lookup agent)
# Clone the repository
git clone <repo-url>
cd Lead_Generator
# Create and activate a virtual environment
python -m venv venv
source venv/bin/activate # macOS/Linux
# venv\Scripts\activate # Windows
# Install dependencies
pip install -r requirements.txtCreate a .env file in the project root:
RAPIDAI_API_KEY=your_rapidapi_key_here
OPENAI_API_KEY=your_openai_api_key_here
SERPAPI_API_KEY=your_serpapi_api_key_hereSecurity note: Never commit your
.envfile or hardcode API keys in source files.
from main import lead_gen
# Find all "Manager" employees at Adidas and generate sales pitches
results = lead_gen(company_name="adidas", search_term="Manager")
print(results)Or run directly:
python main.pyThe agents/linkedin_lookup_agent.py module can resolve a person's LinkedIn username from their full name alone, using a LangChain agent backed by Google Search:
from agents.linkedin_lookup_agent import look_up
username = look_up("Jane Doe")Lead_Generator/
├── main.py # Entry point and LLM chain orchestration
├── utils.py # RapidAPI LinkedIn utility functions
├── requirements.txt # Python dependencies
├── .env # API keys (not committed)
├── agents/
│ ├── __init__.py
│ └── linkedin_lookup_agent.py # LangChain agent for profile URL discovery
├── third_parties/
│ ├── __init__.py
│ └── linkedIn.py # Alternate LinkedIn API module
└── tools/
├── __init__.py
└── search_tool.py # Custom SerpAPI Google search wrapper
The project uses LangChain's model-agnostic interface, so you can swap the underlying LLM without changing any pipeline logic. Only the model instantiation line needs to change.
from langchain_openai import ChatOpenAI
llm = ChatOpenAI(model="gpt-3.5-turbo-0125", temperature=0.5)Other OpenAI models you can drop in:
| Model | Notes |
|---|---|
gpt-3.5-turbo-0125 |
Default — fast and cost-effective |
gpt-4o |
Higher quality output, better reasoning |
gpt-4-turbo |
Stronger reasoning, larger context window |
pip install langchain-anthropicfrom langchain_anthropic import ChatAnthropic
llm = ChatAnthropic(model="claude-3-5-sonnet-20241022", temperature=0.5)Set your API key in .env:
ANTHROPIC_API_KEY=your_anthropic_api_key_herepip install langchain-google-genaifrom langchain_google_genai import ChatGoogleGenerativeAI
llm = ChatGoogleGenerativeAI(model="gemini-1.5-pro", temperature=0.5)Set your API key in .env:
GOOGLE_API_KEY=your_google_api_key_hereRun models locally using Ollama:
pip install langchain-ollama
ollama pull llama3from langchain_ollama import ChatOllama
llm = ChatOllama(model="llama3", temperature=0.5)For the full list of supported providers and models, see the LangChain Chat Models documentation.
The LLM is given the following role and instructions when generating outreach:
You are a sales representative for a new ERP company. Given a person's LinkedIn profile, create:
- A short summary of the person
- A personalized sales pitch that relates the ERP product to their role and industry
The prompt template lives in main.py and can be edited to target any product, tone, or persona.
langchain
langchain-openai
google-search-results # SerpAPI Python client
openai==1.37.2
python-dotenv
pandas
- The RapidAPI LinkedIn endpoints are subject to rate limits and terms of service — ensure your usage complies with LinkedIn's data policies.
- The
fiter_employeesfilter performs a simple substring match on job titles; complex role hierarchies may require more nuanced filtering logic. - The current pipeline processes one lead at a time; for bulk campaigns, consider batching API calls and adding retry logic.
MIT