AI Agent for Fleet Management: Vehicle Tracking, Maintenance Scheduling, and Driver Communication
Build an AI agent that monitors fleet vehicles via GPS integration, enforces maintenance schedules based on mileage and time rules, and sends alerts to drivers and fleet managers automatically.
The Fleet Management Challenge
Fleet operators with 50 to 5,000 vehicles face a constant operational balancing act. Every vehicle needs regular oil changes, tire rotations, brake inspections, and DOT compliance checks. Drivers need route updates, maintenance reminders, and emergency support. Managers need visibility into where every vehicle is, which ones are due for service, and which drivers are approaching hours-of-service limits.
An AI agent for fleet management ties together GPS telematics, maintenance rule engines, and communication channels into a single conversational interface that fleet managers and dispatchers can query naturally.
Modeling Fleet Vehicles and Maintenance Rules
Start with data models that capture vehicle state and maintenance requirements:
from dataclasses import dataclass, field
from datetime import datetime, date
from enum import Enum
from typing import Optional
class MaintenanceType(str, Enum):
OIL_CHANGE = "oil_change"
TIRE_ROTATION = "tire_rotation"
BRAKE_INSPECTION = "brake_inspection"
DOT_INSPECTION = "dot_inspection"
TRANSMISSION_SERVICE = "transmission_service"
@dataclass
class MaintenanceRule:
maintenance_type: MaintenanceType
interval_miles: int
interval_days: int
description: str
@dataclass
class FleetVehicle:
vehicle_id: str
unit_number: str
make: str
model: str
year: int
current_mileage: int
last_oil_change_miles: int
last_oil_change_date: date
latitude: float
longitude: float
speed_mph: float
driver_name: str
driver_phone: str
status: str = "active"
MAINTENANCE_RULES = [
MaintenanceRule(MaintenanceType.OIL_CHANGE, 7500, 180, "Engine oil and filter"),
MaintenanceRule(MaintenanceType.TIRE_ROTATION, 10000, 365, "Rotate all tires"),
MaintenanceRule(MaintenanceType.BRAKE_INSPECTION, 25000, 365, "Full brake check"),
MaintenanceRule(MaintenanceType.DOT_INSPECTION, 0, 365, "Annual DOT compliance"),
]
GPS Tracking Integration Tool
The vehicle tracking tool simulates pulling real-time location data from a telematics provider like Samsara, Geotab, or Verizon Connect:
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 function_tool
FLEET_VEHICLES = [
FleetVehicle("FV-001", "Unit 14", "Freightliner", "Cascadia", 2024,
142000, 135000, date(2025, 11, 15), 37.7749, -122.4194,
58.0, "Mike Torres", "+1-555-0101"),
FleetVehicle("FV-002", "Unit 27", "Kenworth", "T680", 2023,
198000, 195500, date(2026, 1, 20), 34.0522, -118.2437,
0.0, "Sarah Kim", "+1-555-0102"),
FleetVehicle("FV-003", "Unit 33", "Volvo", "VNL 860", 2025,
67000, 62000, date(2025, 12, 10), 41.8781, -87.6298,
62.5, "James Okafor", "+1-555-0103"),
]
@function_tool
def get_vehicle_location(unit_number: Optional[str] = None) -> str:
"""Get current GPS location and status for fleet vehicles."""
vehicles = FLEET_VEHICLES
if unit_number:
vehicles = [v for v in vehicles
if v.unit_number.lower() == unit_number.lower()]
if not vehicles:
return "No matching vehicles found."
lines = []
for v in vehicles:
status = "Moving" if v.speed_mph > 0 else "Stopped"
lines.append(
f"{v.unit_number} ({v.year} {v.make} {v.model}) | "
f"Driver: {v.driver_name} | "
f"Location: ({v.latitude:.4f}, {v.longitude:.4f}) | "
f"Speed: {v.speed_mph} mph | Status: {status}"
)
return "\n".join(lines)
Maintenance Check Tool
This tool evaluates each vehicle against the maintenance rules and flags overdue or upcoming services:
@function_tool
def check_maintenance_status(unit_number: Optional[str] = None) -> str:
"""Check maintenance status for fleet vehicles based on mileage and time rules."""
vehicles = FLEET_VEHICLES
if unit_number:
vehicles = [v for v in vehicles
if v.unit_number.lower() == unit_number.lower()]
today = date.today()
alerts = []
for v in vehicles:
for rule in MAINTENANCE_RULES:
miles_since = v.current_mileage - v.last_oil_change_miles
days_since = (today - v.last_oil_change_date).days
overdue_miles = (rule.interval_miles > 0
and miles_since >= rule.interval_miles)
overdue_days = days_since >= rule.interval_days
if overdue_miles or overdue_days:
reason = []
if overdue_miles:
reason.append(f"{miles_since} miles since last service")
if overdue_days:
reason.append(f"{days_since} days since last service")
alerts.append(
f"OVERDUE: {v.unit_number} needs {rule.description} "
f"({', '.join(reason)})"
)
return "\n".join(alerts) if alerts else "All vehicles are current on maintenance."
Driver Notification Tool
@function_tool
def send_driver_message(
unit_number: str,
message: str,
priority: str = "normal",
) -> str:
"""Send a message to a fleet driver via their registered phone number."""
vehicle = next(
(v for v in FLEET_VEHICLES
if v.unit_number.lower() == unit_number.lower()), None
)
if not vehicle:
return f"Vehicle {unit_number} not found in fleet."
# In production, call Twilio / SMS API here
return (
f"Message sent to {vehicle.driver_name} ({vehicle.driver_phone}): "
f"[{priority.upper()}] {message}"
)
Assembling the Fleet Agent
from agents import Agent, Runner
fleet_agent = Agent(
name="Fleet Manager",
instructions="""You are an AI fleet management assistant. You can:
1. Track vehicle locations and speeds in real time
2. Check maintenance schedules and flag overdue services
3. Send messages to drivers with normal or urgent priority
Always prioritize safety-related maintenance alerts.""",
tools=[get_vehicle_location, check_maintenance_status, send_driver_message],
)
result = Runner.run_sync(
fleet_agent,
"Which vehicles have overdue maintenance? Notify those drivers."
)
print(result.final_output)
FAQ
How do I integrate with real GPS telematics providers?
Most providers like Samsara, Geotab, and KeepTruckin offer REST APIs. Replace the in-memory fleet list with API calls that fetch live vehicle positions. Use webhook subscriptions for real-time event streaming instead of polling, and cache location data for 30 to 60 seconds to reduce API costs.
Can the agent handle hours-of-service (HOS) compliance?
Yes. Add a tool that queries ELD (Electronic Logging Device) data for each driver. The tool checks remaining drive time, mandatory break requirements, and 70-hour weekly limits. If a driver approaches a threshold, the agent can proactively alert dispatch to plan a relief driver or rest stop.
How should I handle maintenance scheduling conflicts?
In production, integrate with a shop management system that tracks bay availability and technician schedules. The agent should check open slots before scheduling and offer the driver the nearest available time. Use optimistic locking on appointment slots to prevent double-booking.
#FleetManagement #VehicleTracking #MaintenanceAI #Logistics #Python #AgenticAI #LearnAI #AIEngineering
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.