From f46932f44acf91854a354a3ece3b90ce4db97862 Mon Sep 17 00:00:00 2001 From: nusquama Date: Thu, 13 Nov 2025 14:21:34 +0100 Subject: [PATCH] creation --- .../readme-3527.md | 563 ++++++++++++++++++ 1 file changed, 563 insertions(+) create mode 100644 workflows/Compare Sequential, Agent-Based, and Parallel LLM Processing with Claude 3.7-3527/readme-3527.md diff --git a/workflows/Compare Sequential, Agent-Based, and Parallel LLM Processing with Claude 3.7-3527/readme-3527.md b/workflows/Compare Sequential, Agent-Based, and Parallel LLM Processing with Claude 3.7-3527/readme-3527.md new file mode 100644 index 000000000..19e84367b --- /dev/null +++ b/workflows/Compare Sequential, Agent-Based, and Parallel LLM Processing with Claude 3.7-3527/readme-3527.md @@ -0,0 +1,563 @@ +Compare Sequential, Agent-Based, and Parallel LLM Processing with Claude 3.7 + +https://n8nworkflows.xyz/workflows/compare-sequential--agent-based--and-parallel-llm-processing-with-claude-3-7-3527 + + +# Compare Sequential, Agent-Based, and Parallel LLM Processing with Claude 3.7 + +### 1. Workflow Overview + +This workflow titled **"Compare Sequential, Agent-Based, and Parallel LLM Processing with Claude 3.7"** demonstrates three distinct architectural approaches to chaining large language model (LLM) operations using the Anthropic Claude 3.7 Sonnet model. It is designed for users to compare the trade-offs between simplicity, speed, and context management when building AI workflows with n8n. + +The workflow is logically divided into three main blocks reflecting different LLM chaining strategies: + +- **1.1 Naive Sequential Chaining**: A straightforward, beginner-friendly approach where multiple LLM nodes are connected in a direct sequence, each processing the output of the previous. This method is easy to set up but inefficient and slow for longer chains. + +- **1.2 Agent-Based Processing with Memory**: Uses a single AI Agent node that processes multiple instructions iteratively while maintaining conversation history (memory). This approach improves context management and scalability but remains slower than parallel processing. + +- **1.3 Parallel Processing for Maximum Speed**: Splits prompts into independent requests processed simultaneously via HTTP webhook calls. This method maximizes speed but lacks shared context or agent memory. + +Supporting these main blocks are auxiliary nodes for data fetching, prompt preparation, memory management, and result merging. + +--- + +### 2. Block-by-Block Analysis + +--- + +#### 1.1 Naive Sequential Chaining + +**Overview:** +This block demonstrates the simplest method of chaining LLM calls by connecting multiple LLM nodes sequentially. Each node receives the same page content and a distinct prompt, producing stepwise outputs. + +**Nodes Involved:** +- When clicking ‘Test workflow’ (Manual Trigger) +- HTTP Request +- Markdown +- Anthropic Chat Model (4 instances) +- LLM Chain - Step 1 to Step 4 +- Merge output with initial prompts1 +- Sticky Note3 (comment) + +**Node Details:** + +- **When clicking ‘Test workflow’** + - Type: Manual Trigger + - Role: Initiates the workflow manually for testing + - Inputs: None + - Outputs: HTTP Request node + - Edge cases: None significant; manual trigger requires user action + +- **HTTP Request** + - Type: HTTP Request + - Role: Fetches content from https://blog.n8n.io/ (default test data) + - Configuration: Simple GET request, no auth or special headers + - Inputs: Manual Trigger + - Outputs: Markdown node + - Edge cases: Network errors, HTTP failures, content format changes + +- **Markdown** + - Type: Markdown + - Role: Converts fetched HTML content to markdown format stored in `markdown` key + - Configuration: Uses expression `={{ $json.data }}` to process HTTP response + - Inputs: HTTP Request + - Outputs: Anthropic Chat Model nodes (via LLM Chain nodes) + - Edge cases: Empty or malformed HTML input + +- **Anthropic Chat Model (4 instances)** + - Type: Anthropic Chat Model (Claude 3.7 Sonnet) + - Role: Executes individual LLM calls for each step with specific prompts + - Configuration: Model set to "claude-3-7-sonnet-20250219", temperature 0.5 + - Inputs: Corresponding LLM Chain nodes (Step 1 to Step 4) + - Outputs: Next LLM Chain node or Merge node + - Credentials: Anthropic API key required + - Edge cases: API errors, rate limits, timeout, invalid prompts + +- **LLM Chain - Step 1 to Step 4** + - Type: Chain LLM + - Role: Wraps Anthropic Chat Model calls with prompt text and message formatting + - Configuration: Each node uses the markdown content as input text and a fixed prompt message (e.g., "What is on this page?") + - Inputs: Previous LLM Chain node (except Step 1 which connects to Anthropic Chat Model) + - Outputs: Next LLM Chain node or Merge node + - Edge cases: Expression failures if markdown missing, API errors + +- **Merge output with initial prompts1** + - Type: Merge + - Role: Combines outputs from sequential LLM steps with initial prompts for comparison or display + - Configuration: Combine mode by position, includes unpaired data + - Inputs: All LLM steps here - sequentially, LLM Chain - Step 4 + - Outputs: Final combined dataset + - Edge cases: Mismatched array lengths + +- **Sticky Note3** + - Content: + ``` + # 1 - Naive Chaining + ### PROs: + - Easy to setup + - Beginner-friendly + + ### CONs + - Not scalable + - Hard to maintain long chains + - SLOOOW! + ``` + - Role: Provides user guidance on this block’s pros and cons + +--- + +#### 1.2 Agent-Based Processing with Memory + +**Overview:** +This block processes multiple instructions through a single AI Agent node that maintains conversation history (memory). It offers better context handling and scalability compared to naive chaining, but still processes instructions sequentially. + +**Nodes Involved:** +- Clean memory +- Initial prompts +- Reshape +- Split Out +- Merge +- Simple Memory +- Anthropic Chat Model4 +- All LLM steps here - sequentially (Agent node) +- Merge output with initial prompts1 +- Sticky Note4 +- Sticky Note1 +- Sticky Note6 + +**Node Details:** + +- **Clean memory** + - Type: Memory Manager + - Role: Deletes all previous memory to start fresh session + - Configuration: Mode set to "delete all" + - Inputs: CONNECT ME1 (NoOp) + - Outputs: Initial prompts + - Edge cases: Memory deletion failures or stale data + +- **Initial prompts** + - Type: Set + - Role: Defines system prompt and multiple step instructions as separate variables + - Configuration: + - system_prompt: "You are a helpful assistant" + - step1: "What is on this page?" + - step2: "List all authors on this page" + - step3: "List all posts on this page" + - step4: "Make a bold funny joke based on the content on this page" + - Inputs: Clean memory + - Outputs: Reshape + - Edge cases: Variable assignment errors + +- **Reshape** + - Type: Set + - Role: Converts step instructions into an array of objects with keys `step` and `instruction` while preserving system_prompt + - Configuration: Uses JavaScript expression to filter and map keys except system_prompt + - Inputs: Initial prompts + - Outputs: Split Out + - Edge cases: Expression failures if input malformed + +- **Split Out** + - Type: Split Out + - Role: Splits the array of instructions into individual items for processing + - Configuration: Splits on `data` field, includes `system_prompt` in each output + - Inputs: Reshape + - Outputs: Merge (via Anthropic Chat Model4 and Agent node) + - Edge cases: Empty array input + +- **Merge** + - Type: Merge + - Role: Combines individual LLM outputs back into a single dataset + - Configuration: Combine mode by position, includes unpaired data + - Inputs: Split Out outputs and Agent node outputs + - Outputs: Merge output with initial prompts1 + - Edge cases: Mismatched output lengths + +- **Simple Memory** + - Type: Memory Buffer Window + - Role: Maintains a sliding window of conversation history with a fixed session key + - Configuration: + - sessionKey: "fixed_session" + - contextWindowLength: 10 + - Inputs: All LLM steps here - sequentially (Agent node) and Clean memory (to clear memory) + - Outputs: All LLM steps here - sequentially + - Edge cases: Memory overflow or corruption + +- **Anthropic Chat Model4** + - Type: Anthropic Chat Model + - Role: Provides LLM processing for the Agent node + - Configuration: Model "claude-3-7-sonnet-20250219", temperature 0.5, thinking disabled + - Inputs: Agent node + - Outputs: Agent node + - Credentials: Anthropic API key + - Edge cases: API errors, rate limits + +- **All LLM steps here - sequentially** + - Type: Agent + - Role: Processes each instruction with memory support, using system prompt and instruction text + - Configuration: + - Text: Combines markdown content and instruction dynamically + - System message: Uses system_prompt from input + - Inputs: Simple Memory (memory), Split Out (instructions) + - Outputs: Merge output with initial prompts1 + - Edge cases: Agent memory failures, API errors + +- **Merge output with initial prompts1** + - Type: Merge + - Role: Combines Agent outputs with initial prompts for final display + - Inputs: Agent node and Merge node + - Outputs: None (end of block) + - Edge cases: Data mismatch + +- **Sticky Note4** + - Content: + ``` + # 2 - Iterative Agent Processing + + ### PROs: + - Scalable + - All inputs & outputs in a single node + - Supports Agent memory + + ### CONs + - Still Slow! + ``` + - Role: Describes benefits and drawbacks of this approach + +- **Sticky Note1** + - Content: "# An array of prompts here" + - Role: Indicates where the prompt array is defined + +- **Sticky Note6** + - Content: "# Array of prompts here" + - Role: Highlights prompt array usage near Anthropic Chat Model4 + +--- + +#### 1.3 Parallel Processing for Maximum Speed + +**Overview:** +This block splits prompts into independent requests processed in parallel via HTTP webhook calls to the same workflow. This maximizes speed but does not share memory or context between requests. + +**Nodes Involved:** +- Initial prompts1 +- Split Out1 +- Merge2 +- LLM steps - parallel (HTTP Request) +- Webhook +- Basic LLM Chain4 +- Anthropic Chat Model5 +- Merge output with initial prompts +- Sticky Note5 +- Sticky Note2 + +**Node Details:** + +- **Initial prompts1** + - Type: Set + - Role: Defines an array variable `userprompt` with multiple prompt strings + - Configuration: + - userprompt: Array of 4 prompts identical to previous blocks + - Inputs: CONNECT ME2 (NoOp) + - Outputs: Split Out1 + - Edge cases: Empty or malformed array + +- **Split Out1** + - Type: Split Out + - Role: Splits the array of user prompts into individual messages for parallel processing + - Configuration: Splits on `userprompt` field + - Inputs: Initial prompts1 + - Outputs: Merge2 + - Edge cases: Empty input array + +- **Merge2** + - Type: Merge + - Role: Combines parallel HTTP Request outputs back into a single dataset + - Configuration: Combine mode "combineAll" (all inputs combined) + - Inputs: Split Out1 and LLM steps - parallel + - Outputs: Merge output with initial prompts + - Edge cases: Mismatched response counts + +- **LLM steps - parallel** + - Type: HTTP Request + - Role: Sends each prompt in parallel as a POST request to the workflow webhook URL + - Configuration: + - URL: `{{ $env.WEBHOOK_URL }}webhook/58d2b899-e09c-45bf-b59b-961a5d7a2470` (must be replaced with actual n8n instance URL for cloud users) + - Method: POST + - Body: JSON, sends the prompt data as-is + - Inputs: Merge2 (from Split Out1) + - Outputs: Merge2 (for combining results) + - Edge cases: Network errors, webhook not reachable, invalid URL, rate limits + +- **Webhook** + - Type: Webhook + - Role: Receives parallel POST requests and triggers processing of each prompt + - Configuration: + - Path: "58d2b899-e09c-45bf-b59b-961a5d7a2470" + - Method: POST + - Response mode: last node output + - Inputs: External HTTP POST requests (from LLM steps - parallel) + - Outputs: Basic LLM Chain4 + - Edge cases: Invalid requests, concurrency issues + +- **Basic LLM Chain4** + - Type: Chain LLM + - Role: Processes each prompt with the page markdown content, formatting prompt and context + - Configuration: + - Text: Combines user prompt and page markdown content dynamically + - Inputs: Webhook + - Outputs: Anthropic Chat Model5 + - Edge cases: Missing markdown content, expression errors + +- **Anthropic Chat Model5** + - Type: Anthropic Chat Model + - Role: Executes the LLM call for each parallel prompt + - Configuration: Model "claude-3-7-sonnet-20250219", temperature 0.5 + - Inputs: Basic LLM Chain4 + - Outputs: Webhook response + - Credentials: Anthropic API key + - Edge cases: API errors, rate limits + +- **Merge output with initial prompts** + - Type: Merge + - Role: Combines parallel LLM outputs with initial prompts for final display + - Inputs: LLM steps - parallel and Merge2 + - Outputs: None (end of block) + - Edge cases: Data mismatch + +- **Sticky Note5** + - Content: + ``` + # 3 - Parallel Processing + + ### PROs: + - Scalable + - All inputs & outputs in a single place + - FAST! + + ### CONs + - Independent requests + (no Agent memory) + ``` + - Role: Explains pros and cons of parallel processing + +- **Sticky Note2** + - Content: + ``` + ## Make sure URL matches + ### ⚠️ Cloud users! + Replace `{{ $env.WEBHOOK_URL }}` + with your n8n instance URL + ``` + - Role: Important deployment instruction for cloud users + +--- + +### 3. Summary Table + +| Node Name | Node Type | Functional Role | Input Node(s) | Output Node(s) | Sticky Note | +|-------------------------------|----------------------------------|----------------------------------------|----------------------------------|-----------------------------------|-------------------------------------------------------------------------------------------------| +| When clicking ‘Test workflow’ | Manual Trigger | Starts workflow manually | None | HTTP Request | | +| HTTP Request | HTTP Request | Fetches n8n blog HTML content | When clicking ‘Test workflow’ | Markdown | | +| Markdown | Markdown | Converts HTML to markdown | HTTP Request | LLM Chain - Step 1, Step 2, Step 3, Step 4 | | +| LLM Chain - Step 1 | Chain LLM | Runs first LLM prompt | Anthropic Chat Model | LLM Chain - Step 2 | | +| LLM Chain - Step 2 | Chain LLM | Runs second LLM prompt | LLM Chain - Step 1 | LLM Chain - Step 3 | | +| LLM Chain - Step 3 | Chain LLM | Runs third LLM prompt | LLM Chain - Step 2 | LLM Chain - Step 4 | | +| LLM Chain - Step 4 | Chain LLM | Runs fourth LLM prompt | LLM Chain - Step 3 | Merge output with initial prompts1 | | +| Anthropic Chat Model (x4) | Anthropic Chat Model | Executes LLM calls for steps 1-4 | Corresponding LLM Chain nodes | Next LLM Chain or Agent node | | +| Merge output with initial prompts1 | Merge | Combines sequential LLM outputs | All LLM steps here - sequentially, LLM Chain - Step 4 | None | | +| Sticky Note3 | Sticky Note | Notes pros and cons of naive chaining | None | None | # 1 - Naive Chaining; PROs: Easy setup, Beginner-friendly; CONs: Not scalable, Slow | +| Clean memory | Memory Manager | Clears AI memory before agent processing | CONNECT ME1 | Initial prompts | | +| Initial prompts | Set | Defines system prompt and step instructions | Clean memory | Reshape | | +| Reshape | Set | Converts step instructions to array | Initial prompts | Split Out | | +| Split Out | Split Out | Splits instructions array into items | Reshape | Merge, Anthropic Chat Model4 | | +| Merge | Merge | Combines agent outputs | Split Out, Agent node | Merge output with initial prompts1 | | +| Simple Memory | Memory Buffer Window | Maintains conversation history | All LLM steps here - sequentially, Clean memory | All LLM steps here - sequentially | | +| Anthropic Chat Model4 | Anthropic Chat Model | LLM model for agent processing | All LLM steps here - sequentially | All LLM steps here - sequentially | | +| All LLM steps here - sequentially | Agent | Processes instructions with memory | Simple Memory, Split Out | Merge output with initial prompts1 | | +| Sticky Note4 | Sticky Note | Notes pros and cons of agent processing | None | None | # 2 - Iterative Agent Processing; PROs: Scalable, Supports memory; CONs: Still slow | +| Sticky Note1 | Sticky Note | Indicates array of prompts | None | None | # An array of prompts here | +| Sticky Note6 | Sticky Note | Highlights prompt array usage | None | None | # Array of prompts here | +| Initial prompts1 | Set | Defines array of user prompts for parallel | CONNECT ME2 | Split Out1 | | +| Split Out1 | Split Out | Splits user prompts array for parallel processing | Initial prompts1 | Merge2 | | +| Merge2 | Merge | Combines parallel HTTP request outputs | Split Out1, LLM steps - parallel | Merge output with initial prompts | | +| LLM steps - parallel | HTTP Request | Sends parallel POST requests to webhook | Merge2 | Merge2 | ## Make sure URL matches; ⚠️ Cloud users! Replace `{{ $env.WEBHOOK_URL }}` with your n8n URL | +| Webhook | Webhook | Receives parallel requests and triggers processing | External HTTP POST | Basic LLM Chain4 | | +| Basic LLM Chain4 | Chain LLM | Processes each prompt with markdown content | Webhook | Anthropic Chat Model5 | | +| Anthropic Chat Model5 | Anthropic Chat Model | Executes LLM call for each parallel prompt | Basic LLM Chain4 | Webhook response | | +| Merge output with initial prompts | Merge | Combines parallel outputs with prompts | LLM steps - parallel, Merge2 | None | | +| Sticky Note5 | Sticky Note | Notes pros and cons of parallel processing | None | None | # 3 - Parallel Processing; PROs: FAST, Scalable; CONs: No Agent memory | +| Sticky Note2 | Sticky Note | Deployment note for cloud users | None | None | ## Make sure URL matches; ⚠️ Cloud users! Replace `{{ $env.WEBHOOK_URL }}` with your n8n URL | +| CONNECT ME | NoOp | Placeholder for connections | None | LLM Chain - Step 1 | | +| CONNECT ME1 | NoOp | Placeholder for connections | None | Clean memory | | +| CONNECT ME2 | NoOp | Placeholder for connections | None | Initial prompts1 | | + +--- + +### 4. Reproducing the Workflow from Scratch + +1. **Create Manual Trigger Node** + - Name: "When clicking ‘Test workflow’" + - Type: Manual Trigger + - No parameters + +2. **Add HTTP Request Node** + - Name: "HTTP Request" + - Type: HTTP Request + - URL: `https://blog.n8n.io/` + - Method: GET + - Connect output of Manual Trigger to this node + +3. **Add Markdown Node** + - Name: "Markdown" + - Type: Markdown + - Input: Use expression `={{ $json.data }}` to convert HTTP response HTML to markdown + - Connect output of HTTP Request to this node + +--- + +#### Naive Sequential Chaining Setup + +4. **Add 4 Anthropic Chat Model Nodes** + - Names: "Anthropic Chat Model", "Anthropic Chat Model1", "Anthropic Chat Model2", "Anthropic Chat Model3" + - Type: Anthropic Chat Model (Langchain) + - Model: "claude-3-7-sonnet-20250219" + - Temperature: 0.5 + - Credentials: Anthropic API key configured in n8n credentials manager + +5. **Add 4 Chain LLM Nodes** + - Names: "LLM Chain - Step 1" to "LLM Chain - Step 4" + - Type: Chain LLM + - For each node: + - Text parameter: `={{ $('Markdown').first().json.markdown }}` + - Messages: Single message with prompt text matching step (e.g., "What is on this page?") + - Connect Anthropic Chat Model nodes as AI language model for each Chain LLM node + - Connect Chain LLM nodes sequentially: Step 1 → Step 2 → Step 3 → Step 4 + +6. **Add Merge Node** + - Name: "Merge output with initial prompts1" + - Type: Merge + - Mode: Combine + - Combine by: Position + - Connect outputs of "All LLM steps here - sequentially" (Agent node) and "LLM Chain - Step 4" to this Merge node + +--- + +#### Agent-Based Processing Setup + +7. **Add Memory Manager Node** + - Name: "Clean memory" + - Type: Memory Manager + - Mode: Delete + - Delete Mode: All + +8. **Add Set Node for Initial Prompts** + - Name: "Initial prompts" + - Type: Set + - Assign variables: + - system_prompt: "You are a helpful assistant" + - step1 to step4: respective prompt strings as in naive chaining + +9. **Add Set Node to Reshape Prompts** + - Name: "Reshape" + - Type: Set + - Mode: Raw + - Use expression to convert step variables to array of objects with keys `step` and `instruction` + - Include system_prompt field + +10. **Add Split Out Node** + - Name: "Split Out" + - Type: Split Out + - Field to split: `data` + - Include `system_prompt` field in outputs + +11. **Add Memory Buffer Window Node** + - Name: "Simple Memory" + - Type: Memory Buffer Window + - Session Key: "fixed_session" + - Context Window Length: 10 + +12. **Add Anthropic Chat Model Node** + - Name: "Anthropic Chat Model4" + - Same configuration as previous Anthropic nodes + +13. **Add Agent Node** + - Name: "All LLM steps here - sequentially" + - Type: Agent + - Text parameter: Combine markdown content and instruction dynamically + - System message: Use system_prompt from input + - Connect Anthropic Chat Model4 as AI language model + - Connect Simple Memory as memory input + +14. **Add Merge Node** + - Name: "Merge" + - Type: Merge + - Mode: Combine + - Combine by: Position + - Connect outputs of Split Out and Agent node + +15. **Connect Clean memory → Initial prompts → Reshape → Split Out → Merge → Merge output with initial prompts1** + +--- + +#### Parallel Processing Setup + +16. **Add Set Node for Parallel Prompts** + - Name: "Initial prompts1" + - Type: Set + - Assign variable `userprompt` as array of prompt strings (same as above) + +17. **Add Split Out Node** + - Name: "Split Out1" + - Type: Split Out + - Field to split: `userprompt` + +18. **Add Merge Node** + - Name: "Merge2" + - Type: Merge + - Mode: Combine + - Combine by: Combine All + +19. **Add HTTP Request Node** + - Name: "LLM steps - parallel" + - Type: HTTP Request + - Method: POST + - URL: `{{ $env.WEBHOOK_URL }}webhook/58d2b899-e09c-45bf-b59b-961a5d7a2470` (replace with actual n8n URL for cloud users) + - Body: JSON, send entire JSON data + - Connect Split Out1 output to this node + - Connect output back to Merge2 + +20. **Add Webhook Node** + - Name: "Webhook" + - Type: Webhook + - Path: "58d2b899-e09c-45bf-b59b-961a5d7a2470" + - Method: POST + - Response Mode: Last node + +21. **Add Chain LLM Node** + - Name: "Basic LLM Chain4" + - Type: Chain LLM + - Text: Combine user prompt and markdown content dynamically + +22. **Add Anthropic Chat Model Node** + - Name: "Anthropic Chat Model5" + - Same model and credentials as previous Anthropic nodes + +23. **Connect Webhook → Basic LLM Chain4 → Anthropic Chat Model5 → Webhook response** + +24. **Connect Merge2 output and LLM steps - parallel output to "Merge output with initial prompts" node** + +--- + +### 5. General Notes & Resources + +| Note Content | Context or Link | +|-------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------| +| Follow me on [LinkedIn](https://www.linkedin.com/in/parsadanyan/) for more AI automation tips. | Author’s LinkedIn profile for additional workflow insights and AI automation resources. | +| ⚠️ Cloud users must replace `{{ $env.WEBHOOK_URL }}` in the "LLM steps - parallel" HTTP Request node with their actual n8n instance URL. | Important deployment instruction for correct webhook routing in cloud environments. | +| The workflow fetches content from the n8n blog by default; you can modify the HTTP Request node URL to use other data sources. | Allows customization of input content for LLM processing. | +| The Anthropic API key must be configured in n8n credentials manager under "Anthropic account". | Required for all Anthropic Chat Model nodes to function properly. | +| Memory Buffer Window node uses a fixed session key "fixed_session" to maintain conversation history in the Agent-based block. | Enables context retention across iterative LLM calls. | + +--- + +This structured document fully describes the workflow’s architecture, node configurations, and instructions for reproduction, enabling users and AI agents to understand, modify, or rebuild the workflow efficiently. \ No newline at end of file