Skip to main content

Automate Document Q&A with Multi-Agent RAG Orchestration using Contextual AI & Gemini

Workflow preview

Workflow preview
100%
Automate Document Q&A with Multi-Agent RAG Orchestration using Contextual AI & Gemini preview
Open on n8n.io

Important notice

This workflow is provided as-is. Please review and test before using in production.

1. Workflow Overview

PROBLEM Managing multiple RAG AI agents can be complex when each has its own purpose and vector database. Manually tracking agents and deciding which one to query wastes time. LLMs often struggle t...

Best for

  • Internal Wiki automation workflows
  • AI RAG automation workflows
  • advanced n8n builders looking for reusable templates

Tools used

n8n-nodes-contextualai.contextualai, n8n-nodes-base.formtrigger, n8n-nodes-base.code, @n8n/n8n-nodes-langchain.agent, @n8n/n8n-nodes-langchain.chattrigger, @n8n/n8n-nodes-langchain.lmchatgooglegemini, @n8n/n8n-nodes-langchain.memorybufferwindow, n8n-nodes-contextualai.contextualaitool

Source and attribution

This workflow is cataloged by N8N Workflows and links back to its original n8n.io source page by Jinash Rouniyar.

Original n8n.io source

1.1 Workflow description

Title
Automate Document Q&A with Multi-Agent RAG Orchestration using Contextual AI & Gemini
Workflow name
Automate Document Q&A with Multi-Agent RAG Orchestration using Contextual AI & Gemini

PROBLEM

Managing multiple RAG AI agents can be complex when each has its own purpose and vector database.

  • Manually tracking agents and deciding which one to query wastes time.
  • LLMs often struggle to determine which agent best fits a user’s request.

This workflow enables automated multi-agent orchestration, dynamically selecting and querying the correct agent using Contextual AI Query Tool and Gemini 2.5 Flash.

How it works

  • A form trigger allows users to create new agents by specifying a name, description, datastore, and uploading files.
  • A new agent is created with the provided information and files are ingested in the datastore
  • We get the status of file ingestion every 30 seconds until the ingestion process is complete
  • When users send queries, the Agent Orchestrator identifies the most relevant agent to generate grounded, context-aware responses.

Note: The document ingestion process is asynchronous and may take a few minutes before your agent has the document fully available in the datastore for querying.

How to set up

  • Create a free Contextual AI account and obtain your CONTEXTUALAI_API_KEY.
  • Add CONTEXTUALAI_API_KEY as an environment variable in n8n.
  • For the baseline model, we have used Gemini 2.5 Flash Model, you can find your Gemini API key here

How to customize the workflow

  • Replace the Form Trigger with a Webhook Trigger or manual input to integrate with custom systems.
  • Swap Gemini 2.5 Flash with another LLM provider
  • Update the wait time as per user requirement
  • Modify the system prompt to fine-tune how the orchestration logic selects and queries agents.
  • You can check out this Contextual AI API reference for more details on agent creation and usage.
  • If you have feedback or need support, please email [email protected].

1.2 Logical Blocks

This catalog entry is organized from the workflow JSON. The node-level section below shows the executable blocks available for review before importing the template.

2. Block-by-Block Analysis

Block 1 - Create Agent

Type / Role
n8n-nodes-contextualai.contextualAi - contextualAi
Config choices
Version 1

Block 2 - Submit Agent Information

Type / Role
n8n-nodes-base.formTrigger - formTrigger
Config choices
Version 2.3

Block 3 - Preprocessing Step

Type / Role
n8n-nodes-base.code - code
Config choices
Version 2

Block 4 - Agent Orchestrator

Type / Role
@n8n/n8n-nodes-langchain.agent - agent
Config choices
Version 2.2

Block 5 - Chat

Type / Role
@n8n/n8n-nodes-langchain.chatTrigger - chatTrigger
Config choices
Version 1.3

Block 6 - Google Gemini Chat Model

Type / Role
@n8n/n8n-nodes-langchain.lmChatGoogleGemini - lmChatGoogleGemini
Config choices
Version 1

Block 7 - Simple Memory

Type / Role
@n8n/n8n-nodes-langchain.memoryBufferWindow - memoryBufferWindow
Config choices
Version 1.3

Block 8 - Query Agent Tool

Type / Role
n8n-nodes-contextualai.contextualAiTool - contextualAiTool
Config choices
Version 1

Block 9 - List Agents Tool

Type / Role
n8n-nodes-contextualai.contextualAiTool - contextualAiTool
Config choices
Version 1

Block 10 - Sticky Note

Type / Role
n8n-nodes-base.stickyNote - stickyNote
Config choices
Version 1

Block 11 - Sticky Note1

Type / Role
n8n-nodes-base.stickyNote - stickyNote
Config choices
Version 1

Block 12 - Sticky Note2

Type / Role
n8n-nodes-base.stickyNote - stickyNote
Config choices
Version 1

Block 13 - Split Out

Type / Role
n8n-nodes-base.splitOut - splitOut
Config choices
Version 1

Block 14 - Wait

Type / Role
n8n-nodes-base.wait - wait
Config choices
Version 1.1

Block 15 - If

Type / Role
n8n-nodes-base.if - if
Config choices
Version 2.2

Block 16 - Iterate over each files

Type / Role
n8n-nodes-base.splitInBatches - splitInBatches
Config choices
Version 3

Block 17 - Get Document Ingestion Status

Type / Role
n8n-nodes-contextualai.contextualAi - contextualAi
Config choices
Version 1

3. Summary Table

Workflow Automate Document Q&A with Multi-Agent RAG Orchestration using Contextual AI & Gemini
Complexity advanced
Nodes 17
Categories Internal Wiki, AI RAG
Author Jinash Rouniyar
Published 09 Dec 2025

4. Reproducing the Workflow from Scratch

  1. 1. Download the workflow JSON

    Use the JSON export at /data/workflows/11619/11619.json as the source template for this automation.

  2. 2. Import the template into n8n

    Open n8n, import the downloaded JSON, and review each node before activating the workflow.

  3. 3. Configure credentials and variables

    Replace placeholder credentials, API keys, webhook URLs, account IDs, and environment-specific values with your own settings.

  4. 4. Test with sample data

    Run the workflow manually or in a staging workspace, inspect node output, and confirm downstream systems receive the expected data.

  5. 5. Activate and monitor

    Enable the workflow only after testing, then monitor executions, errors, and rate limits during the first production runs.

5. General Notes & Resources

Review imported nodes carefully before activation. This catalog entry is intended to help you inspect the workflow structure, understand required services, and find related templates faster.

Node names, credentials, schedules, webhook paths, and external service limits may need adjustment for your workspace.

Frequently asked questions

What does Automate Document Q&A with Multi-Agent RAG Orchestration using Contextual AI & Gemini do?

PROBLEM Managing multiple RAG AI agents can be complex when each has its own purpose and vector database. Manually tracking agents and deciding which one to query wastes time. LLMs often struggle t...

What do I need before importing this workflow?

Review the workflow JSON, configure any required credentials in n8n, and test the automation in a safe workspace before using it in production.

Can I customize this workflow?

Yes. Use the block-by-block analysis and the downloadable JSON to inspect each node, then adjust credentials, prompts, schedules, filters, or destinations for your Internal Wiki, AI RAG use case.