Why is the AI Agent in n8n is Extremely Slow When Processing Data?

I am using the AI Agent in n8n to analyze and categorize error data, but the execution time is significantly slow. Sometimes, it takes over 2 minutes to process a relatively small dataset of 5-10 entries, which feels excessive.

I expected a much faster response time (ideally under 20 seconds), given that the dataset is small. Even after trying different batch sizes, the AI Agent still runs slowly.

Below is a fake dataset (not my real data) that mimics my use case and workflow:

Input:

[
  {
    "title": "Printed Brochures",
    "data": [
      {
        "id": "error-abc123",
        "job": "job-111111",
        "comment": "Brochures arrived with torn pages."
      },
      {
        "id": "error-def456",
        "job": "job-222222",
        "comment": "Pages were printed in the wrong order."
      },
      {
        "id": "error-ghi789",
        "job": "job-333333",
        "comment": "The brochure cover was printed in the wrong color."
      }
    ]
  },
  {
    "title": "Flyers",
    "data": [
      {
        "id": "error-jkl987",
        "job": "job-444444",
        "comment": "Flyers were misaligned during printing."
      },
      {
        "id": "error-mno654",
        "job": "job-555555",
        "comment": "Flyers were cut incorrectly, leaving uneven edges."
      },
      {
        "id": "error-pqr321",
        "job": "job-666666",
        "comment": "The wrong font was used in the printed text."
      }
    ]
  }
]

Output:

[
  {
    "title": "Printed Brochures",
    "errors": [
      {
        "errorType": "Physical Damage",
        "summary": "Brochures arrived with torn or damaged pages.",
        "job": ["job-111111"],
        "error": ["error-abc123"]
      },
      {
        "errorType": "Print Order Issue",
        "summary": "Pages were printed in an incorrect sequence.",
        "job": ["job-222222"],
        "error": ["error-def456"]
      },
      {
        "errorType": "Color Mismatch",
        "summary": "The cover was printed in the wrong color.",
        "job": ["job-333333"],
        "error": ["error-ghi789"]
      }
    ]
  },
  {
    "title": "Flyers",
    "errors": [
      {
        "errorType": "Print Alignment Issue",
        "summary": "Flyers were misaligned during the printing process.",
        "job": ["job-444444"],
        "error": ["error-jkl987"]
      },
      {
        "errorType": "Cutting Issue",
        "summary": "Flyers were cut incorrectly, resulting in uneven edges.",
        "job": ["job-555555"],
        "error": ["error-mno654"]
      },
      {
        "errorType": "Font Error",
        "summary": "Incorrect font was used in the printed text.",
        "job": ["job-666666"],
        "error": ["error-pqr321"]
      }
    ]
  }
]

Prompt Used in the AI Agent Node in n8n

You are an advanced data analysis and error categorization AI. Your task is to process input data containing error details grouped by “title”. Each group contains multiple error objects. Your goal is to identify unique error types from the comment field, generate concise summaries for each error type, and include relevant job and error values for those errors.

Input Fields:

  • title: The product group title.
  • data: An array of objects with the following fields:
    • id: Unique identifier for the error.
    • job: ID of the job.
    • comment: Description of the issue.

Objective:

  • Group errors by title.
  • Analyze the comment field to identify unique error types.
  • Generate meaningful summaries for each error type without repeating the comments verbatim.
  • Include all relevant job and error values for each error type.

Output Format:

[
  {
    "title": "ProductGroupTitle",
    "errors": [
      {
        "errorType": "Error Type",
        "summary": "Detailed summary of the issue.",
        "job": ["RelevantJobId1", "RelevantJobId2"],
        "error": ["RelevantErrorId1", "RelevantErrorId2"]
      }
    ]
  }
]

Guidelines:

  • Extract and group data by title.
  • Identify error types from the comment field.
  • Write concise, non-redundant summaries for each error type.
  • Include only relevant job and error values for each error type.
  • Return a clean, well-structured JSON array without additional text.

Input for Analysis: {{ JSON.stringify($input.all()[0].json.data) }}

Information on your n8n setup

  • n8n version: 1.63.4
  • Database (default: SQLite): cloud
  • n8n EXECUTIONS_PROCESS setting (default: own, main): cloud
  • Running n8n via (Docker, npm, n8n cloud, desktop app): cloud
  • Operating system: cloud
