Skip to content
Learn Agentic AI14 min read0 views

Building a Car Dealership AI Agent: Inventory Search, Test Drive Scheduling, and Finance Quotes

Learn how to build an AI agent for car dealerships that searches vehicle inventory, schedules test drives, and generates finance quotes using tool-calling patterns and structured vehicle databases.

Why Car Dealerships Need AI Agents

Car dealerships handle thousands of customer inquiries every week. Shoppers want to know if a specific model is in stock, whether they can test drive it Saturday afternoon, and what their monthly payment would be on a 60-month loan. Traditionally these questions get routed to salespeople who manually search DMS (Dealer Management System) databases, check calendars, and run finance calculators.

An AI agent can handle the entire pre-sales workflow: searching inventory by make, model, year, color, and price range; booking test drive appointments against availability; and generating personalized finance estimates based on credit tier and down payment. The agent connects to real dealership data through tools and returns accurate, structured answers in seconds.

Designing the Vehicle Database Schema

A dealership inventory system needs to capture vehicle details, pricing, and availability status. Here is a practical schema:

from dataclasses import dataclass
from enum import Enum
from typing import Optional

class VehicleStatus(str, Enum):
    AVAILABLE = "available"
    ON_HOLD = "on_hold"
    SOLD = "sold"
    IN_TRANSIT = "in_transit"

@dataclass
class Vehicle:
    stock_number: str
    vin: str
    year: int
    make: str
    model: str
    trim: str
    exterior_color: str
    interior_color: str
    mileage: int
    msrp: float
    selling_price: float
    status: VehicleStatus
    features: list[str]
    image_url: Optional[str] = None

In production, this data lives in the DMS. For our agent, we expose it through search tools that query the database with filters.

Building the Inventory Search Tool

The search tool accepts flexible criteria and returns matching vehicles ranked by relevance:

See AI Voice Agents Handle Real Calls

Book a free demo or calculate how much you can save with AI voice automation.

from agents import Agent, Runner, function_tool
from typing import Optional

VEHICLE_INVENTORY = [
    Vehicle("STK-1001", "1HGCG5655WA123456", 2026, "Honda", "Accord",
            "Sport", "Platinum White", "Black", 12, 33500.00, 32200.00,
            VehicleStatus.AVAILABLE, ["Sunroof", "Heated Seats", "CarPlay"]),
    Vehicle("STK-1002", "5YJSA1E26MF123789", 2026, "Tesla", "Model 3",
            "Long Range", "Midnight Silver", "White", 0, 42990.00, 42990.00,
            VehicleStatus.AVAILABLE, ["Autopilot", "Premium Audio"]),
    Vehicle("STK-1003", "2T1BURHE0KC987654", 2025, "Toyota", "Camry",
            "XSE", "Celestial Silver", "Red", 8500, 31500.00, 29800.00,
            VehicleStatus.AVAILABLE, ["TRD Package", "Panoramic Roof"]),
]

@function_tool
def search_inventory(
    make: Optional[str] = None,
    model: Optional[str] = None,
    min_year: Optional[int] = None,
    max_price: Optional[float] = None,
    color: Optional[str] = None,
) -> str:
    """Search dealership vehicle inventory by make, model, year, price, or color."""
    results = [v for v in VEHICLE_INVENTORY if v.status == VehicleStatus.AVAILABLE]

    if make:
        results = [v for v in results if v.make.lower() == make.lower()]
    if model:
        results = [v for v in results if v.model.lower() == model.lower()]
    if min_year:
        results = [v for v in results if v.year >= min_year]
    if max_price:
        results = [v for v in results if v.selling_price <= max_price]
    if color:
        results = [v for v in results
                   if color.lower() in v.exterior_color.lower()]

    if not results:
        return "No vehicles found matching your criteria."

    lines = []
    for v in results:
        lines.append(
            f"{v.year} {v.make} {v.model} {v.trim} | {v.exterior_color} | "
            f"{v.mileage} mi | ${v.selling_price:,.0f} | Stock: {v.stock_number}"
        )
    return "\n".join(lines)

Test Drive Scheduling Tool

