Showing posts with label Agent Building Series. Show all posts
Showing posts with label Agent Building Series. Show all posts

Friday, June 5, 2026

How to Give Your AI Agent Memory Using Simple Storage


Up to this point in the series, we’ve built practical AI agents using n8n, Ollama, and Phi-3 that can organize files and summarize emails.

However, all of these agents share one major limitation:

They do not remember anything.

Each workflow run is independent. The system processes input, produces output, and then forgets everything immediately after.

To move from basic automation to more advanced AI agents, we need to introduce memory.

In this article, we’ll build a simple but powerful memory system using local storage and n8n workflows. This will allow our AI agents to store past decisions, recall context, and improve future outputs.


Why AI Agents Need Memory

Without memory, an AI agent behaves like a stateless function:

Input → Output → Forget

This is fine for simple tasks like classification, but it becomes a limitation when building real systems.

Memory enables:

  • Consistent decisions over time

  • Context-aware responses

  • Learning from past actions

  • Smarter automation logic

  • Personalized behavior

For example:

Without Memory

Email arrives → AI says "High priority"
Next email from same sender → AI treats it differently

With Memory

Email arrives → AI checks sender history → consistent prioritization

This is what transforms a workflow into a real AI agent system.


The Simplest Memory System: Local Storage

We don’t need complex databases to implement memory.

For local AI systems using n8n, we can start with:

  • JSON files

  • CSV logs

  • Simple databases (SQLite)

  • Google Sheets (optional hybrid)

  • Local folders as structured storage

In this guide, we will use a JSON-based memory system, because it is:

  • Easy to implement

  • Fully local

  • Human-readable

  • Flexible for expansion


Memory Architecture Overview

Our updated AI agent architecture becomes:

Input
↓
n8n Workflow
↓
Load Memory (JSON)
↓
Phi-3 Reasoning (via Ollama)
↓
Update Memory
↓
Decision + Action
↓
Save Memory

Now every interaction can influence future behavior.


Step 1: Define What Your Agent Should Remember

Before building anything, we must define memory structure.

For our email and file agents, useful memory includes:

Email Agent Memory

  • Sender reputation (High / Medium / Low priority)

  • Past email classifications

  • Common topics per sender

File Organizer Memory

  • File type patterns

  • User corrections (if misclassified)

  • Folder preferences

Example JSON structure:

{
  "senders": {
    "team@company.com": {
      "priority": "high",
      "count": 12
    }
  },
  "file_patterns": {
    "invoice": "Invoices",
    "resume": "Resumes"
  }
}

This becomes the brain’s memory layer.


Step 2: Create a Memory File

Create a file on your system:

memory.json

Place it in a dedicated folder:

C:\AI-Agent-Memory\memory.json

Start with an empty structure:

{
  "senders": {},
  "files": {}
}

This file will evolve as your agent runs.


Step 3: Load Memory in n8n

In your workflow, add a node at the beginning:

Read File Node

  • File Path: memory.json

This loads existing memory into the workflow.

Now the AI has access to past context.


Step 4: Send Memory to Phi-3

Next, we include memory in the prompt sent to Phi-3.

Example prompt:

You are an AI assistant with memory.

Use the memory below to make better decisions.

MEMORY:
{{memory}}

TASK:
Analyze this email and classify importance.

EMAIL:
Subject: {{subject}}
Body: {{body}}

Now Phi-3 is no longer stateless—it is context-aware.


Step 5: Updating Memory After Each Run

After Phi-3 produces an output, we update memory.

Example logic:

If email is high priority:

Increase sender priority score

If file is misclassified:

Update file pattern mapping

In n8n, this is done using:

  • Set Node (modify memory object)

  • Function Node (JavaScript logic)

  • Write File Node (save updated JSON)


Step 6: Example Memory Update Logic

Here is a simple rule:

If sender exists:
    increase count
    adjust priority

If sender not exists:
    create new entry

This creates a learning system over time.


Step 7: Save Updated Memory

After updating, write the memory back to disk:

  • File: memory.json

  • Mode: overwrite

Now the system has learned something new.


Step 8: How Memory Improves Your AI Agents

Let’s compare behavior.

Before Memory

Email from team@company.com → Medium priority
Email from team@company.com → Medium priority
Email from team@company.com → Medium priority

After Memory

Email 1 → Medium
Email 2 → High (based on history)
Email 3 → High (consistent pattern learned)

The system becomes adaptive instead of static.


Step 9: Real-World Use Cases

1. Smart Email Assistant

  • Learns important senders

  • Prioritizes messages automatically

  • Reduces manual filtering


2. File Organizer with Learning

  • Learns new file types

  • Improves classification accuracy over time

  • Adapts to user corrections


