This tutorial walks you thru the method of making a totally autonomous fleet analytics agent utilizing SmolAgents and a neighborhood Qwen mannequin. Generate telemetry information and cargo it via customized instruments to allow brokers to cause, analyze, and visualize upkeep dangers with out making exterior API calls. At every step of the implementation, see how the agent interprets structured logs, applies logical filters, detects anomalies, and finally generates clear visible alerts for fleet managers. Please test Full code here.
print("⏳ Putting in libraries... (approx 30-60s)")
!pip set up smolagents transformers speed up bitsandbytes ddgs matplotlib pandas -q
import os
import pandas as pd
import matplotlib.pyplot as plt
from smolagents import CodeAgent, Device, TransformersModel
Set up all required libraries and import core modules that construct the agent will depend on. We arrange SmolAgent, Transformers, and primary information processing instruments to course of the telemetry and run the native mannequin easily. At this stage, we are going to put together the setting and be sure that all the pieces hundreds accurately earlier than continuing. Please test Full code here.
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.")
Generate a dummy fleet dataset that the agent will later analyze. Create a small however lifelike set of telemetry fields, convert it to a DataFrame, and put it aside as a CSV file. Right here, we set up the core information sources that drive the agent’s inference and predictions. Please test Full code here.
class FleetDataTool(Device):
identify = "load_fleet_logs"
description = "Hundreds car telemetry logs from 'fleet_logs.csv'. Returns the information abstract."
inputs = {}
output_type = "string"
def ahead(self):
strive:
df = pd.read_csv("fleet_logs.csv")
return f"Columns: {checklist(df.columns)}nData Pattern:n{df.to_string()}"
besides Exception as e:
return f"Error loading logs: {e}"
Defines a FleetDataTool that acts as a bridge between the agent and the underlying telemetry file. The agent hundreds and inspects the CSV file in order that it may well perceive its construction. This device is the idea for all subsequent analyzes carried out by the mannequin. Please test Full code here.
print("⏳ Downloading & Loading Native Mannequin (approx 60-90s)...")
mannequin = TransformersModel(
model_id="Qwen/Qwen2.5-Coder-1.5B-Instruct",
device_map="auto",
max_new_tokens=2048
)
print("✅ Mannequin loaded on GPU.")
agent = CodeAgent(
instruments=[FleetDataTool()],
mannequin=mannequin,
add_base_tools=True
)
print("n🤖 Agent is analyzing fleet information... (Test the 'Agent' output beneath)n")
question = """
1. Load the fleet logs.
2. Discover the truck with the worst gasoline effectivity (lowest 'fuel_efficiency_kml').
3. For that truck, test whether it is overdue for upkeep (threshold is 90 days).
4. Create a bar chart evaluating the 'fuel_efficiency_kml' of ALL vans.
5. Spotlight the worst truck in RED and others in GRAY on the chart.
6. Save the chart as 'maintenance_alert.png'.
"""
response = agent.run(question)
print(f"n📝 FINAL REPORT: {response}")
Load Qwen2.5 native mannequin and initialize CodeAgent utilizing customized instruments. Subsequent, write an in depth question that outlines the inference steps you need the agent to comply with and run it end-to-end. Right here, we watch brokers suppose, analyze, calculate, and even plot with full autonomy. Please test Full code here.
if os.path.exists("maintenance_alert.png"):
print("n📊 Displaying Generated Chart:")
img = plt.imread("maintenance_alert.png")
plt.determine(figsize=(10, 5))
plt.imshow(img)
plt.axis('off')
plt.present()
else:
print("⚠️ No chart picture discovered. Test the agent logs above.")
Test whether or not the agent efficiently saved the generated upkeep chart and think about it if out there. You may affirm that the agent carried out information evaluation and plotting accurately by visualizing the output instantly in your pocket book. This ensures clear, interpretable outcomes from the whole workflow.
In conclusion, we constructed an clever end-to-end pipeline that enables native fashions to autonomously load information, assess fleet well being, determine autos at highest threat, and generate diagnostic charts for actionable insights. Witness how straightforward it’s to increase this framework to real-world datasets, combine extra complicated instruments, and add multi-step inference capabilities for security, effectivity, and predictive upkeep use circumstances. Lastly, we’re grateful that SmolAgents permits us to create sensible agent techniques that run actual code, infer actual telemetry, and supply on the spot insights.
Please test Full code here. Additionally, be at liberty to comply with us Twitter Do not forget to affix us 100,000+ ML subreddits and subscribe our newsletter. grasp on! Are you on telegram? You can now also participate by telegram.
Michal Sutter is a knowledge science professional with a grasp’s diploma in information science from the College of Padova. With a robust basis in statistical evaluation, machine studying, and information engineering, Michal excels at reworking complicated datasets into actionable insights.

