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.
Related Documents
- ENT-AGENT-CHAINING - Core concept definition
- Pattern: Memory & State Management - State management patterns
- Implementation Guide: Building Agents with LangChain - LangChain implementation
- Implementation Guide: Building Agents with n8n - n8n implementation