# Manage AI agent chat sessions: n8n workflow template

> Started by another system calling it, and works across n8n data table. 18 steps, 2 branches: a working afternoon to understand properly.

Source: https://millionrounds.com/workflow/manage-ai-agent-chat-sessions (Millionrounds; every figure on the page links to its filing or article)

[Automation library](https://millionrounds.com/workflows) · [Integrations](https://millionrounds.com/workflows?category=Integrations#library)

# Manage AI agent chat sessions

Started by another system calling it, and works across n8n data table. 18 steps, 2 branches: a working afternoon to understand properly.

Medium

[Download free](https://millionrounds.com/login?next=%2Fapp%2Fworkflow%2Fmanage-ai-agent-chat-sessions)

**18 steps** Medium: a working afternoon

**2** Branches: places the flow splits

**0** Loops or waits

**1** Service it connects to

## The flow

Starts it 2 Logic 9 Service 7

The steps in the order they run, from what starts it.

- 1 **Handle Incoming Message** Webhook *Starts it*
- 2 **Handle Control Request** Webhook *Starts it*
- 3 **Normalize Message Input** Code *Logic*
- 4 **Normalize Command Input** Code *Logic*
- 5 **Configure Session Parameters** Code *Logic*
- 6 **Route by Request Type** Switch *Logic*
- 7 **Fetch Latest Session** Data Table *Service*
- 8 **Fetch Session for Control** Data Table *Service*
- 9 **Evaluate Session State** Code *Logic*
- 10 **Execute Session Command** Code *Logic*
- 11 **Route by Session Status** Switch *Logic*
- 12 **Modify Session State** Data Table *Service*
- 13 **Create New Session Record** Data Table *Service*
- 14 **Log Activity Update** Data Table *Service*
- 15 **Expire Old Session** Data Table *Service*
- 16 **Restore to Active Session** Data Table *Service*
- 17 **Build Session Context** Code *Logic*
- 18 **Generate Control Result** Code *Logic*

## How it's built

- **Starts on:** Another system calling it
- **Steps:** 18, with 2 branches
- **Size:** Medium: a working afternoon
- **Connects to:** n8n data table
- **Model:** None. This is plumbing, not judgement

## Questions

What does it need to run?

An n8n account. You connect your own accounts after importing it; none are included.

What starts it?

It starts on another system calling it.

Does it use AI?

No. Every step is fixed logic or a call to a service, so it does the same thing every time.

How long does it take to set up?

Plan an afternoon. 18 steps is enough that you should read each one before running it.

How do I import it?

Copy the workflow, open a new workflow in n8n and paste. The steps appear on the canvas, ready for your own accounts.

**Before you run it**

Nothing here has been tested by us. It is somebody's working automation, read and described from its own steps. Treat the connections it wants as a list of accounts it will touch, and read the 18 steps before you point it at anything that matters.

## Run it in n8n

- **Create your n8n account** Free to start. n8n is where the workflow runs. [Create an n8n account ↗](https://millionrounds.com/n8n)
- **Download the workflow** Free with a Millionrounds account. [Download free](https://millionrounds.com/login?next=%2Fapp%2Fworkflow%2Fmanage-ai-agent-chat-sessions)
- **Paste it into n8n** Open a new workflow in n8n and paste. Then connect your own accounts.

Stored with the author's traces removed: canvas notes, instance identifiers, saved credential names and any live document they had left behind.

## Connects to

Each opens the other workflows that use it.

[n8n data table](https://millionrounds.com/workflows?service=n8n+data+table#library)

## Workflows like it

Also integrations, with the same services where possible, closest in size first.

- [**Back up a Linux server directory to Backblaze B2** 18 steps · n8n data table](https://millionrounds.com/workflow/back-up-a-linux-server-directory-to-backblaze-b2)
- [**Back up self-hosted workflows to Google Drive daily** 18 steps · Google Drive, n8n data table](https://millionrounds.com/workflow/back-up-self-hosted-workflows-to-google-drive-daily)
- [**Acquire hierarchical mutex tokens** 17 steps · n8n data table](https://millionrounds.com/workflow/acquire-hierarchical-mutex-tokens)
- [**Back up Linux server directories to Google Drive with Borg** 20 steps · Google Drive, n8n data table](https://millionrounds.com/workflow/back-up-linux-server-directories-to-google-drive-with-borg)
- [**Generate product and marketing images with Riverflow 2.0** 20 steps · n8n data table](https://millionrounds.com/workflow/generate-product-and-marketing-images-with-riverflow-2-0)
- [**Protect downstream APIs with Data Tables** 16 steps · n8n data table](https://millionrounds.com/workflow/protect-downstream-apis-with-data-tables)
