Correct JSON structure for tool_calls in Postgres Chat Memory?

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 and function.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") with tool_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

(post deleted by author)

UPDATE:
I tried using the following:

{
  "type": "ai",
  "content": "Hello how are you?",
  "tool_calls": [
    {
      "id": "tool_call_id",
      "args": {
        "location": "sf"
      },
      "name": "get_weather",
      "type": "tool_call"
    }
  ],
  "tool_outputs": [
    {
      "output": "Done.",
      "tool_call_id": "tool_call_id"
    }
  ]
}

But I receive the error:

An assistant message with ‘tool_calls’ must be followed by tool messages responding to each ‘tool_call_id’. The following tool_call_ids did not have response messages: tool_call_id

I opened this topic being more objetctive: Tool response JSON schema for AI Agent node