The scheduling tool checks availability windows and books appointments:

from datetime import datetime, timedelta

BOOKED_SLOTS: dict[str, list[str]] = {}

@function_tool
def schedule_test_drive(
    stock_number: str,
    customer_name: str,
    preferred_date: str,
    preferred_time: str,
) -> str:
    """Schedule a test drive for a specific vehicle."""
    try:
        dt = datetime.strptime(
            f"{preferred_date} {preferred_time}", "%Y-%m-%d %H:%M"
        )
    except ValueError:
        return "Invalid date/time format. Use YYYY-MM-DD and HH:MM."

    if dt < datetime.now():
        return "Cannot book a test drive in the past."

    if dt.weekday() == 6:
        return "Dealership is closed on Sundays."

    slot_key = dt.strftime("%Y-%m-%d %H:%M")
    day_key = dt.strftime("%Y-%m-%d")

    if day_key in BOOKED_SLOTS and slot_key in BOOKED_SLOTS[day_key]:
        return f"The {slot_key} slot is already booked. Try 30 minutes later."

    BOOKED_SLOTS.setdefault(day_key, []).append(slot_key)
    return (
        f"Test drive confirmed for {customer_name}: "
        f"{stock_number} on {slot_key}. Please bring a valid driver's license."
    )

Finance Quote Tool

The finance calculator computes monthly payments using standard amortization:

@function_tool
def calculate_finance_quote(
    vehicle_price: float,
    down_payment: float,
    term_months: int = 60,
    annual_rate: float = 6.5,
) -> str:
    """Calculate monthly payment for a vehicle purchase."""
    loan_amount = vehicle_price - down_payment
    if loan_amount <= 0:
        return "Down payment covers the full vehicle price. No financing needed."

    monthly_rate = (annual_rate / 100) / 12
    payment = loan_amount * (
        monthly_rate * (1 + monthly_rate) ** term_months
    ) / ((1 + monthly_rate) ** term_months - 1)

    return (
        f"Vehicle Price: ${vehicle_price:,.0f}\n"
        f"Down Payment: ${down_payment:,.0f}\n"
        f"Loan Amount: ${loan_amount:,.0f}\n"
        f"Term: {term_months} months at {annual_rate}% APR\n"
        f"Monthly Payment: ${payment:,.2f}"
    )

Assembling the Dealership Agent

dealership_agent = Agent(
    name="Dealership Assistant",
    instructions="""You are a helpful car dealership assistant. Help customers:
    1. Search for vehicles by make, model, year, price, or color
    2. Schedule test drives for available vehicles
    3. Calculate finance quotes with different down payments and terms
    Always be friendly and transparent about pricing.""",
    tools=[search_inventory, schedule_test_drive, calculate_finance_quote],
)

result = Runner.run_sync(
    dealership_agent,
    "I'm looking for a white sedan under $35,000. Can I test drive one Saturday at 2pm?"
)
print(result.final_output)

The agent will search inventory, find the Honda Accord, and offer to book the test drive in a single conversational turn.

FAQ

How do I connect this to a real DMS like DealerSocket or CDK?

Replace the in-memory inventory list with API calls to your DMS provider. Most modern DMS platforms offer REST APIs. Wrap each API call in a tool function that handles authentication, pagination, and error responses. Cache inventory data with a short TTL to reduce API calls.

Can the agent handle trade-in valuations?

Yes. Add a tool that accepts the customer's trade-in VIN and mileage, then calls a valuation API like Kelley Blue Book or Black Book to return an estimated value. Subtract the trade-in value from the vehicle price before calculating the finance quote.

How do I prevent double-booking test drives?

In production, use a database-backed appointment system with row-level locking or optimistic concurrency control. Check availability inside a transaction and insert the booking atomically. The in-memory approach shown here is for demonstration only.


#AutomotiveAI #CarDealership #InventoryManagement #AIAgents #Python #AgenticAI #LearnAI #AIEngineering

Share this article
C

CallSphere Team

Expert insights on AI voice agents and customer communication automation.

Try CallSphere AI Voice Agents

See how AI voice agents work for your industry. Live demo available -- no signup required.