3. Personal Workflow Assistant

  • Remembers user preferences

  • Adjusts responses dynamically

  • Improves automation decisions


Step 10: Limitations of Simple Memory

While effective, JSON-based memory has limitations:

  • Not scalable for large datasets

  • No advanced querying

  • No multi-user support

  • Risk of corruption if not handled properly

Later in the series, we can upgrade to:

  • SQLite databases

  • Vector databases

  • Hybrid memory systems

But JSON is perfect for starting local AI systems.


Why This Matters

Memory is what separates a chatbot from an AI agent.

Without memory:

System = Stateless tool

With memory:

System = Learning automation agent

Even simple memory dramatically improves usefulness.


The Updated AI Agent Architecture

Now our system looks like this:

Input
↓
n8n
↓
Load Memory
↓
Phi-3 (Ollama)
↓
Update Memory
↓
Decision Logic
↓
Action
↓
Save Memory

This is the foundation of persistent AI systems.


Conclusion

Adding memory to your AI agent is a major step forward in building intelligent automation systems.

With a simple JSON file and n8n workflows, we’ve introduced:

  • Persistence

  • Learning behavior

  • Context awareness

  • Adaptive decision-making

Even though the system is simple, the impact is significant.

Your AI agents are no longer stateless scripts—they are evolving systems.


What’s Next?

Now that our agents can remember information, the next step is making them more powerful and practical.

In the next article, we’ll explore:

How to Turn Your AI Agent into a Multi-Tool Automation System

We’ll connect APIs, external services, and advanced workflows to expand what our local AI system can actually do in real-world scenarios.

Building an Email Summarizer AI Agent (Fully Local Setup)


After building a File Organizer AI Agent, we now move to one of the most impactful real-world automations: managing email overload.

Emails are one of the most common sources of daily information fatigue. Important messages get buried under newsletters, promotions, and low-priority notifications.

In this project, we will build an Email Summarizer AI Agent using n8n, Ollama, and Phi-3.

This agent will:

  • Monitor incoming emails

  • Extract email content

  • Summarize messages

  • Identify importance level

  • Provide actionable insights

Everything runs locally, meaning no external APIs or cloud AI services are required.


What We’re Building

The workflow architecture looks like this:

New Email
↓
n8n Email Trigger
↓
Extract Email Content
↓
Phi-3 Summarization (via Ollama)
↓
Classify Importance
↓
Output Summary / Notification

Example transformation:

Subject: Meeting rescheduled to Friday

Original Email:
Long discussion about schedule changes...

↓
Phi-3 Output:
Summary: Meeting moved to Friday
Importance: High
Action: Update calendar

Why Build an Email Summarizer Agent?

Unlike file organization, email management involves interpretation and prioritization.

A good email agent helps you:

  • Reduce reading time

  • Focus on important messages

  • Avoid missing critical updates

  • Automatically filter noise

This is where AI adds real value.


Step 1: Configure Email Input in n8n

Open n8n and create a new workflow:

AI Email Summarizer

Now add an email trigger node.

Depending on your setup, this could be:

  • IMAP Email Trigger

  • Gmail Trigger

  • Outlook Trigger

Configure it to watch your inbox in real time.

Once set, every new email will trigger the workflow automatically.


Step 2: Extract Email Content

After the trigger node, add a data extraction step.

We only need:

  • Subject

  • Sender

  • Email body

Example structure:

{
  "subject": "Project Update",
  "from": "team@company.com",
  "body": "We have updated the project timeline..."
}

Keep the input clean before sending it to the AI model.


Step 3: Connect Phi-3 via Ollama

Add an AI Agent node and configure:

Model Provider

Ollama

Model

Phi-3

Endpoint

http://localhost:11434

This ensures all processing stays local on your machine.


Step 4: Create the Summarization Prompt

Prompt design is critical for consistent results.

Use the following structured prompt:

You are an email assistant.

Your task is to:
1. Summarize the email in 1–2 sentences
2. Identify importance (High, Medium, Low)
3. Suggest a possible action

Email:

Subject: {{subject}}
From: {{from}}
Body: {{body}}

Return format:

Summary:
Importance:
Action:

This forces structured output, which is essential for automation.


Step 5: Example AI Output

For an email like:

Subject: Server Maintenance Tonight
Body: We will perform maintenance at 11 PM...

Phi-3 might return:

Summary: Server maintenance scheduled tonight at 11 PM.
Importance: High
Action: Inform stakeholders and prepare downtime notice.

This structured format allows n8n to make decisions automatically.


Step 6: Add Decision Logic

After the AI node, add a Switch node.

