HomeSample Page

Sample Page Title


On this tutorial, we stroll by the method of making a completely autonomous fleet-analysis agent utilizing SmolAgents and a neighborhood Qwen mannequin. We generate telemetry information, load it by a customized software, and let our agent cause, 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, Instrument, 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 all the things hundreds appropriately 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 real looking set of telemetry fields, convert it right into a DataFrame, and put it aside 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(Instrument):
   title = "load_fleet_logs"
   description = "Hundreds car 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: {checklist(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 flexibility to load and examine the CSV file to grasp its construction. This software 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... (Examine the 'Agent' output beneath)n")


question = """
1. Load the fleet logs.
2. Discover the truck with the worst gas effectivity (lowest 'fuel_efficiency_kml').
3. For that truck, verify 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 software. 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. Examine the agent logs above.")

We verify whether or not the agent efficiently saved the generated upkeep chart and show it if obtainable. We visualize the output immediately within the pocket book, permitting us to verify that the agent appropriately carried out information evaluation and plotting. This offers us a clear, interpretable consequence from the whole workflow.

In conclusion, we constructed an clever end-to-end pipeline that allows a neighborhood mannequin to autonomously load information, consider fleet well being, determine the highest-risk car, and generate a diagnostic chart for actionable insights. We witness how simply we are able to 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. Eventually, we admire how SmolAgents empowers us to create sensible agentic methods that execute actual code, cause over actual telemetry, and ship insights instantly.


Take a look at the FULL CODES right here. Additionally, be at liberty 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 may 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 reworking advanced datasets into actionable insights.

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest Articles