Describe the problem/error/question
How can I insert a message list JSON into the agent and make it as the context?
I just want to pass it to the agent as a temporary message context.
How can I insert a message list JSON into the agent and make it as the context?
I just want to pass it to the agent as a temporary message context.
hey @blowsnow Welcome to the n8n community!
I think if you just use the simple memory option and connect it to the ai agent, it will retain the context of the conversation you are having with the ai agent.
Let me know if this helps or if i’m misunderstanding the problem.
@blowsnow To pass a message list JSON as temporary context to an AI Agent in n8n, you have a few options:
Option 1: Use the Chat Memory Node
The Window Buffer Memory node lets you inject a conversation history:
Add a Window Buffer Memory node before your AI Agent
In the memory node, use the “Session ID” to create unique conversation contexts
Pass your message list JSON through an Edit Fields node to format it as:
{
"chatHistory": [
{"role": "user", "content": "Previous message"},
{"role": "assistant", "content": "Previous response"}
]
}
Connect this to your AI Agent node
Option 2: Include in System Message
Add your message context directly in the AI Agent’s system prompt:
In your AI Agent node, go to Options → System Message
Use an expression to inject your JSON:
Here is the conversation context:
{{ $json.messageHistory }}
Use this context to inform your responses.
Option 3: Use a Tool with Context
Create a custom tool that provides the context:
Add a Code Tool to your agent
Have it return your message list when called
The agent can reference this context as needed
Hope this helps!
Hi @blowsnow Welcome!
You can do something like this:
This can help you give JSON as a context to your AI Agent, hope this helps.