After learning how to design AI agent architectures, it's time to build our first practical AI-powered automation.
One of the most common frustrations for computer users is managing files. Downloads folders become cluttered, documents get misplaced, and finding important files becomes increasingly difficult over time.
In this project, we'll build a File Organizer AI Agent using n8n, Ollama, and Phi-3.
The agent will automatically:
Monitor a folder
Detect new files
Analyze filenames
Determine file categories
Move files into appropriate folders
By the end of this tutorial, you'll have a working AI agent that organizes files without manual intervention.
What We're Building
Our workflow architecture looks like this:
New File
↓
n8n Detects File
↓
Extract Filename
↓
Phi-3 Classifies File
↓
Determine Destination Folder
↓
Move File
For example:
resume_john_smith.pdf
↓
Phi-3 → Resume
↓
Move to:
Documents/Resumes
Or:
invoice_may_2026.pdf
↓
Phi-3 → Invoice
↓
Move to:
Documents/Invoices
This simple workflow demonstrates the core principles behind AI-powered automation.
Step 1: Create the Folder Structure
First, create a test folder.
Example:
C:\AI-File-Agent\Inbox
This folder will act as the monitored location.
Next, create destination folders:
C:\AI-File-Agent\Documents
C:\AI-File-Agent\Invoices
C:\AI-File-Agent\Resumes
C:\AI-File-Agent\Images
C:\AI-File-Agent\Other
These folders will receive files based on the AI's classification.
Step 2: Create a New Workflow in n8n
Open n8n and create a new workflow.
Name it:
AI File Organizer
We'll gradually build the workflow one node at a time.
Step 3: Add a Folder Trigger
Add a node that monitors files.
Depending on your n8n version, this may be:
Local File Trigger
or
Schedule Trigger
↓
Read Directory
The objective is simple:
Detect when a new file appears in the Inbox folder.
Step 4: Extract the Filename
Once a file is detected, add a node that retrieves:
{
"filename": "invoice_may_2026.pdf"
}
We don't need to send the entire file to Phi-3.
For this first version, the filename alone is sufficient.
This keeps the workflow lightweight and fast.
Step 5: Connect Phi-3
Add an AI Agent node.
Configure:
Model
phi3
Provider
Ollama
Endpoint
http://localhost:11434
Now n8n can communicate with your local AI model.
Step 6: Create the Classification Prompt
This prompt is critical.
Instead of asking Phi-3 open-ended questions, we want predictable responses.
Use:
You are a file classification assistant.
Classify the following filename into one category:
Invoice
Resume
Image
Document
Other
Return only the category name.
Filename:
{{filename}}
Example output:
Invoice
This consistency makes automation easier.
Step 7: Add Decision Logic
After the AI node, add a Switch node.
The Switch node evaluates the category returned by Phi-3.
Example:
Invoice → Invoices Folder
Resume → Resumes Folder
Image → Images Folder
Document → Documents Folder
Other → Other Folder
This is the Decision Layer of our AI agent.
Step 8: Move the File
For each branch, add a file operation node.
Examples:
Invoice Branch
Move File
From:
Inbox
To:
Invoices
Resume Branch
Move File
From:
Inbox
To:
Resumes
Repeat for all categories.
Now the workflow can physically organize files.
Step 9: Test the Agent
Drop several files into the Inbox folder.
Examples:
invoice_april.pdf
resume_mark_jones.pdf
vacation_photo.jpg
meeting_notes.docx
Run the workflow.
Watch as files are automatically routed to the correct folders.
The AI is now actively participating in a real-world automation process.
Why This Architecture Works
Notice something important:
Phi-3 does not move files.
Phi-3 does not monitor folders.
Phi-3 does not make workflow decisions.
Instead:
n8n Handles
Monitoring
Routing
File operations
Phi-3 Handles
Understanding
Classification
Reasoning
This separation keeps the system reliable.
AI is only used where intelligence is needed.
Improving Accuracy
Filename classification works surprisingly well, but it has limitations.
For example:
document1.pdf
provides little context.
A better version of this agent would:
Read File
↓
Extract Text
↓
Send Content to Phi-3
↓
Classify
↓
Move File
This allows the model to classify based on actual content rather than filenames.
We'll build more advanced versions later in the series.
Adding Confidence Checks
Sometimes the model may be uncertain.
You can improve reliability by modifying the prompt:
Return:
Category:
Confidence:
Example:
Invoice
95%
Then use n8n logic such as:
If confidence > 80%
Move File
Else
Move to Review Folder
This creates a human-review workflow for ambiguous files.
Expanding the Agent
Once the basic organizer works, you can add:
Duplicate Detection
Identify duplicate files before moving them.
OCR Processing
Read scanned documents and images.
Metadata Extraction
Extract dates, names, or invoice numbers.
Database Logging
Record every classification event.
Email Notifications
Send a notification whenever files are processed.
This is how simple AI agents gradually evolve into intelligent workflow systems.
What We Learned
This project introduced the complete AI agent lifecycle:
Trigger
↓
Data Collection
↓
AI Reasoning
↓
Decision Logic
↓
Action
Every major AI automation system follows this pattern.
Whether you're organizing files, processing emails, or managing customer requests, the architecture remains remarkably similar.
Conclusion
Our File Organizer AI Agent is the first real automation project in this series.
It demonstrates how Phi-3, Ollama, and n8n can work together to solve a practical problem.
More importantly, it shows that AI agents don't need to be complicated.
A successful agent often performs one task well:
Detect
Analyze
Decide
Act
Master this pattern and you'll be able to build increasingly sophisticated local AI systems.
What's Next?
Now that we've built an AI-powered file organizer, we'll move on to another highly practical automation project:
Building an Email Summarizer AI Agent with Phi-3 and n8n
In that project, our AI will automatically read incoming emails, generate concise summaries, identify priority messages, and help reduce information overload.
We'll continue expanding our local AI toolkit one workflow at a time.
No comments:
Post a Comment