What is the best pattern for waiting on long-running agent workflows

Describe the problem/error/question

I have a main workflow that triggers multiple sub-workflows that running in parallel , and each agent needs to send a long prompt to an external LLM that’s wrapped in an MCP tool.

**The Challenge:**

- Each MCP call has a 60-second timeout

- The LLM processing takes longer than 60 seconds

- I need the main workflow to wait for all sub-agents to complete before continuing

- Currently, the MCP timeout causes the workflow to fail

**What I’m trying to achieve:**

1. Main workflow triggers several sub-agent workflows

2. Each sub-agent sends a prompt to an external LLM via MCP

3. Wait for all agents to complete (even if they take several minutes)

4. Continue main workflow with all results

**Potential solutions I’m considering:**

- Async callback pattern (immediate response + callback when done)

- Status polling with a loop

- Webhook-based completion notifications

Has anyone successfully implemented long-running MCP calls or agent workflows in n8n?

What’s the best approach to handle timeouts with external LLM services?

what is the best way to trigger few sub workflows in parallel? and collect them after finish?

Any guidance on the recommended pattern for this use case would be greatly appreciated!

main

option 1: sub workflow per task

option 2: sub workflow with n8n Workflow Tool

tool:

Callback Coordinator - to collect all tasks:

Information on your n8n setup

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

The 60-second timeout should be configurable in the MCP tool nodes under ‘options’.

To wait for all calls to finish before continuing you can put them on separate branches and then merge the branches at the end using a ‘merge’ node. Note however that branches in n8n are executed sequentially so you won’t get any parallelisation.

but I dont know how many tasks will be run in parallel, its generic and depends the user

I need 2 things:

  1. best way to run multiple sub-workflows in parallel

  2. best way to run a long process, maybe return immediately taskId and then poll the status with wait until complete? I’m search for something better if you know…

main workflow that trigger sub workflows:

sub workflow that using mcp get the taskID and then loop until finish

What about:

  1. Launch sub-workflows with “wait for completion” DISABLED, pass jobId + workerIndex to each
  2. Add Wait node (“On Webhook Call”)

You also can store job id, worker index and status in db for state management (n8n tables/postgres/supabase/mongodb/ainoflow/etc).
You might need aggergator workflow, which will collect all responses and call resume url once to resume main workflow.

Thanks for your answer,

  • regarding the parallel tasks I collect them with Callback Coordinator workflow that resume the main workflow when all task finished

There is a better way to know when all the tasks completed?

  • Reg the long process I tried something like this:
    sub workflow with n8n Workflow Tool that response auto when complete

Tool - Poll Task Until Complete

but it is also using wait node, maybe there is a way without “wait”?

or this is the recommendation solution for long process case?

Another option to solve the long process is by callback when the long process is completed

sub agent call the mcp (long process)

callback from the mcp when done:

n8n guys, What is the recommendation solution?

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.