TypeScriptADK-TS

Sequential Agents

Execute agents one after another in a specific order

Sequential agents create powerful pipelines where agents execute in a specific order, with each step building on the results of the previous one. Think assembly line for AI - each agent specializes in one part of the process, and the final result is the combined output of all steps working together.

Perfect for workflows where order matters: research before analysis, writing before editing, data collection before processing. Unlike parallel agents that run simultaneously, sequential agents guarantee execution order and enable sophisticated multi-step reasoning.

When Order Matters

Use sequential agents when each step depends on the previous one's output. The magic happens when agents pass enriched context down the pipeline, creating more sophisticated results than any single agent could achieve.

Quick Start Example

Here's a content creation pipeline that writes, edits, and fact-checks articles in sequence:

import { LlmAgent, SequentialAgent } from "@iqai/adk";

// Step 1: Create initial content
const writerAgent = new LlmAgent({
  name: "writer_agent",
  description: "Creates engaging and informative articles on given topics",
  instruction: `Write a comprehensive, engaging article on the given topic. Include an introduction, main points with examples, and a conclusion.`,
  outputKey: "draft_content", // Key for passing output to next agent
});

// Step 2: Edit for clarity and style
const editorAgent = new LlmAgent({
  name: "editor_agent",
  description: "Edits content for clarity, grammar, and style",
  instruction: `Review and edit the article for clarity, grammar, and style. Improve readability while maintaining the original voice and message.`,
  outputKey: "edited_content", // Key for passing output to next agent
});

// Step 3: Verify facts and add citations
const factCheckerAgent = new LlmAgent({
  name: "fact_checker_agent",
  description: "Verifies factual claims and adds citations where needed",
  instruction: `Verify factual claims in the content. Flag any unsupported statements and add citations where needed. Ensure accuracy and credibility.`,
  outputKey: "verified_content", // Final output key
});

// Sequential pipeline: write → edit → fact_check
const contentCreationAgent = new SequentialAgent({
  name: "content_creation_agent",
  description: "End-to-end content creation with quality controls",
  subAgents: [writerAgent, editorAgent, factCheckerAgent],
});

// Export the sequential agent for use
export { contentCreationAgent };

Visual Flow

How Sequential Processing Works

Sequential agents create a data pipeline where information gets progressively enriched at each step:

🔄 Execution Flow

  1. Agent 1 receives the original input and processes it
  2. Agent 2 gets both the original input AND Agent 1's output
  3. Agent 3 receives original input + Agent 1's output + Agent 2's output
  4. This continues for each agent in the sequence

💡 Context Accumulation
Each agent sees the full conversation history, so later agents can reference and build upon earlier agents' work. This creates sophisticated reasoning chains that single agents can't achieve.

🎯 Deterministic Order
Execution order is guaranteed - no race conditions or unpredictable results. Perfect for production workflows where consistency matters.

Data Flow Between Agents

Agents automatically share session state, so later agents can reference earlier results. Use unique outputKey values for each agent and clear instructions to help agents understand what information to pass forward.

Real-World Use Cases

📊 Business Intelligence Pipeline
Research → Analysis → Strategic Recommendations → Executive Summary

📝 Content Creation Workflow
Draft → Fact-check → Edit → Style Review → Final Polish

🔍 Technical Documentation
Code Analysis → Documentation Draft → Technical Review → User Testing → Publication

⚖️ Legal Document Review
Initial Review → Compliance Check → Risk Assessment → Final Approval

🧪 Scientific Analysis
Data Collection → Statistical Analysis → Peer Review → Conclusion Generation

When to Choose Sequential Agents

Perfect For Sequential Processing

  • Use when: Each step builds on the previous one's output
  • Benefit: Creates sophisticated reasoning chains impossible with single agents

✅ Choose Sequential When:

  • Dependencies matter - Later steps need earlier results
  • Quality control - Each stage validates and improves the work
  • Specialization - Different expertise needed at each step
  • Compliance - Regulated workflows requiring specific order
  • Complex reasoning - Multi-step analysis and decision making

❌ Don't Use Sequential When:

  • Tasks are completely independent
  • Speed is more important than thoroughness
  • You need real-time parallel processing
  • Simple, single-step operations

How is this guide?