Hi everyone,
I’m using n8n Postgres Chat Memory with the AI Agent node, and I’m trying to manually add the response of a tool into the stored messages. But I keep running into errors with the JSON schema that the AI Agent node expects.
At first, I was able to add the tool_calls schema. I got errors about missing fields (function.name, id, etc.), and I fixed them by adding each required property. Now the assistant no longer complains about tool_callwhen I save something like this:
{
"type": "ai",
"content": "Hello how are you?",
"tool_calls": [
{
"id": "tool_call_id",
"name": "get_weather",
"args": {
"location": "sf"
},
"type": "tool_call"
}
]
}
But then I hit the next problem:
When consulting the memory, the AI Agent throws this error:
An assistant message with ‘tool_calls’ must be followed by tool messages responding to each ‘tool_call_id’.
I understand this means I need to provide a tool response message, but I don’t know the correct schema to save it in Postgres Chat Memory.
I tried adding a tool_outputs field inline, but this approach failed:
{
"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"
}
}
]
}
I also tried moving tool_outputs outside of tool_calls, but I still get the same error.
Does anyone know the exact JSON format that the AI Agent node expects for tool responses in Postgres Chat Memory?
Thanks in advance!