Agent: Sales Lead Scoring

View as Markdown

This guide walks through building an end-to-end Sales Lead Scoring Agent using KumoRFM MCP, integrated with OpenAI Agents via the Model Context Protocol (MCP).

It’s designed to be read, executed, and extended — all within 10 minutes.

Introduction — What We’re Building

The Sales Lead Scoring Agent automates the process of identifying and ranking new leads so sales teams can focus on those most likely to convert. It combines KumoRFM’s predictive intelligence with OpenAI’s agentic orchestration, producing a daily, data-driven prioritization that tells Sales Development Representatives (SDRs) exactly who to contact first.

Every day, the agent:

  • Loads the latest lead data from your CRM or CSV source
  • Uses KumoRFM (Kumo Relational Foundation Model) to infer conversion likelihoods — no training required
  • Categorizes leads into HIGH, MEDIUM, and LOW priority tiers
  • Summarizes key drivers behind each prediction so SDRs know why each lead ranks where it does

By using KumoRFM MCP, the agent communicates directly with a local or remote KumoRFM server through standardized MCP APIs — enabling predictive queries, graph exploration, and explainable insights without extra setup.
This integration allows OpenAI Agents to reason over multi-table business data, invoke KumoRFM tools dynamically, and turn raw relational data into actionable daily insights — seamlessly, reproducibly, and at scale.

Behind the scenes, this walkthrough uses the kumo-rfm-mcp server — a Python MCP server that exposes KumoRFM tools (e.g., predict, evaluate) for various agentic frameworks, including OpenAI, CrewAI, and LangGraph. Please see KumoRFM MCP Server for more details.

System Overview

Architecture Components

The Sales Lead Scoring Agent consists of four key components working together through the Model Context Protocol (MCP):

  • 🧠 Agent (GPT-5) — The central reasoning engine.
    It plans actions, interprets instructions, and dynamically invokes MCP tools (e.g., predict, lookup_table_rows) to analyze and rank sales leads.
  • ⚙️ Runner — The execution harness.
    It initializes the Agent, maintains the session state, and most importantly, loads lead data from an external source such as S3 or a CRM database. The Runner passes this data into the MCP environment so KumoRFM can interpret it as part of a relational feature graph.
  • 🔌 KumoRFM MCP Server — The integration bridge.
    It exposes the KumoRFM model as a standardized MCP toolset that can be called by any AI agent.
    Each tool is strongly typed, authenticated, and schema-aware — handling data loading, graph construction, and model inference.
  • 🧮 KumoRFM Model — The predictive reasoning engine.
    A pre-trained Relational Foundation Model (RFM) that performs zero-training inference over multi-table data.
    Through the MCP interface, it executes predictive queries, evaluates results, and provides explainability — all without custom model training.

End-to-End Flow

Each daily run of the Sales Lead Scoring Agent needs to follow these key steps:

  1. Initialize the Agent — Runner launches the Agent and connects it securely to data sources and the KumoRFM MCP Server.
  2. Fetch Latest Data — Load new or updated leads from CRM or S3 for scoring.
  3. Inspect Data — Preview schema and structure using inspect_table_files to understand available features.
  4. Build Graph — Use update_graph_metadata and materialize_graph to form a relational feature graph.
  5. Predict — Execute a predict query to estimate conversion likelihoods — no model training required.
  6. Enrich Results — Retrieve key details for top leads via lookup_table_rows.
  7. Rank & Summarize — Categorize leads into priority tiers and provide short explanations.
  8. Log & Automate — Record outputs and repeat the process automatically for continuous insights.

KumoRFM tools used in this agent:

  • inspect_table_files — Analyze the structure and preview rows of tabular data.
  • update_graph_metadata — Define or refresh the relationships among tables.
  • materialize_graph — Assemble the relational feature graph for inference.
  • predict — Run predictive queries to generate conversion likelihoods.
  • lookup_table_rows — Retrieve detailed records for selected entities or leads.

Together, these tools allow the Agent to explore tables, build a graph, run predictions, and deliver enriched, prioritized results — all without custom training.

Data & Problem Definition

In this example, we work with the Lead Scoring Dataset, publicly available at:
s3://kumo-sdk-public/rfm-datasets/lead_scoring/lead_scoring.csv

This dataset contains about 8,000 historical leads — both converted and unconverted — and serves as the foundation for our sales prioritization model.
It is composed of a single table with the following key columns:

ColumnDescription
lead_idUnique identifier for each lead
contact_dateDate of first contact
convertedBinary target (1 = converted, 0 = not converted)
source, region, industry, …Lead attributes describing each lead

Our agent uses this historical data to help the sales team reach out to prospects in an optimal way — learning from the past behavior of successful conversions.

What We’re Predicting

Our goal is to predict which new leads (added yesterday) are most likely to convert (converted = 1).
This enables the sales or marketing team to focus efforts on the highest-potential leads, automatically and intelligently.

As part of our daily team sync, the sales agent will:

  1. Take the leads submitted yesterday (one day before MEETING_DAY).
  2. Generate a ranked list of leads based on their likelihood to convert.
  3. Present this prioritized list to the team — helping guide outreach efforts efficiently.

Setup

Prerequisites

  • Python environment: Create a new environment using uv or pip with Python ≥ 3.10
  • KumoRFM API key: Use the API key provided for your KumoRFM environment and set it as
    export KUMO_API_KEY=<your_api_key>
  • OpenAI API key: Obtain from https://platform.openai.com/api-keys and set it as
    export OPENAI_API_KEY=<your_openai_api_key>
  • Internet access: Required for MCP to communicate with KumoRFM services

Once these are ready, everything else in this walkthrough can be copy-and-paste runnable.

Install and Import Required Libraries

Before running the example agent notebook, install the following dependencies:

$pip install kumo-rfm-mcp openai-agents==0.2.9 fsspec s3fs pandas
  • kumo-rfm-mcp — Provides the KumoRFM MCP server and tools to interact with relational graph data.
  • openai-agents — Framework for building and running agent workflows.
  • fsspec and s3fs — Enable file system access (e.g., loading data from S3).
  • pandas — Required for tabular data handling.

Once all the required libraries are installed, we start implementing with importing the following libraries:

1# Import required libraries
2import asyncio
3import os
4from datetime import datetime, timedelta
5from typing import List
6
7from agents import Agent, Runner, gen_trace_id, trace
8from agents.mcp import MCPServer, MCPServerStdio
9import pandas as pd
10
11import kumoai.rfm as rfm

Data Loading: Getting Yesterday’s Leads

Now, let’s define a helper function to load the lead data from S3 and extract the lead IDs from the day before the meeting date.
This ensures the agent only scores the most recent leads for prioritization.

1import pandas as pd
2from datetime import datetime, timedelta
3from typing import List
4
5def get_leads_from_previous_day(meeting_date: str, data_source: str) -> List[int]:
6 """
7 Get lead IDs from the day before the meeting date.
8
9 Args:
10 meeting_date: Format "YYYY-MM-DD" (e.g., "2025-06-02")
11 data_source: Data source URL (e.g., S3 path)
12 Returns:
13 List of lead IDs from the previous day
14 """
15 # Get leads data from data source
16 leads_data = pd.read_csv(data_source)
17
18 # Parse meeting date
19 meeting_dt = datetime.strptime(meeting_date, "%Y-%m-%d")
20 previous_day = meeting_dt - timedelta(days=1)
21
22 print(f"📅 Meeting date: {meeting_date}")
23 print(f"🔍 Looking for leads from previous day: {previous_day.strftime('%Y-%m-%d')}")
24
25 # Parse contact date
26 leads_data['contact_date'] = pd.to_datetime(leads_data['contact_date'])
27
28 # Filter by previous day
29 filtered_leads = leads_data[
30 leads_data['contact_date'].dt.date == previous_day.date()
31 ]
32
33 # Extract lead IDs
34 previous_day_leads = filtered_leads['lead_id'].tolist()
35
36 print(f"📊 Found {len(previous_day_leads)} leads from previous day: {previous_day_leads}")
37 return previous_day_leads

In short, the above code works:

  1. Loads the dataset directly from S3 using fsspec and pandas.
  2. Parses the contact_date column into a proper datetime format.
  3. Filters the dataset to include only leads from one day before the given MEETING_DAY.
  4. Returns a clean list of lead IDs ready to be passed to the agent for prediction.

This function keeps the pipeline dynamic — just update MEETING_DAY, and it will automatically fetch the latest leads for scoring.

Let’s test the get_leads_from_previous_day() function with a real example from our S3 dataset.