2 Likes

It looks like your topic is missing some important information. Could you provide the following if applicable.

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

Also a note, all the steps are fast, except the AI Agent Step.

any luck with this? mine is also very slow.

Mine too actually, dont know what to do :grimacing:

I have exactly the same situation! I connected deepseek and it worked very slowly, then connected openai, but nothing changed and only then I realized that it was not llm that was slowing down, but ai agent itself.

1 Like

There seems to be a huge delay in the LM Callbacks, called before and after the actual LLM is requested. Most of the time is spent inside n8n, not the language model. See this post:

Removing the callbacks actually speed up the thing a lot!

1 Like

Any solution for self hosted?

+1 :frowning:
It’s quite new, I think a couple of weeks, might be related to the runner config (not fully deployed because of the external JS libs required in this setup)

Also struggling with this on self-hosted. First it took 10 seconds to response, now even simple “Hi” takes 30 seconds when I use AI Agent with Deepseek

Same hère using magistral, the api replu fastly but it takes a lot of time with n8n.

devs, we’d be pleased to get an answer or a reply that you are working on this issue

This is basically an issue anyone runs into right with their initial meaningful AI workflow. That’s quite disappointing given all the noise about how n8n provides a path to agentic AI.

For what it’s worth, I tried applying the fix described further above, to a self-hosted Docker instance. I opened a shell in the container

docker exec -it --user root <container-name> /bin/sh

And found the relevant file. In the case of the Mistral AI Agent, it would be

/usr/local/lib/node_modules/n8n/node_modules/.pnpm/@n8n+n8n-nodes-langchain@file+packages+@n8n+nodes-langchain_90fd06b925ebd5b6cf3e2451e17cc4b6/node_modules/@n8n/n8n-nodes-langchain
/dist/nodes/llms/LmChatMistralCloud/LmChatMistralCloud.node.js

(The long number after langchain depends on the container and will be different in each case.)

I changed

callbacks: [new import_N8nLlmTracing.N8nLlmTracing(this)],

into

callbacks: [],

And there is a small positive effect initially (approx. 15 seconds instead of over a minute), but it gets slower with a longer context window, and also depends otherwise on the query. About 40 seconds is still a fairly common timing I am getting.

Also, the main effect of this is that the animation in the workflow window don’t work anymore (e.g., the rotating arrows when the chat node is active, and the counter for the Simple Memory as the context window grows).

Overall not particularly useful.

I found the Mistral node to be among the slowest, and the Open AI node slightly faster (but still >10 seconds typically). Groq is the fastest at about 5-6 seconds (without any code change), but only makes available certain open models, esp. Llama, DeepSeek and Qwen.

1 Like

Hey everyone,

If you’re finding the AI Agent slow, the issue is likely the LlmTracing callbacks.

I’ve built a custom Docker image that removes them, which made my workflows much faster. You can try it if you’re using Docker:

blackpc/n8n:1.99.0-no-llm-tracing

Please note, this is an unofficial community fix and should be used as a temporary workaround. Hope it helps!

3 Likes

hi, i had the same issue but i found this solution which worked well, before adding those variables, my ai agent node took 22 sec to execute, now it takes only 2 to 3 secs.
here the link Significant performance delay with AI Agent / Ollama Node on Windows compared to direct API calls or Open WebUI · Issue #15263 · n8n-io/n8n · GitHub,
here the variables i add:
N8N_RUNNERS_ENABLED=true
N8N_DIAGNOSTICS_ENABLED=false
N8N_VERSION_NOTIFICATIONS_ENABLED=false
EXTERNAL_FRONTEND_HOOKS_URLS=

1 Like

Does this solution work for n8n cloud? How do I accomplish this on the cloud version of n8n?

Hi, thank you so much for sharing the container with us — it’s been really helpful and we truly appreciate your time and effort.
Could you guide us on how we might adapt it for more recent versions?
Or do you plan to update the container in the future?

I have the same question, what did you actually change then I can follow in recent version? Thanks!

Check out here feat: remove N8nLlmTracing callbacks · blackpc/n8n@d5dc22b · GitHub