Developing AI Agents for Sales and Lead Generation
An AI sales agent automates stages of the funnel: lead qualification, personalized communication, objection handling, and meeting scheduling. Unlike scripted chatbots, LLM agents adapt communication to each lead's context, handle non-standard questions, and support multi-turn dialogue.
Sales Agent Functionality
Inbound Leads: qualification using BANT/MEDDIC, follow-up questions, CRM entry with scoring.
Outbound Outreach: personalized email sequences based on company data.
Objection Handling: working with typical objections ("too expensive", "wrong timing", "already have a solution").
Lead Scoring: scoring leads against specified criteria, routing hot leads to managers.
Follow-up: automatic scheduled follow-up contacts.
Qualification Agent
from openai import OpenAI
from pydantic import BaseModel
from typing import Optional
import json
client = OpenAI()
class LeadQualification(BaseModel):
lead_score: int # 0-100
budget_fit: bool
authority_confirmed: bool
need_identified: bool
timeline_clear: bool
next_action: str # "schedule_demo", "nurture", "disqualify"
disqualify_reason: Optional[str]
key_pain_points: list[str]
notes: str
QUALIFICATION_SYSTEM_PROMPT = """You are a B2B SaaS sales manager.
Your task is to qualify inbound leads using the BANT methodology:
- Budget: is there budget for the solution?
- Authority: are you speaking with a decision maker or influencer?
- Need: is there a real business need?
- Timeline: when are they planning implementation?
Lead natural dialogue. Don't ask all questions in sequence — weave them into conversation.
Track answers and update qualification as you go.
For positive qualification (score>70) — offer a demo call.
For score<30 — politely close, add to nurture sequence."""
def sales_agent_response(session_id: str, user_message: str, conversation_history: list) -> dict:
conversation_history.append({"role": "user", "content": user_message})
# Generate agent response
response = client.chat.completions.create(
model="gpt-4o",
messages=[
{"role": "system", "content": QUALIFICATION_SYSTEM_PROMPT},
*conversation_history,
],
tools=[
{
"type": "function",
"function": {
"name": "update_lead_qualification",
"description": "Update lead qualification based on new information",
"parameters": LeadQualification.model_json_schema(),
}
},
{
"type": "function",
"function": {
"name": "schedule_demo",
"description": "Offer a demo time slot",
"parameters": {
"type": "object",
"properties": {
"lead_name": {"type": "string"},
"lead_email": {"type": "string"},
},
"required": ["lead_name", "lead_email"],
}
}
}
],
)
# ... handle response
return {"response": response.choices[0].message.content}
Personalized Outreach
def generate_personalized_outreach(lead_data: dict, sequence_step: int) -> str:
"""Generates personalized email based on company data"""
# Enrich company data via API (Dadata, LinkedIn)
company_info = company_enrichment_api.get(lead_data["company_domain"])
sequence_contexts = {
1: "First contact — introduction and value proposition",
2: "Follow-up in 3 days — specific pain point from company data",
3: "Follow-up in 1 week — social proof (case study from industry)",
4: "Final email — direct meeting proposal",
}
email_content = client.chat.completions.create(
model="gpt-4o",
messages=[{
"role": "system",
"content": f"""Write a personalized sales email (step {sequence_step}).
Context: {sequence_contexts[sequence_step]}
Tone: professional but informal. No clichés.
Length: 100-150 words."""
}, {
"role": "user",
"content": f"""Lead data:
Name: {lead_data['first_name']}
Position: {lead_data['title']}
Company: {lead_data['company']}
Industry: {company_info.get('industry')}
Company size: {company_info.get('employee_count')} employees
Recent news: {company_info.get('recent_news', 'no data')}"""
}],
temperature=0.7,
)
return email_content.choices[0].message.content
Practical Case: B2B SaaS Lead Generation
Context: company selling ERP system for mid-market business. 200+ inbound leads per month, 4-person SDR team can't keep up.
Agent handles: initial response to inbound request, qualification dialogue (3–7 messages), scoring, passing hot leads to SDR with full context.
Results over first 3 months:
- Time-to-first-response: 6.5h → 3min
- Qualified leads passed to SDR: +34% (agent doesn't miss any)
- Demo-scheduled conversion: 18% (agent) vs 22% (SDR) — slightly lower
- SDR focus: shifted from L1 qualification to working with already-warm leads
- Pipeline revenue: +28% per quarter
Limitation: agent doesn't conduct final negotiations and doesn't work with C-level corporate clients — only qualification and handoff.
Objection Handling
OBJECTION_HANDLERS = {
"price": "I understand the cost question. Let's look at ROI — our clients typically recover their investment in {payback_period} months thanks to {key_benefit}. Want me to show you the calculation for your scale?",
"timing": "I understand, now isn't the best time. When would be good to circle back? We can set a reminder for {suggested_date}.",
"competitor": "I hear you're looking at {competitor}. We work with several companies who switched from them — I can share their experience. What's most important to you in your choice?",
"no_need": "Interesting — most of our clients thought the same until they discovered {pain_point}. Tell me, how do you currently handle {relevant_challenge}?",
}
Timeline
- Qualification agent: 2–3 weeks
- CRM integration (AmoCRM/Bitrix24): 1–2 weeks
- Email sequences + outreach: 2 weeks
- A/B testing and tuning: 2 weeks
- Total: 7–10 weeks







