Hey everyone, Emma here from agent101.net!
It’s mid-May 2026, and if you’re anything like me, your feed is probably swamped with new AI agent tools every other day. Remember last year, when it felt like we were just getting our heads around ChatGPT plugins? Fast forward a year, and now we’re talking about autonomous agents that can chain tasks, use tools, and even learn from their mistakes. It’s a lot to keep up with, even for someone like me who practically eats, sleeps, and breathes this stuff.
The problem I keep seeing, especially for folks just dipping their toes into AI agents, is that most tutorials assume you’ve already got a computer science degree and a deep understanding of large language models. Or, they’re so high-level they don’t give you anything practical to actually *do*. I get it. I remember the frustration. My first few attempts at running an agent locally felt like trying to assemble IKEA furniture with only the cover photo as instructions.
So, today, I want to cut through the noise and show you exactly how to get started with a super practical, genuinely useful AI agent: one that can help you manage your digital clutter. Specifically, we’re going to build a simple agent that monitors a folder for new files, identifies what they are (e.g., an image, a document, a code file), and then moves them to a pre-defined, organized subfolder. Think of it as your personal digital assistant, tidying up your downloads folder so you don’t have to.
Why this specific project? Because it hits that sweet spot of being straightforward enough for beginners but immediately demonstrates the power of an agent: autonomy, task execution, and interaction with your local system. Plus, who doesn’t need a cleaner downloads folder? Mine is currently a war zone of screenshots, half-finished code, and presentation decks I downloaded “just in case.”
What Exactly Are We Building? A Digital Tidy-Upper Agent
Our goal is to create an agent that performs the following steps:
- Watches a designated “inbox” folder (e.g., your Downloads).
- When a new file appears, it “inspects” it to determine its type.
- Based on the file type, it moves the file to an appropriate subfolder (e.g., “Images,” “Documents,” “Code,” “Other”).
- It does this continuously, so you set it up once and forget about it.
This isn’t just about moving files; it’s about understanding the core components of an AI agent: sensing, reasoning (even if simple), and acting. We’ll be using Python, because honestly, it’s the friendliest language for getting started with AI, and there are tons of libraries that make complex tasks feel simple.
Getting Started: Your Agent’s Toolkit
Before we write a single line of code, let’s make sure you have everything you need. Think of this as preparing your agent’s workbench.
Prerequisites: The Basics You’ll Need
- Python 3: If you don’t have it, head over to python.org and grab the latest version. Make sure to check the box that says “Add Python to PATH” during installation – it saves a lot of headaches later.
- A Code Editor: VS Code (code.visualstudio.com) is my go-to. It’s free, powerful, and has excellent Python support.
- A Terminal/Command Prompt: You’ll be interacting with your computer’s command line to run our Python script.
Libraries We’ll Use: Python’s Superpowers
We’re going to need a few Python libraries. These are like specialized tools that extend Python’s capabilities.
os: This comes built-in with Python and helps us interact with the operating system, like listing files or moving them.shutil: Another built-in library, great for file operations like moving and copying.time: Also built-in, useful for adding pauses to our agent so it doesn’t hog all your CPU.watchdog: This is the star of the show for sensing. It allows our agent to “watch” a directory for changes without us constantly polling it. This is a game-changer for efficiency and responsiveness.python-magic(orfiletype): This library helps us identify the actual file type, not just relying on the extension (which can be unreliable). I’ve had good luck withpython-magicon Linux/macOS, butfiletypeis often easier to install on Windows. We’ll usefiletypefor simplicity here.
Open your terminal or command prompt and install the external libraries:
pip install watchdog filetype
If you’re on Windows and hit issues with filetype, sometimes it’s because of missing C++ build tools. Try pip install python-magic-bin instead (if you want to go the python-magic route) or ensure your Visual Studio Build Tools are up to date. For this tutorial, filetype is generally more robust across platforms.
Setting Up Your Agent’s Workspace: Folders!
Let’s create the folder structure our agent will use. I recommend creating a new folder somewhere easy to access, like on your Desktop, named AgentTidy. Inside AgentTidy, create these subfolders:
Inbox(This is the folder our agent will watch – your messy downloads will go here first)Organized/ImagesOrganized/DocumentsOrganized/CodeOrganized/Other
Your structure should look something like this:
AgentTidy/
├── Inbox/
└── Organized/
├── Images/
├── Documents/
├── Code/
└── Other/
Now, let’s create a Python file inside your AgentTidy folder, named tidy_agent.py.
Coding Our First Agent: The Core Logic
Open tidy_agent.py in your code editor. We’ll build this up piece by piece.
Step 1: Imports and Configuration
First, we bring in our tools and define our paths.
import os
import shutil
import time
from watchdog.observers import Observer
from watchdog.events import FileSystemEventHandler
import filetype
# --- Configuration ---
WATCH_FOLDER = os.path.join(os.path.dirname(__file__), "Inbox")
ORGANIZED_BASE_FOLDER = os.path.join(os.path.dirname(__file__), "Organized")
# Define target subfolders based on file categories
DESTINATION_FOLDERS = {
"image": os.path.join(ORGANIZED_BASE_FOLDER, "Images"),
"document": os.path.join(ORGANIZED_BASE_FOLDER, "Documents"),
"code": os.path.join(ORGANIZED_BASE_FOLDER, "Code"),
"other": os.path.join(ORGANIZED_BASE_FOLDER, "Other"),
}
# Ensure all destination folders exist
for folder in DESTINATION_FOLDERS.values():
os.makedirs(folder, exist_ok=True)
print(f"Agent watching: {WATCH_FOLDER}")
print(f"Organizing into: {ORGANIZED_BASE_FOLDER}")
A quick note on os.path.join(os.path.dirname(__file__), ...): This is a neat trick to make sure our script finds the Inbox and Organized folders relative to where the script itself is run, no matter where you execute it from. This makes our agent more portable.
Step 2: The Event Handler – Our Agent’s Senses and Brain
The watchdog library works by having an “observer” that watches a folder, and an “event handler” that defines what happens when an event occurs (like a new file being created). This is where our agent’s logic lives.
class MyHandler(FileSystemEventHandler):
def on_created(self, event):
if event.is_directory:
return
file_path = event.src_path
file_name = os.path.basename(file_path)
print(f"Detected new file: {file_name}")
self.process_file(file_path)
def process_file(self, file_path):
try:
kind = filetype.guess(file_path)
if kind is None:
file_category = "other"
elif kind.mime.startswith("image/"):
file_category = "image"
elif kind.mime.startswith("text/") or kind.mime.endswith("pdf") or kind.mime.endswith("msword") or kind.mime.endswith("opendocument.text") or kind.mime.endswith("presentation") or kind.mime.endswith("spreadsheet"):
# A bit broad, but covers common documents. You can refine this!
file_category = "document"
elif file_path.endswith((".py", ".js", ".html", ".css", ".java", ".c", ".cpp", ".sh")):
# Simple check for common code files.
file_category = "code"
else:
file_category = "other"
destination_folder = DESTINATION_FOLDERS.get(file_category, DESTINATION_FOLDERS["other"])
# Construct a unique destination path to avoid overwriting
base_name, extension = os.path.splitext(os.path.basename(file_path))
dest_file_path = os.path.join(destination_folder, os.path.basename(file_path))
counter = 1
while os.path.exists(dest_file_path):
dest_file_path = os.path.join(destination_folder, f"{base_name}_{counter}{extension}")
counter += 1
shutil.move(file_path, dest_file_path)
print(f"Moved '{os.path.basename(file_path)}' to '{os.path.basename(destination_folder)}'")
except Exception as e:
print(f"Error processing {os.path.basename(file_path)}: {e}")
Let’s break down process_file:
filetype.guess(file_path): This is where the magic happens. It tries to figure out the actual file type.- Conditional Logic: We then use simple
if/elif/elsestatements to categorize the file based on its detected MIME type or, for code, its extension. This is our agent’s “reasoning.” You can expand these conditions significantly! shutil.move(): This is our agent’s “action” – moving the file.- Duplicate Handling: The
while os.path.exists(dest_file_path):loop is crucial. It ensures that if you download “report.pdf” twice, the agent will move the second one as “report_1.pdf” instead of overwriting the first. This is a simple form of conflict resolution.
Step 3: Starting the Agent – The Main Loop
Finally, we need to tell our observer to start watching and keep running.
if __name__ == "__main__":
event_handler = MyHandler()
observer = Observer()
observer.schedule(event_handler, WATCH_FOLDER, recursive=True)
observer.start()
print(f"Agent started. Watching for new files in '{WATCH_FOLDER}'...")
print("Press Ctrl+C to stop the agent.")
try:
while True:
time.sleep(1) # Keep the main thread alive
except KeyboardInterrupt:
observer.stop()
print("Agent stopped.")
observer.join()
observer.start() kicks off a separate thread to watch the folder. The while True: time.sleep(1) loop keeps our main program running so the observer thread can do its work. The try...except KeyboardInterrupt block allows you to gracefully stop the agent by pressing Ctrl+C in your terminal.
Running Your Agent for the First Time!
Okay, moment of truth! Save your tidy_agent.py file.
Open your terminal or command prompt, navigate to your AgentTidy folder (use cd path/to/AgentTidy), and then run your script:
python tidy_agent.py
You should see output like:
Agent watching: /path/to/AgentTidy/Inbox
Organizing into: /path/to/AgentTidy/Organized
Agent started. Watching for new files in '/path/to/AgentTidy/Inbox/'...
Press Ctrl+C to stop the agent.
Now for the fun part! Open your Inbox folder (the one inside AgentTidy). Drag and drop some files into it:
- A
.jpgimage - A
.pdfdocument - A
.pyPython script (you can just create an empty file namedtest.py) - Maybe a
.ziparchive (this should go into “Other”)
Watch your terminal! You should see messages indicating that files are being detected and moved. Then, check your Organized subfolders. Voila! Your files should be neatly sorted.
This is a real, live AI agent performing a useful task autonomously on your computer. How cool is that?
What We Just Built: The Agent’s Core Capabilities
Even though it’s simple, our “Tidy-Upper Agent” demonstrates key AI agent principles:
- Perception/Sensing: The
watchdoglibrary acts as our agent’s “eyes,” detecting new files. - Reasoning/Planning: Our
process_filefunction, with itsfiletype.guessand conditional logic, is its “brain,” deciding where a file belongs. - Action:
shutil.moveis its “hand,” performing the physical act of moving the file. - Autonomy: Once started, it runs on its own, continuously monitoring and acting without further human intervention.
This is the fundamental loop of almost every AI agent, from the simplest to the most complex multi-agent systems. They perceive, they reason, they act, and they learn (though ours doesn’t explicitly learn yet, it could be extended to).
Taking It Further: Ideas for Your Next Agent Iteration
This is just the beginning! Here are some ideas to expand your Tidy-Upper Agent, or to inspire your next AI agent project:
- More Granular Categorization: Instead of just “Documents,” could you sort by “Reports,” “Invoices,” “Letters”?
- Dynamic Folder Creation: What if it created a new folder for each month or year?
- Rename Files: Automatically rename files based on their content (e.g., “Invoice_ABC_2026-05-17.pdf”). This would involve using a more advanced LLM to read the file content.
- Cloud Integration: Instead of moving locally, upload certain file types to Google Drive or Dropbox.
- Notification System: Send you a desktop notification or an email when it moves a file.
- Error Handling & Logging: Make the agent more robust by logging errors to a file instead of just printing them.
- User Interface: Build a simple web interface (using Flask or Django) to configure the agent or view its activity.
- AI-Powered Naming/Tagging: This is where it gets really interesting! Imagine using an LLM (like OpenAI’s GPT-4o or a local open-source model) to read the content of a document and suggest a more descriptive filename or even tag it with keywords.
For that last point, you’d integrate an LLM API call within your process_file function. For example, after identifying a PDF as a document, you could send its text content to an LLM with a prompt like “Summarize this document and suggest a concise filename based on its content.” The LLM’s response would then inform your renaming action.
Actionable Takeaways
You’ve just built your first practical AI agent! Here’s what I want you to take away from this:
- AI Agents are Accessible: You don’t need to be a data scientist. With Python and some great libraries, you can build useful agents.
- Start Simple, Build Up: This file organizer is a perfect example. It does one thing well, and from that foundation, you can add complexity.
- Perception -> Reasoning -> Action: This loop is the heart of almost every agent. Understand it, and you understand agents.
- Don’t Be Afraid to Experiment: Change the categories, add new file types, try different actions. That’s how you learn!
The world of AI agents is exploding right now, and the best way to understand it isn’t just by reading about it, but by getting your hands dirty and building something. You’ve taken that first step, and honestly, that’s the biggest hurdle.
Keep tinkering, keep exploring, and let me know in the comments what kind of agents you’re dreaming up!
Until next time,
Emma
agent101.net
🕒 Published: