Hi everyone
I’m using the Postgres Chat Memory integration with the AI Agent node, and I want to update the stored messages so they also include tool_calls
(the tool name, arguments, and response).
The problem:
I’ve been trying to manually add tool_calls
into the messages stored by Postgres Chat Memory, but I ran into several errors along the way:
-
“string too long (id > 40 chars)” → fixed by reusing the
toolCallId
that the AI Agent generates instead of creating my own UUID. -
“invalid input syntax for type json (object vs string)” → fixed by serializing
arguments
as a stringified JSON, not as a raw object. -
“Missing required parameter: messages[x].tool_calls[0].function.name” → fixed by making sure I followed the correct schema with
function.name
andfunction.arguments
. -
“An assistant message with tool_calls must be followed by tool messages responding to each tool_call_id” → this still happens because I don’t know how to correctly store the tool response.
Right now I can successfully add a tool call like this:
"tool_calls": [
{
"id": "tool_call_id",
"type": "function",
"function": {
"name": "get_weather",
"arguments": "{\"location\":\"sf\"}"
}
}
]
What I need to know is:
What is the exact JSON structure that the Postgres Chat Memory block generates automatically?
I can add the tool_calls
, but what’s still missing is: how do I properly store the response for that tool call in Postgres Chat Memory, in a way that the AI Agent accepts it?
-
How does it store AI messages (
type: "ai"
) withtool_calls
? -
How does it expect the corresponding
tool
messages to look? -
What fields are mandatory (
id
,function.name
,function.arguments
, etc.)?
I’ve seen examples in the OpenAI / LangChain docs, but I want to be sure about the exact format that n8n expects in the Postgres Chat Memory table, so I can safely add or update tool call information without breaking compatibility.
Has anyone already inspected or documented the JSON that is written automatically by this node? A working example would be very helpful