Skip to main content

On This Page

How to Build a Fully Autonomous Local Fleet-Maintenance Analysis Agent Using SmolAgents and Qwen Model

3 min read
Share

These articles are AI-generated summaries. Please check the original sources for full details.

How to Build a Fully Autonomous Local Fleet-Maintenance Analysis Agent Using SmolAgents and Qwen Model

This tutorial details the creation of a fully autonomous fleet-analysis agent using SmolAgents and a local Qwen model; the system generates telemetry data, loads it locally, and analyzes maintenance risks. The completed system produces a visual warning for fleet managers without requiring any external API calls.

Why This Matters

Current AI agent solutions often rely on cloud-based APIs for data access and analysis, introducing latency, cost, and privacy concerns. A fully local, autonomous agent utilizing open-source models like Qwen addresses these shortcomings, enabling real-time analysis of sensitive data without external dependencies. The cost of inaccurate fleet maintenance predictions can reach thousands of dollars per vehicle due to downtime and repairs.

Key Insights

  • pip install smolagents transformers accelerate bitsandbytes ddgs matplotlib pandas -q: Installs the necessary Python libraries for the agent’s operation.
  • Local Reasoning vs. API Calls: SmolAgents facilitates complex, multi-step reasoning directly on local data, removing the need for frequent communication with external services.
  • Qwen Model Choice: Qwen2.5-Coder-1.5B-Instruct provides a powerful, yet relatively lightweight, local language model suitable for agent-based tasks.

Working Example

print("⏳ Installing libraries... (approx 30-60s)")
!pip install smolagents transformers accelerate bitsandbytes ddgs matplotlib pandas -q
import os
import pandas as pd
import matplotlib.pyplot as plt
from smolagents import CodeAgent, Tool, TransformersModel
fleet_data = {
"truck_id": ["T-101", "T-102", "T-103", "T-104", "T-105"],
"driver": ["Ali", "Sara", "Mike", "Omar", "Jen"],
"avg_speed_kmh": [65, 70, 62, 85, 60],
"fuel_efficiency_kml": [3.2, 3.1, 3.3, 1.8, 3.4],
"engine_temp_c": [85, 88, 86, 105, 84],
"last_maintenance_days": [30, 45, 120, 200, 15]
}
df = pd.DataFrame(fleet_data)
df.to_csv("fleet_logs.csv", index=False)
print("✅ 'fleet_logs.csv' created.")
print("⏳ Downloading & Loading Local Model (approx 60-90s)...")
model = TransformersModel(
model_id="Qwen/Qwen2.5-Coder-1.5B-Instruct",
device_map="auto",
max_new_tokens=2048
)
print("✅ Model loaded on GPU.")
agent = CodeAgent(
tools=[FleetDataTool()],
model=model,
add_base_tools=True
)
print("\n🤖 Agent is analyzing fleet data... (Check the 'Agent' output below)\n")
query = """
1. Load the fleet logs.
2. Find the truck with the worst fuel efficiency (lowest 'fuel_efficiency_kml').
3. For that truck, check if it is overdue for maintenance (threshold is 90 days).
4. Create a bar chart comparing the 'fuel_efficiency_kml' of ALL trucks.
5. Highlight the worst truck in RED and others in GRAY on the chart.
6. Save the chart as 'maintenance_alert.png'.
"""
response = agent.run(query)
print(f"\n📝 FINAL REPORT: {response}")

Practical Applications

  • Predictive Maintenance: Early detection of potential failures in logistics fleets can minimize downtime and reduce maintenance costs.
  • Pitfall: Relying on a single tool for data loading without error handling can lead to agent failure if the data source is unavailable or corrupted.

References:

Continue reading

Next article

Self-Healing AI Agent Platform Built with FastAPI and Docker

Related Content