1# Test the function
2DATA_SOURCE = "s3://kumo-sdk-public/rfm-datasets/lead_scoring/lead_scoring.csv"
3MEETING_DATE = "2025-05-31" # Demo date - in practice this would be today's date
4
5test_leads = get_leads_from_previous_day(MEETING_DATE, DATA_SOURCE)

Output

📅 Meeting date: 2025-05-31
🔍 Looking for leads from previous day: 2025-05-30
📊 Found 30 leads from previous day: [42, 322, 495, 834, 954, 1370, 1376, 1524, 2141, 2202, 2236, 2255, 2838, 2882, 2991, 3167, 3912, 3928, 4336, 4891, 5301, 5693, 5709, 5779, 5866, 6022, 6052, 6377, 6869, 7213]

Build the Sales Agent

Now that we’ve prepared our dataset and helper functions, we’re ready to create the agent function.
The OpenAI Agents SDK makes this process simple and modular — allowing us to combine reasoning, data access, and predictive intelligence in just a few lines of code.

Here’s what we’ll do next:

  1. Define lead_scoring_agent — an Agent object initialized with the system prompt and connected to KumoRFM MCP tools.
  2. Fetch the target leads using our get_leads_from_previous_day() helper function.
  3. Compose the request (prompt) for the agent to run predictions and prioritize the leads.
  4. Execute the agent using:
1 result = await Runner.run(starting_agent=lead_scoring_agent, input=request)

Lead Scoring Agent

The Lead Scoring Agent is a specialized sub-agent responsible for predicting which leads are most likely to convert.
It works as part of the daily automation pipeline — taking yesterday’s leads, running predictions with KumoRFM, and delivering a prioritized outreach list for the sales development team.

The following Agent Prompt defines the role, goals, and workflow of our AI sales assistant.
It tells the model how to think and act — from connecting to KumoRFM, running predictions, and generating ranked outreach lists for SDRs.

In this scenario, the agent will:

  • Use the Lead Scoring dataset hosted on S3
  • Run KumoRFM predictive queries to estimate conversion probabilities
  • Rank leads into priority tiers (High, Medium, Low)
  • Return a clean, actionable list for the daily sales meeting

Below is the full prompt string assigned to the variable LEAD_SCORING_AGENT_PROMPT.

1LEAD_SCORING_AGENT_PROMPT = """
2You are a lead scoring agent for the daily sales team meeting. Your task is to:
3
41. Set up the KumoRFM model with the S3 lead scoring data
52. Make predictions for the provided lead IDs from yesterday
63. Create a prioritized outreach list for SDRs
74. Provide actionable insights
8
9Workflow:
10- inspect_table_files: s3://kumo-sdk-public/rfm-datasets/lead_scoring/lead_scoring.csv
11- update_graph_metadata: Register table as "leads", set primary key to lead_id
12- materialize_graph: Assemble graph for predictions
13- predict: Use query "PREDICT leads.converted=1 FOR leads.lead_id IN (<lead_ids>)"
14- lookup_table_rows: Get lead details for the high-priority leads
15
16Output format:
17🚀 HIGH PRIORITY (>15% conversion probability)
18🔥 MEDIUM PRIORITY (10-15% conversion probability)
19⏳ LOW PRIORITY (<10% conversion probability)
20
21For each lead, show: ID, probability, business segment, origin, lead type
22Focus on actionable SDR guidance.
23""".strip()

Sales Agent Function

The following function ties everything together — it initializes the Lead Scoring Agent, retrieves the latest leads, builds the prompt, and runs the prediction workflow end to end.
It serves as the main entry point that the Sales Agent uses during each daily sync to generate actionable insights for the team.

1async def run_daily_sales_agent(mcp_server: MCPServer):
2 """
3 Run the daily lead scoring agent demo
4 """
5 # Daily Lead Scoring Agent
6 lead_scoring_agent = Agent(
7 name="Daily Lead Scoring Agent",
8 model="gpt-5",
9 instructions=LEAD_SCORING_AGENT_PROMPT,
10 mcp_servers=[mcp_server],
11 )
12
13 # Get leads from previous day
14 previous_day_leads = get_leads_from_previous_day(MEETING_DATE, DATA_SOURCE)
15
16 if not previous_day_leads:
17 print("❌ No leads found from previous day")
18 return
19
20 # Create the daily sales meeting request
21 lead_ids_str = ",".join(map(str, previous_day_leads))
22 request = f"""
23 📋 DAILY SALES TEAM MEETING - {MEETING_DATE}
24
25 We need to prioritize outreach for {len(previous_day_leads)} leads that came in yesterday.
26
27 Lead IDs to score: {lead_ids_str}
28
29 Please:
30 1. Set up the lead scoring model
31 2. Score these leads for conversion probability
32 3. Create a prioritized outreach list for our SDRs
33 4. Provide insights on which leads to focus on first
34
35 Data source: {DATA_SOURCE}
36 """
37
38 print("🎯 Daily Lead Scoring Meeting")
39 print("=" * 50)
40 print(f"Request: {request.strip()}")
41 print("-" * 50)
42
43 # Run the agent
44 result = await Runner.run(starting_agent=lead_scoring_agent, input=request, max_turns=20)
45 print("\n📊 SDR Prioritization Results:")
46 print(result.final_output)
47
48 return result

