Variables Become Undefined when an HTTP Request Node is triggered

Describe the problem/error/question

I’ve built a missed call text back agent. To explain the logic, the idea is a missed call comes in, it triggers the workflow. There is a variable initialization. Then a conditional statement (if body is empty or not – ie. whether a call was missed or whether someone is texting the agent). So there’s two agents, one to handle the initial missed call and send a text, then any ongoing conversations go to the second texting agent. From there it’s a standard Agent, that can send emails and has an http request connected to Pinecone to be able to access the business details.

The issue I’m having is when a text comes that triggers the HTTP pinecone RAG node, variables become undefined all of a sudden. This happens in the memory ID key, as well as downstream “to” and “from” Variables in the twilio node. So something in the flow gets messed up when the http request is executed. Otherwise, it works as intended, and variables stay connected and defined.

Would greatly appreciate some help/insight. Thanks in advance.

What is the error message (if any)?

Please share your workflow

Share the output returned by the last node

This was the output from the HTTP Request - RAG Node. The question was “Tell me about the business”.

{
“finish_reason”: “stop”,
“message”: {
“role”: “assistant”,
“content”: “Ryhno is a company that provides AI-powered communication and automation tools designed for small and medium-sized businesses. Their services aim to help businesses capture more leads, book more appointments, and eliminate repetitive tasks using AI. Ryhno specializes in missed call text-back services, AI receptionist solutions, and custom AI automations. The company’s goal is to ensure businesses never miss an opportunity by addressing common issues such as missed calls, slow responses, and lost leads to competitors.\n\nRyhno’s products include:\n1. Missed Call Text-Back: This service automatically sends a personalized SMS whenever a business misses a phone call. It starts a conversation, captures caller details, books appointments or quotes, and routes leads to the appropriate person. It works with existing business phone numbers and offers instant lead responses without losing calls.\n2. AI Receptionist: A 24/7 AI-powered phone receptionist that can answer calls, greet callers professionally, understand their needs, transfer calls, book appointments, send follow-up texts, take messages, and block spam calls. It functions as either a full-time receptionist or a backup when staff are unavailable.\n3. Custom AI Automations: Ryhno builds tailored AI systems to automate repetitive tasks such as lead handling, CRM updates, appointment scheduling, follow-ups, quote requests, data entry, internal notifications, and workflow automation. These solutions are custom-built based on the specific needs of each business.\n\nRyhno positions itself as a revenue capture system that helps businesses stop missed leads, increase conversion rates, reduce staffing costs, and automate operations. It is particularly suited for businesses that rely heavily on phone calls, leads, or bookings, such as home service businesses, contractors, trades, clinics, realtors, and professional services.”
},
“id”: “0000000000000000756ec9e89ba5a79e”,
“model”: “gpt-4o-2024-11-20”,
“usage”: {
“prompt_tokens”: 1786,
“completion_tokens”: 368,
“total_tokens”: 2154
},
“citations”: [
{
“position”: 521,
“references”: [
{
“file”: {
“status”: “Available”,
“id”: “021ad4cd-cdd8-4d29-9c92-4231dc4352ef”,
“name”: “RYHNO KNOWLEDGE BASE.pdf”,
“size”: 105763,
“metadata”: null,
“updated_on”: “2026-01-13T03:31:02.388403317Z”,
“created_on”: “2026-01-13T03:30:58.740200316Z”,
“percent_done”: 1,
“signed_url”: “https://storage.googleapis.com/knowledge-prod-files/5068adfe-9d98-4acd-9ee8-160e82f0031e%2Fb59e1e74-593a-48c7-a339-69daa4e16960%2F021ad4cd-cdd8-4d29-9c92-4231dc4352ef.pdf?X-Goog-Algorithm=GOOG4-RSA-SHA256&X-Goog-Credential=ke-prod-1%40pc-knowledge-prod.iam.gserviceaccount.com%2F20260116%2Fauto%2Fstorage%2Fgoog4_request&X-Goog-Date=20260116T031819Z&X-Goog-Expires=3600&X-Goog-SignedHeaders=host&response-content-disposition=inline&response-content-type=application%2Fpdf&X-Goog-Signature=a957b030a84f28df7c3b94f47c6da8c3eddfba750608272985ff8bfc6124fbc721198169f2e5f308877ae51ddaa05e9fc5cf67e010b161b398d7cbdc7d82a92c119b2a73cec3f2b4f40a747dec7f84a98dc4882ee3af7fcec5679a20fadd2484d6aa2c0163bfdc6aaaf1b5c374690122860d31c51d97754b14a2d6a71915032ebfba379001a3dd783b7a6b286bffae052a9238ae67787a2291cd2b3d30353a024c5a778460cf3899f344bcaf236ca8581842756c8ce02b484e3ee2391b913bcf960173a5c867892c30df0d56eccab5683be118fc5e5481bea4dc5dc06e57a6f3428e95a072e41e9f808ec0beb71a7086c338cc8973dc5ffdc5ce8c4a63f1d788”,
“error_message”: null,
“multimodal”: false
},
“pages”: [
1,
2,
3,
4,
5
],
“highlight”: null
}
]
}
]
}

