Describe the problem/error/question
I don’t know what is going, why is the AI Agent node not running correctly even though all the Parameters are Green.
What is the error message (if any)?
Got unexpected type: undefined
Please share your workflow
(Select the nodes on your canvas and use the keyboard shortcuts CMD+C/CTRL+C and CMD+V/CTRL+V to copy and paste the workflow.)
{
“nodes”: [
{
“parameters”: {
“workflowInputs”: {
“values”: [
{
“name”: “body”
},
{
“name”: “session_id”
}
]
}
},
“type”: “n8n-nodes-base.executeWorkflowTrigger”,
“typeVersion”: 1.1,
“position”: [
-512,
0
],
“id”: “4a847219-20f8-4151-9a82-dcef56cfe58f”,
“name”: “When Executed by Another Workflow”
},
{
“parameters”: {
“operation”: “select”,
“schema”: {
“__rl”: true,
“mode”: “list”,
“value”: “public”
},
“table”: {
“__rl”: true,
“value”: “clinic_convo_history”,
“mode”: “list”,
“cachedResultName”: “clinic_convo_history”
},
“where”: {
“values”: [
{
“column”: “session_id”,
“value”: “={{ $json.session_id }}”
}
]
},
“combineConditions”: “OR”,
“sort”: {
“values”: [
{
“column”: “session_id”,
“direction”: “DESC”
}
]
},
“options”: {
“outputColumns”: [
“first_name”,
“last_name”,
“email”,
“phone_number”,
“appointment_date”,
“appointment_time”,
“updated_time”,
“updated_date”
]
}
},
“type”: “n8n-nodes-base.postgres”,
“typeVersion”: 2.6,
“position”: [
-304,
0
],
“id”: “844d42d2-11ec-424e-b730-eb1e2dd3efc5”,
“name”: “Select rows from a table1”,
“credentials”: {
“postgres”: {
“id”: “YOUR_POSTGRES_CREDENTIAL_ID”,
“name”: “Pg Connection”
}
}
},
{
“parameters”: {
“promptType”: “define”,
“text”: “={{ $(‘When Executed by Another Workflow’).item.json.body }}”,
“options”: {
“systemMessage”: “## JOB\n- Analyze the message and output these variables based on the user message (these are all boolean (true or false):\n\n- general (could be a question or a basic conversation phrase e.g hi, hello, etc)\n- wants_to_book (whether or not the user wants to book an appointment)\n- wants_to_update (whether or not the user wants to update their appointment)\n- wants_to_cancel (whether or not the user wants to cancel their appointment)”
}
},
“type”: “@n8n/n8n-nodes-langchain.agent”,
“typeVersion”: 2.2,
“position”: [
-96,
0
],
“id”: “34c3cde2-e464-4e47-bfb2-cb69a7fb3fd9”,
“name”: “AI Agent”
},
{
“parameters”: {
“sessionIdType”: “customKey”,
“sessionKey”: “={{ $(‘When Executed by Another Workflow’).item.json.session_id }}”,
“tableName”: “clinic_convo_history”,
“contextWindowLength”: 15
},
“type”: “@n8n/n8n-nodes-langchain.memoryPostgresChat”,
“typeVersion”: 1.3,
“position”: [
0,
208
],
“id”: “8da7a056-9876-43b4-9300-631607ced515”,
“name”: “Postgres Chat Memory”,
“credentials”: {
“postgres”: {
“id”: “YOUR_POSTGRES_CREDENTIAL_ID”,
“name”: “Pg Connection”
}
}
},
{
“parameters”: {
“model”: {
“__rl”: true,
“mode”: “list”,
“value”: “gpt-4.1-mini”
},
“options”: {}
},
“type”: “@n8n/n8n-nodes-langchain.lmChatOpenAi”,
“typeVersion”: 1.2,
“position”: [
-240,
208
],
“id”: “a3301623-e102-4cac-a89a-e007aeec9ca6”,
“name”: “OpenAI Chat Model”,
“credentials”: {
“openAiApi”: {
“id”: “YOUR_OPENAI_API_CREDENTIAL_ID”,
“name”: “Whatsapp key”
}
}
},
{
“parameters”: {
“jsCode”: “// N8N Code Node to parse JSON string and extract variables separately\nconst items = $input.all();\n\nreturn items.map(item => {\n // Parse the JSON string from the output field\n const parsedData = JSON.parse(item.json.output);\n \n // Return each variable separately in an output wrapper\n return {\n json: {\n general: parsedData.general,\n wants_to_book: parsedData.wants_to_book,\n wants_to_update: parsedData.wants_to_update,\n wants_to_cancel: parsedData.wants_to_cancel\n }\n };\n});”
},
“type”: “n8n-nodes-base.code”,
“typeVersion”: 2,
“position”: [
256,
0
],
“id”: “9f57b85c-b3a0-4323-8027-665aae8ceb74”,
“name”: “Code”
}
],
“connections”: {
“When Executed by Another Workflow”: {
“main”: [
[
{
“node”: “Select rows from a table1”,
“type”: “main”,
“index”: 0
}
]
]
},
“Select rows from a table1”: {
“main”: [
[
{
“node”: “AI Agent”,
“type”: “main”,
“index”: 0
}
]
]
},
“AI Agent”: {
“main”: [
[
{
“node”: “Code”,
“type”: “main”,
“index”: 0
}
]
]
},
“Postgres Chat Memory”: {
“ai_memory”: [
[
{
“node”: “AI Agent”,
“type”: “ai_memory”,
“index”: 0
}
]
]
},
“OpenAI Chat Model”: {
“ai_languageModel”: [
[
{
“node”: “AI Agent”,
“type”: “ai_languageModel”,
“index”: 0
}
]
]
}
},
“pinData”: {},
“meta”: {
“templateCredsSetupCompleted”: true,
“instanceId”: “YOUR_N8N_INSTANCE_ID”
}
}
Share the output returned by the last node
[
{
“first_name”: null,
“last_name”: null,
“email”: null,
“phone_number”: null,
“appointment_date”: null,
“appointment_time”: null,
“updated_time”: null,
“updated_date”: null
}
]
Share the output returned by the last node
Information on your n8n setup
- n8n version:
- Database (default: SQLite):
- n8n EXECUTIONS_PROCESS setting (default: own, main):
- Running n8n via (Docker, npm, n8n cloud, desktop app):
- Operating system:

