How to use N8N Chat LoadPreviousSession set as Manually?

Describe the problem/error/question

I’m trying to use the Chat Trigger node with Load Previous Session = Manually.

When the chat widget first loads, it sends:

{
  "action": "loadPreviousSession",
  "sessionId": "b4a7310f-69e3-43d8-85aa-caf845ca740c",
  "metadata": {
    "sessionId": "atlas_1758029186304_rt4srhmuh"
  }
}

My workflow retrieves past conversation from memory and I transform it like this:

{
  "previousSession": [
    { "role": "user", "text": "hello" },
    { "role": "assistant", "text": "Hi, how can I help you today?" },
    { "role": "user", "text": "what is 2+2?" },
    { "role": "assistant", "text": "The answer is 4." }
  ]
}

But the chat widget does not render this conversation on the front-end.

I could not find any documentation showing the exact response format expected when loadPreviousSession is set to manually.

:backhand_index_pointing_right: My question:
What is the exact JSON structure I need to return so that the chat widget displays the previous conversation?


What is the error message (if any)?

There is no explicit error. The widget simply does not show the history.


Please share your workflow


Share the output returned by the last node

Currently I return:

{
  "previousSession": [
    { "role": "user", "text": "hello" },
    { "role": "assistant", "text": "Hi, how can I help you today?" },
    { "role": "user", "text": "what is 2+2?" },
    { "role": "assistant", "text": "The answer is 4." }
  ]
}


Expected output

I expect the chat widget to display these messages as conversation history, e.g.:

  • User: hello

  • Assistant: Hi, how can I help you today?

  • User: what is 2+2?

  • Assistant: The answer is 4.

Hi @felipe_agm

Welcome!

The format the Chat would expect there is defined as follows:

export interface LoadPreviousSessionResponseItem {
	id: string[];
	kwargs: {
		content: string;
		additional_kwargs: Record<string, unknown>;
	};
	lc: number;
	type: string;
}

export interface LoadPreviousSessionResponse {
	data: LoadPreviousSessionResponseItem[];
}

And this is basically just the raw output of messages from a memory node inside a new object with a data attribute.

To make this work with the memory manager you’d need to deactivate Simplify output to get back the raw messages and use either a Set or code node to return the messages with

{ data: $json.messages }

Hope that helps!