Information on your n8n setup

  • n8n version: 2.2.6
  • Database (default: SQLite): SQ Lite
  • n8n EXECUTIONS_PROCESS setting (default: own, main):
  • Running n8n via (Docker, npm, n8n cloud, desktop app): n8n cloud
  • Operating system: MAC

Side note: I did notice that I’m missing the Open AI node in my text model. I forgot to paste it, but its in my workflow as shown in the snip above it.

hello @jererocks

Actually, it looks fine. Try replacing .item.json with .last().json

Hi, thanks for sharing the workflow and details — this is a good example of a structural context issue, not a Twilio or Pinecone problem.

:magnifying_glass_tilted_left: What’s actually happening

The root cause is context loss after the RAG (HTTP-based) node.

In n8n, every node passes data as items, and most nodes (including HTTP / RAG / Agent tools) replace the $json root with their own output.

In your case:

  1. Before RAG

    • $json contains Twilio fields (from, to, body, etc.)

    • These values are used for:

      • memoryId

      • Twilio to / from

      • Conversation session keys

  2. RAG / HTTP node

    • Returns a new payload (message, usage, citations, etc.)

    • This replaces the original $json

    • Twilio fields are no longer present in the active item

  3. After RAG

    • Downstream nodes still reference $json.from, $json.to, $json.memoryId

    • Those fields no longer exist, so they become undefined

This explains why:

  • The workflow works until the RAG node runs

  • Variables suddenly break only when the HTTP/RAG node is triggered


:warning: Why this feels “random”

It’s not random — it depends on which execution path replaces the item.

Your If + Agent + RAG combination means:

  • Some paths preserve the original payload

  • Other paths overwrite it completely

That makes the workflow non-deterministic from a data perspective.


:hammer_and_wrench: Production-grade fix (not a workaround)

The key principle is:

Do not rely on $json for long-lived context.

Recommended pattern:

  1. Persist critical context early

    • Store from, to, memoryId, session keys in:

      • Workflow static data, or

      • A dedicated Set node that you always merge back

  2. Treat RAG / HTTP nodes as isolated

    • Assume they will:

      • Replace $json

      • Change item shape

      • Drop unrelated fields

  3. Re-attach context explicitly

    • After RAG, merge the original context back into the item

    • Never assume $json survives across Agent / HTTP boundaries

  4. One responsibility per node

    • Context handling

    • External calls

    • Messaging output
      should be clearly separated


:white_check_mark: Summary

  • This is expected n8n behavior

  • The issue is context replacement, not credentials or Twilio

  • The fix is structural context management, not retrying or re-authenticating

Once you treat RAG / Agent nodes as context-breaking boundaries, the workflow becomes stable.

Hope this helps — happy to clarify further if needed :+1: