Monday, December 22, 2025

The right way to Construct a Absolutely Autonomous Native Fleet-Upkeep Evaluation Agent Utilizing SmolAgents and Qwen Mannequin


On this tutorial, we stroll by way of the method of making a completely autonomous fleet-analysis agent utilizing SmolAgents and an area Qwen mannequin. We generate telemetry information, load it by way of a customized instrument, and let our agent purpose, analyze, and visualize upkeep dangers with none exterior API calls. At every step of implementation, we see how the agent interprets structured logs, applies logical filters, detects anomalies, and eventually produces a transparent visible warning for fleet managers. Take a look at the FULL CODES right 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

We set up all required libraries and import the core modules we depend on for constructing our agent. We arrange SmolAgents, Transformers, and primary data-handling instruments to course of telemetry and run the native mannequin easily. At this stage, we put together the environment and guarantee every little thing hundreds accurately earlier than shifting forward. Take a look at the FULL CODES right 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.")

We generate the dummy fleet dataset that our agent will later analyze. We create a small however lifelike set of telemetry fields, convert it right into a DataFrame, and reserve it as a CSV file. Right here, we set up the core information supply that drives the agent’s reasoning and predictions. Take a look at the FULL CODES right here.

class FleetDataTool(Device):
   identify = "load_fleet_logs"
   description = "Masses automobile telemetry logs from 'fleet_logs.csv'. Returns the information abstract."
   inputs = {}
   output_type = "string"


   def ahead(self):
       attempt:
           df = pd.read_csv("fleet_logs.csv")
           return f"Columns: {record(df.columns)}nData Pattern:n{df.to_string()}"
       besides Exception as e:
           return f"Error loading logs: {e}"

We outline the FleetDataTool, which acts because the bridge between the agent and the underlying telemetry file. We give the agent the power to load and examine the CSV file to know its construction. This instrument turns into the inspiration for each subsequent evaluation the mannequin performs. Take a look at the FULL CODES right 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... (Verify 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, examine 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}")

We load the Qwen2.5 native mannequin and initialize our CodeAgent with the customized instrument. We then craft an in depth question outlining the reasoning steps we would like the agent to observe and execute it end-to-end. That is the place we watch the agent assume, analyze, compute, and even plot, absolutely autonomously. Take a look at the FULL CODES right 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. Verify the agent logs above.")

We examine whether or not the agent efficiently saved the generated upkeep chart and show it if accessible. We visualize the output instantly within the pocket book, permitting us to substantiate that the agent accurately carried out information evaluation and plotting. This provides us a clear, interpretable outcome from all the workflow.

In conclusion, we constructed an clever end-to-end pipeline that permits an area mannequin to autonomously load information, consider fleet well being, establish the highest-risk automobile, and generate a diagnostic chart for actionable insights. We witness how simply we will prolong this framework to real-world datasets, combine extra advanced instruments, or add multi-step reasoning capabilities for security, effectivity, or predictive upkeep use circumstances. Finally, we admire how SmolAgents empowers us to create sensible agentic techniques that execute actual code, purpose over actual telemetry, and ship insights instantly.


Take a look at the FULL CODES right here. Additionally, be happy to observe us on Twitter and don’t neglect to hitch our 100k+ ML SubReddit and Subscribe to our Publication. Wait! are you on telegram? now you’ll be able to be a part of us on telegram as nicely.


Michal Sutter is an information science skilled with a Grasp of Science in Knowledge Science from the College of Padova. With a stable basis in statistical evaluation, machine studying, and information engineering, Michal excels at remodeling advanced datasets into actionable insights.

Related Articles

Latest Articles