TAI Labs
TAI Lightning Lesson · Free

Stateful
AI agents
with n8n

Visual, debuggable agent workflows. Without overengineering.
Session
Live · one sitting
You bring
One agent idea · a browser
Led by
Aki WijesundaraAki Wijesundara
Manu JayawardanaManu Jayawardana
TAI Labs
The problem

Most agents fail from missing structure, not missing intelligence.

01

No memory

Every interaction starts from zero. The agent forgets the previous turn, the previous session, the user's name, the ticket status.

Amnesia
02

No control flow

Unpredictable decisions. No explicit logic. The agent picks a tool because the vibe felt right, not because a step told it to.

Vibes
03

No debuggability

When it fails, it's a black box. You get an error and a stack trace, but not the sequence of decisions that got there.

Opaque
Teams reach for heavy frameworks. Eighty percent of the time, a simple stateful workflow works better. That's what this session is about.
TAI Labs
Introduction · what is n8n

Open-source visual workflow automation. "Nodemation."

The primitives
  • Each node = an action. API call, AI model, data transform, decision.
  • Connections = data flow. The green lines between nodes carry the payload.
  • Every execution logged. Full input and output per node, saved automatically.
  • Click any node to see exactly what happened on that step, live.
Why n8n for agents

Logic is visible, debuggable, editable.

No Python or JS required. The whole workflow is on a canvas you can point at during a code review, hand off to a teammate, or open in a live incident.

Compare that to an opaque agent framework where the loop lives inside agent.run() and every debug is a printf-into-the-void.

TAI Labs
Core concept · chatbot vs agent

The difference is memory and state.

Chatbot

Input → process → output → done.

A single pass. No memory of the last turn. No plan for the next one. Every request is stateless. Fast, simple, useful for narrow tasks. Not an agent.

Agent

Perceive → remember → reason → act. Then loop.

Every step feeds the next. Memory carries context across turns. State tracks what has happened, what is pending, what is done. Different shape entirely.

Without memory and state, every interaction starts from scratch. Adding "please remember our last conversation" to a chatbot prompt doesn't make it an agent. Memory that lives across the loop does.
TAI Labs
Memory pattern 1 · window buffer

Short-term memory. A rolling window.

In n8n · Window Buffer Memory
  • Keeps a rolling window of the last N message pairs.
  • Injected into the prompt automatically each turn.
  • Oldest messages drop when the buffer fills.
  • Config to start with: five to ten pairs, unique session ID per user.
Human analogy

Your working memory during a conversation.

You remember what was said a moment ago. You don't remember every word from every conversation you've ever had. The window is bounded on purpose.

Use for: multi-turn conversations, follow-ups, clarifications. Scope is the current session only. When the session ends, the buffer is gone.

The rule of the session

Every piece of state is a visible node.

If the agent depends on it, it lives on the canvas as its own node. Nothing hidden inside a framework. Nothing implicit in a prompt. If you can't point at where a piece of state comes from and where it goes, you have already lost the debuggability you came for.

TAI Labs
Memory pattern 2 · persistent storage

Long-term memory. External datastore.

In n8n · three nodes
  • 1. Get Memories. Search the datastore (Google Sheets, Airtable, any DB) for this user.
  • 2. Aggregate. Compile the results into a context block for the agent.
  • 3. Save Memory. After the reply, write new facts back to the store for next time.
What to store
  • User identity and preferences.
  • Key decisions made.
  • Project context.
  • Important facts learned.

Use for: repeat users, support agents, personal assistants. Scope is across all sessions. Survives restarts, deploys, and the user closing the tab.

TAI Labs
Memory patterns · when to use each

Short-term for coherence. Long-term for continuity.

Short-term
Long-term
Scope
Current session
All sessions
Storage
In-memory buffer
External datastore
Lifespan
Gone when session ends
Persists indefinitely
n8n node
Window Buffer Memory
Get + Save Memory
Risk
Too small → amnesia
Stale data, latency
Use both. Short-term keeps the conversation coherent. Long-term keeps the relationship coherent. Different problems, different tools, same canvas.
TAI Labs
Architecture · the whole workflow

Every piece of state is a visible node. Nothing hidden.

Chat Interface RAW MESSAGE Path 1 · the user's ask GET MEMORIES Path 2 · from datastore Aggregate compile context Merge AI AGENT OpenAI + Window Buffer + Tools Save Memory write new facts Path 1 · short-term Path 2 · long-term
Key insight: both memory types feed into the same AI Agent node. Click any node to see exactly what happened. The workflow itself is the trace.
TAI Labs
Best practices · five principles

Five principles that keep stateful agents from overengineering themselves.

01
Make state explicit. If the agent depends on it, it is a node on the canvas. No implicit context. No "the model just knows".
02
Separate memory types. Don't force one system to do both short-term and long-term. They have different lifespans, different storage, different risks.
03
Design for debuggability. Click any node, see what happened. No black boxes. This is the whole point of visual workflows; do not throw it away with clever abstractions.
04
Start simple, extend later. Add complexity only with evidence it is needed. Every extra node you add without a failing case to justify it is a future incident source.
05
Control the loop. Clear inputs, clear outputs, no unbounded recursion. If the agent can call itself, decide out loud when it must stop.
TAI Labs
The takeaway

Eighty percent of the time, a simple stateful workflow beats a complex framework.

What to remember: agents fail from missing structure, not missing intelligence. n8n gives you visual, debuggable workflows without code. Combine short-term and long-term memory. Every piece of state should be explicit and inspectable.
Next

Agentic AI Builder's Bootcamp

Build shipping AI products with n8n, Claude Code, Cowork, and Hermes. Cohorts start monthly.

Where this leads
Now

Questions in chat

Post one agent you are trying to build. One line. Aki or Manu will sketch the memory design live.

Open floor
Later

Your first workflow

Open n8n. Add a Window Buffer node. Point it at your existing chatbot. That's a stateful agent. Send us the link.

The receipt
01 / 11