Integrating KumoRFM via MCP

The only remaining thing to do is initialize the KumoRFM MCP and provide it to the agent! We can do so with:

1server = MCPServerStdio(
2 name="kumo_rfm",
3 args=["-m", "kumo_rfm_mcp.server"],
4 env={"KUMO_API_KEY": os.environ["KUMO_API_KEY"]},
5)

OpenAI agents SDK also provides a tracing tool which is very useful for inspecting and debugging agentic runs, so we can complete the following main function to run:

1async def main():
2 """
3 Main demo function - connects to MCP server and runs the agent
4 """
5 print("🔌 Connecting to KumoRFM MCP Server...")
6
7 async with MCPServerStdio(
8 name="KumoRFM Server",
9 params={
10 "command": "python",
11 "args": ["-m", "kumo_rfm_mcp.server"],
12 "env": {
13 "KUMO_API_KEY": os.getenv("KUMO_API_KEY"),
14 }
15 },
16 ) as server:
17 trace_id = gen_trace_id()
18 with trace(workflow_name="Daily Lead Scoring Meeting", trace_id=trace_id):
19 print(f"📊 View trace: https://platform.openai.com/traces/trace?trace_id={trace_id}\n")
20 print("✅ MCP Server connected successfully!")
21 print("🤖 Running Daily Lead Scoring Agent...\n")
22
23 # Run the demo
24 result = await run_daily_sales_agent(server)
25
26 print("\n" + "="*60)
27 print("🎉 DONE TODAY!")
28 print("="*60)
29 return result

If you run this main(), then the following outcomes can be shown:

book slot.
- Organic_search: Educational angle—send 1-pager/case study in their segment, then propose a focused demo.
- Referral: Ask who referred; leverage social proof to secure meeting (“we work with X; similar outcomes for you”).
- Tailor by lead_type
- Industry: Treat as multi-stakeholder—ask about decision process and procurement; share security and pricing overview; propose 30‑min discovery.
- Offline: Phone-first; verify best number; offer to walk through options live.
- Online_beginner: Provide simple onboarding path and “quick win” use case; offer starter plan.
- Online_big/top: Emphasize scale, SLAs, and ROI; propose a customized demo.
- Segment-specific talk tracks you can reuse today
- Household_utilities (834, 2991, 1524, 6377): Reliability/cost savings; reference bulk usage and uptime.
- Computers (7213, 6052, 1376): Performance and integration; highlight API/compatibility.
- Car_accessories (2838, 42, 2141, 4891, 5693, 954): Quick wins; offer catalog/fitment guidance and fast setup.
- Health_beauty (5779, 2202, 1370): Compliance and brand; share case study results with conversion lifts.
Suggested cadence
- Today: Call all High and top 5 Mediums (6869, 7213, 5709, 3167, 6052). Email remaining Mediums with a clear CTA and book follow-up calls.
- Next 48 hours: Follow-up call attempts for Mediums; add remaining Lows to a 3‑step nurture (value email → case study → light CTA). Only call Lows with direct_traffic or display if time permits.
Notes
- 6869 rounds to 15.0% but is just under the high threshold; treat as near‑high priority.
- Materialized with anchor time 2025-05-31 to avoid future leakage. Model context used 5,000 examples with 10.7% positive base rate.
============================================================
🎉 DONE TODAY!
============================================================

For the full end-to-end code, please see the notebook example

We’d love to hear from you! ❤️

Found a bug or have a feature request? Submit issues directly on GitHub. Your feedback helps us improve RFM for everyone.

Built something cool with RFM? We’d love to see it! Share your project on LinkedIn and tag @kumo. We regularly spotlight on our official channels—yours could be next!