Agentic Design

Patterns
πŸ”—

Sequential Chaining

A fundamental prompt engineering technique that breaks complex tasks into smaller, interconnected prompts where each output serves as input for the next step, creating a structured reasoning pipeline that significantly improves LLM performance on multi-step problems

Complexity: lowPrompt Chaining

Video Explanation

Loading video explanation...

🎯 30-Second Overview

Pattern: Break complex tasks into linear pipeline of focused steps

Why: Reduces model cognitive load, isolates errors, enables tool integration & step caching

Key Insight: Output[N] β†’ Input[N+1] with structured data (JSON) - each step cacheable

⚑ Quick Implementation

1Decompose:Break task into focused stages
2Define I/O:JSON schemas for each stage
3Chain:Output[N] β†’ Input[N+1]
4Validate:Assert & retry at each step
5Monitor:Log latency, cost, errors
Example: analyze_doc β†’ extract_data β†’ validate β†’ transform β†’ summarize

πŸ“‹ Do's & Don'ts

βœ…Use JSON/structured outputs between stages
βœ…Cache deterministic stage outputs (huge cost savings)
βœ…Use cache keys based on input hash + prompt version
βœ…Implement circuit breakers & retries
βœ…Set TTL for cached steps based on data freshness needs
❌Pass verbose prose between stages
❌Cache non-deterministic or time-sensitive steps
❌Skip cache invalidation on prompt changes
❌Ignore partial outputs/refusals
❌Let errors cascade unchecked

🚦 When to Use

Use When

  • β€’ Multi-step workflows (3+ stages)
  • β€’ Complex reasoning tasks
  • β€’ Need error isolation
  • β€’ Different models per stage

Avoid When

  • β€’ Simple single-step tasks
  • β€’ Real-time/low-latency needs
  • β€’ Tightly coupled logic
  • β€’ Limited API budget

πŸ“Š Key Metrics

Success Rate
Per-stage & E2E completion
Latency
P50/P95 per stage
Cost
Ξ£(tokens Γ— model_rate)
Error Recovery
% failures handled
Cache Hit Rate
% reused computations
Cost Savings
$ saved via caching

πŸ’‘ Top Use Cases

Document Analysis: parse β†’ extract β†’ analyze β†’ summarize (cache parsing)
Content Creation: research β†’ outline β†’ draft β†’ edit (cache research)
Data Pipeline: validate β†’ transform β†’ enrich β†’ aggregate (cache transforms)
Decision Flow: gather β†’ evaluate β†’ score β†’ recommend (cache gathering)
Report Generation: fetch β†’ process β†’ format β†’ deliver (cache all but delivery)

Pattern Relationships

Discover how Sequential Chaining relates to other patterns

Prerequisites, next steps, and learning progression

Prerequisites

No prerequisites needed - great for beginners!

Next Steps

(5)
⚑
Parallel Chaining
mediumprompt chaining

Execute multiple chains concurrently for speed and multi-perspective analysis

πŸ’‘ Natural next step to add concurrency to your linear chains

πŸ—ΊοΈ
Map-Reduce
mediumparallelization

Parallel processing followed by aggregation - perfect evolution of sequential chains

πŸ’‘ Scale your sequential logic to handle parallel data streams

πŸ“‘
Scatter-Gather
mediumparallelization

Distribute sequential steps across multiple agents and gather results

πŸ’‘ Transform linear chains into parallel distribution patterns

🍴
Fork-Join
mediumparallelization

Fork sequential tasks into parallel subtasks and join when complete

πŸ’‘ Add sophisticated parallel execution with synchronization points

πŸ•ΈοΈ
Stateful Graph Workflows
very-highworkflow orchestration

DAG-based workflows with complex branching logic

πŸ’‘ Advanced evolution for complex non-linear workflows

Alternatives

(2)
πŸ”—
Chain-of-Thought
lowreasoning techniques

Single-prompt step-by-step reasoning without explicit chaining

πŸ’‘ Simpler approach when you don't need separate API calls for each step

🎭
ReAct (Reasoning + Acting)
mediumtool use

Interleaves reasoning and action steps with tool use

πŸ’‘ Better when you need dynamic tool usage throughout the workflow

Industry Applications

Financial Services

Multi-stage analysis and decision-making workflows using sequential chains

πŸ“ŠMulti-Criteria Decision Making
βš–οΈLLM-as-Judge

Content & Knowledge

Sequential processing for document analysis and knowledge extraction

πŸ“šAdvanced RAG
πŸ—‚οΈHierarchical Planning

Software Development

Code analysis and generation workflows

πŸ’»Code Execution
πŸ”§SWE-Bench Suite

References & Further Reading

Deepen your understanding with these curated resources

Contribute to this collection

Know a great resource? Submit a pull request to add it.

Contribute

Patterns

closed

Loading...