architecture

Pattern: Agent Chaining & Orchestration

Architectural pattern for chaining multiple AI agents into workflows. Covers when to chain vs single-agent, framework selection, and implementation patterns.

Overview

Agent chaining connects multiple AI agents into workflows where the output of one agent feeds into another. This pattern enables complex, multi-step tasks that exceed single-agent capabilities.

When to Chain Agents

Chain When

Condition Example
Multi-step reasoning with validation Research β†’ Validate β†’ Draft
Different tools per stage APIs β†’ Database β†’ LLM
Parallel data gathering LinkedIn + CRM + News β†’ Synthesis
Quality gates between stages Draft β†’ Review β†’ Approve
Fallback logic needed Primary path β†’ Alternative path

Don't Chain When

Condition Better Approach
Single well-defined task Single prompt
Linear transformation Prompt chaining in one call
Simple data lookup + response RAG
Adding complexity for complexity's sake KISS

Framework Selection

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                    FRAMEWORK DECISION TREE                       β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚                                                                 β”‚
β”‚  Need system integration (APIs, databases, webhooks)?           β”‚
β”‚  β”œβ”€β–Ί Yes + No-code preferred β†’ n8n / Make                       β”‚
β”‚  └─► Yes + Code preferred β†’ LangChain + custom                  β”‚
β”‚                                                                 β”‚
β”‚  Need complex state management?                                  β”‚
β”‚  β”œβ”€β–Ί Yes + Conditional branching β†’ LangGraph                    β”‚
β”‚  └─► Yes + Role-based agents β†’ CrewAI                           β”‚
β”‚                                                                 β”‚
β”‚  Need visual building?                                           β”‚
β”‚  └─► Flowise / Langflow                                          β”‚
β”‚                                                                 β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Framework Comparison

Framework Complexity Integration State Best For
n8n Low Excellent Basic Workflows with APIs
Make/Zapier Very Low Good None Quick automation
LangChain Medium Custom Manual Reasoning chains
LangGraph High Custom Excellent Complex state machines
CrewAI Medium Custom Role-based Agent teams

Chaining Patterns

Pattern 1: Sequential Pipeline

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”     β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”     β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”     β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Agent A │────►│ Agent B │────►│ Agent C │────►│ Output  β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜     β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜     β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜     β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Use for: Linear transformations, content pipelines Example: SEO Research β†’ Brief β†’ Draft β†’ Edit

Pattern 2: Parallel Gather + Synthesize

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Source A│────┐
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β”‚     β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”     β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”œβ”€β”€β”€β”€β–Ίβ”‚ Synthesizer │────►│ Output  β”‚
β”‚ Source B│─────     β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜     β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β”‚
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”‚
β”‚ Source Cβ”‚β”€β”€β”€β”€β”˜
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Use for: Research aggregation, data enrichment Example: LinkedIn + CRM + News β†’ Prospect Brief

Pattern 3: Router

                    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”
              β”Œβ”€β”€β”€β”€β–Ίβ”‚ Path A  β”‚
              β”‚     β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”   β”‚     β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Router  │───┼────►│ Path B  β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜   β”‚     β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
              β”‚     β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”
              └────►│ Path C  β”‚
                    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Use for: Conditional logic, risk-based responses Example: Health Score β†’ Red/Yellow/Green Response Path

Pattern 4: Shared Memory

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”     β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”     β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Agent A │────►│ Agent B │────►│ Agent C β”‚
β””β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”˜     β””β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”˜     β””β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”˜
     β”‚               β”‚               β”‚
     β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                     β”‚
              β”Œβ”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”
              β”‚ Shared      β”‚
              β”‚ Memory      β”‚
              β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Use for: Long-running workflows, context accumulation Example: Sales cycle with persistent prospect context

Anti-Patterns

Anti-Pattern Problem Solution
Over-chaining Simple task in 5 agents Single well-prompted agent
No validation Errors compound Add validation nodes
Sync everything Slow, expensive Parallelize independent steps
No fallback One failure kills all Add retry/fallback branches
Stateless Context lost Persist state appropriately
LLM for everything Expensive Use deterministic logic where possible

Role-Specific Chains

See detailed chains in role documents:

Chain Agents Document
Prospect β†’ Email Research + Draft Sales AI Agents
Health β†’ Response Monitor + Router + Action Customer Success AI Agents
Content Pipeline SEO + Brief + Draft + Edit Marketing AI Agents
Incident Response Logs + Hypothesis + Runbook Engineering AI Agents

Implementation Examples

n8n Example

[Webhook] β†’ [HTTP: LinkedIn] ──┐
                               β”œβ”€β–Ί [Merge] β†’ [OpenAI] β†’ [CRM Update]
[Webhook] β†’ [HTTP: News]    β”€β”€β”˜

LangChain Example

chain = (
    RunnableParallel(linkedin=linkedin_tool, news=news_tool)
    | synthesis_prompt
    | llm
    | output_parser
)

See Implementation Guide: Building Agents with n8n and Implementation Guide: Building Agents with LangChain for full guides.