Hi everyone,
I’m developing a custom node for n8n that works similarly to an AI Agent in terms of how it stores data in a database (but it’s not related to AI itself).
My goal is for the node to generate an authority value, and then use that value — via AI Memory — to store data in a database like PostgreSQL.
Here’s the issue I’m facing:
My node needs to execute first to generate the authority value. I want to use this value as a sessionId in my Postgres table (or in any other AI Memory backend).
By default, AI Memory gets its sessionId from the previous node using the path $json.sessionId.
However, in my case, the authority value is created in the parent node, not the previous one.
Also, I don’t want to manually set the sessionId.
Another problem is that I can’t access the authority value from the parent node using expressions.
Important note:
I don’t want to build a workflow with multiple nodes (e.g. one for authority and another for database).
I want to have only one node, which internally can use AI Memory to interact with and store data in the database.
MyCode ![]()
const memory = await getOptionalMemory(this);
if (!memory) {
throw new NodeOperationError(this.getNode(), 'No memory connected to this node');
}
await memory.saveContext({ input: 'value' }, { output: String(processedParams['value']) });
I want to be able to do something like this:
If anyone has ideas, examples, or suggestions on how to achieve this, I’d really appreciate your help ![]()