We will classify emails based on importance.

Rules:

High → Immediate Notification

Medium → Daily Digest

Low → Store Only

This is the decision layer of the agent.


Step 7: Configure Output Actions

Now we define what happens for each category.

High Priority Emails

  • Send notification (Telegram, Discord, Email)

  • Mark as unread

  • Flag for review


Medium Priority Emails

  • Add to daily summary log

  • Store in database or spreadsheet


Low Priority Emails

  • Archive automatically

  • No notification


Step 8: Optional Enhancement — Daily Digest System

Instead of sending every summary individually, you can batch medium-priority emails.

Workflow:

Collect Emails (24h)
↓
Group Data
↓
Phi-3 Summary Report
↓
Send Daily Digest

This creates a personal AI assistant that summarizes your entire inbox each day.


Step 9: Testing the Agent

Send test emails such as:

Example 1

Subject: Invoice for April Services

Example 2

Subject: Weekly Newsletter

Example 3

Subject: Urgent: Password Reset Required

Observe how the AI classifies and summarizes each message.


Why This Architecture Works

This system separates responsibilities clearly:

n8n Handles

  • Email monitoring

  • Data routing

  • Notifications

  • Storage

  • Scheduling

Phi-3 Handles

  • Understanding email content

  • Summarization

  • Priority classification

  • Action suggestions

This division ensures reliability and scalability.


Improving the Agent

Once the basic system works, you can enhance it with:

1. Calendar Integration

Automatically create events from emails.


2. Task Management

Convert important emails into tasks (Todoist, Notion, etc.).


3. Sender Reputation System

Prioritize emails based on sender history.


4. Spam Filtering Layer

Use AI to detect and ignore irrelevant messages.


5. Memory System

Store past summaries to improve future classification.


Limitations of the Basic Version

While powerful, this initial version has limitations:

  • No long-term memory

  • No deep contextual understanding

  • Relies on email content quality

  • May misclassify ambiguous messages

These will be addressed in later advanced agent designs.


What We Learned

This project reinforces the core AI agent pattern:

Input → Process → Reason → Decide → Act

In this case:

  • Input: Email

  • Process: n8n extraction

  • Reason: Phi-3 summarization

  • Decide: Importance classification

  • Act: Notification or storage

This pattern is the foundation of all practical AI automation systems.


Conclusion

We have now built a fully functional Email Summarizer AI Agent that runs entirely on local infrastructure.

It demonstrates how AI can be used not just for conversation, but for real productivity improvement.

With n8n handling automation and Phi-3 providing intelligence, we can transform overwhelming email streams into structured, actionable insights.


What’s Next?

Now that we can organize files and manage emails, the next step is expanding our agent capabilities further.

In the next article, we will build:

How to Give Your AI Agent Memory Using Simple Storage

This will allow our agents to remember past interactions, improve decision-making, and become more context-aware over time.

Creating a File Organizer AI Agent with n8n + Phi-3

 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.

Designing Your First Local AI Agent Architecture


In the previous article, we built our first AI chat workflow using Phi-3, Ollama, and n8n. While that workflow demonstrated how local AI can process and respond to user input, it was still fundamentally a chatbot.

A true AI agent is different.

Instead of waiting for a user to initiate every interaction, an AI agent operates within a workflow, receives information from multiple sources, makes decisions, and triggers actions.

In this article, we'll learn how to design a local AI agent architecture and understand the core components that make AI agents work.

This architectural foundation will guide every automation project we build throughout the rest of this series.


What Is an AI Agent?

An AI agent is a system that combines:

  • Inputs

  • Intelligence

  • Decision-making

  • Actions

Unlike a simple chatbot, an agent has a purpose.

For example:

New File Arrives
↓
Analyze File
↓
Determine Category
↓
Move File

Or:

New Email
↓
Summarize Content
↓
Determine Priority
↓
Notify User

The language model is only one part of the system.

The workflow surrounding the model is what transforms it into an agent.


The Four Core Components of an AI Agent

Nearly every practical AI agent contains four major components.

1. Input Layer

This is where information enters the system.

Examples include:

  • Chat messages

  • Emails

  • Files

  • Webhooks

  • APIs

  • Database records

  • Scheduled tasks

The input layer answers the question:

What event causes the agent to act?

Without an input source, the agent has nothing to process.


2. Reasoning Layer

This is where Phi-3 operates.

The reasoning layer evaluates information and generates insights.

Examples:

  • Classification

  • Summarization

  • Decision-making

  • Content generation

  • Data extraction

In our architecture:

Input
↓
Phi-3

The model acts as the brain of the system.


3. Decision Layer

This layer determines what happens next.

Examples:

If invoice → Finance Folder

If resume → Recruitment Folder

If urgent email → Send Alert

Many AI agents fail because they rely entirely on the model for decision-making.

In practice, deterministic workflow logic often produces more reliable systems.

A good agent combines:

  • AI reasoning

  • Workflow rules


4. Action Layer

The final layer performs real work.

Examples:

  • Move files

  • Send emails

  • Update databases

  • Create reports

  • Trigger notifications

  • Call APIs

This is where the agent produces value.

Without actions, the agent is simply generating text.


The Basic Local AI Agent Architecture

Our local AI architecture currently looks like this:

Input
↓
n8n
↓
Ollama
↓
Phi-3
↓
Decision
↓
Action

Each component has a clear responsibility.

n8n

Coordinates the workflow.

Ollama

Provides access to the language model.

Phi-3

Performs reasoning.

Actions

Interact with the real world.

This separation makes the system easier to maintain and improve.


Designing Around Tasks, Not Models

One of the most common beginner mistakes is designing around the AI model.

For example:

I have Phi-3.
What can I do with it?

A better approach is:

I need to organize files.
How can AI help?

Start with the task.

Then determine where AI adds value.

This mindset leads to simpler and more reliable agents.


Example Agent: File Organizer

Let's examine a practical architecture.

Goal

Automatically organize downloaded files.

Workflow

Watch Downloads Folder
↓
Read Filename
↓
Phi-3 Classifies File
↓
Determine Destination Folder
↓
Move File

Notice that Phi-3 only performs one responsibility:

Classification.

The workflow handles everything else.

This keeps the system focused and predictable.


Example Agent: Email Summarizer

Goal

Reduce email overload.

Workflow

New Email
↓
Extract Content
↓
Phi-3 Creates Summary
↓
Determine Priority
↓
Send Notification

Again, the model contributes intelligence while n8n handles orchestration.


Example Agent: Research Assistant

Goal

Extract insights from documents.

Workflow

Document Added
↓
Read File
↓
Phi-3 Extracts Key Points
↓
Generate Summary
↓
Store Results

This pattern can scale from simple personal projects to enterprise systems.


The Importance of Clear Responsibilities

A well-designed agent assigns each component a specific job.

Good Design

n8n → Workflow Logic

Phi-3 → Reasoning

Storage → Memory

APIs → External Data

Actions → Execution

Poor Design

Everything handled by AI

When AI is responsible for every decision, systems become unpredictable.

A balanced architecture is easier to debug and maintain.


Thinking Like a Systems Designer

As your projects become more advanced, you'll spend less time writing prompts and more time designing systems.

Questions to ask include:

  • What triggers the workflow?

  • What information is needed?

  • What should the model analyze?

  • What decisions must be made?

  • What action should occur?

These questions define the architecture.

The model simply fills one role within it.


Common Beginner Mistakes

Mistake 1: Making AI Do Everything

Not every problem requires AI.

Use workflow logic whenever possible.

Use AI only where reasoning is needed.


Mistake 2: No Clear Goal

An agent should solve a specific problem.

Avoid vague objectives such as:

Build a smart AI assistant

Instead define:

Automatically organize downloaded files

Specific goals produce better architectures.


Mistake 3: Ignoring Actions

An AI response alone rarely creates value.

Always ask:

What should happen after the AI responds?

The answer usually involves an action.


A Blueprint for Future Projects

Throughout the remainder of this series, nearly every project will follow this structure:

Trigger
↓
Collect Data
↓
Phi-3 Analysis
↓
Decision Logic
↓
Action

Whether we're processing documents, organizing files, managing emails, or building autonomous workflows, the architecture remains largely the same.

Master this pattern and you'll be able to build a wide range of practical AI systems.


Conclusion

Designing an AI agent is not about creating the most intelligent model possible.

It's about building a system where intelligence is applied at the right point in a workflow.

A successful local AI agent combines:

  • Reliable inputs

  • Structured reasoning

  • Clear decision-making

  • Meaningful actions

With Phi-3 providing intelligence, Ollama providing local model execution, and n8n orchestrating workflows, we now have everything needed to begin building useful AI agents.

The challenge is no longer technology.

It's architecture.


What's Next?

Now that we understand how AI agents are structured, it's time to build our first practical automation project.

In the next article, we'll create a complete File Organizer AI Agent that automatically categorizes and organizes files using Phi-3 and n8n.

This project will introduce real-world automation and demonstrate how agent architecture translates into practical results.

AI-Powered Software Development with n8n, Ollama, and Phi-3

  Introduction Software development is changing rapidly with the rise of Artificial Intelligence. Tasks that once required hours of manual e...