TypeScriptADK-TS

Parallel Agents

Run multiple agents simultaneously for faster processing

Parallel agents unleash the power of concurrent processing, running multiple agents simultaneously to tackle independent tasks. Think of it as your AI team working in parallel - while one agent analyzes sentiment, another extracts topics, and a third generates summaries, all at the same time.

Unlike sequential agents that process step-by-step, parallel agents maximize speed and efficiency by utilizing multiple processing streams. Perfect when you have independent tasks that don't need to wait for each other.

Speed Through Parallelism

  • Key benefit: Process multiple independent tasks simultaneously instead of waiting for each one to finish.
  • Performance boost: 3 tasks that take 10 seconds each = 10 seconds total (not 30!)

Quick Start Example

Here's a comprehensive parallel analysis agent that evaluates user feedback from multiple angles simultaneously:

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

// Parallel analysis agents for user feedback - each analyzes different aspects simultaneously
const sentimentAgent = new LlmAgent({
  name: "sentiment_agent",
  description:
    "Analyzes the overall sentiment and emotional tone of user feedback",
  instruction: `Analyze the sentiment of the user feedback. Classify as positive, negative, or neutral, and provide a confidence score. Identify specific emotional indicators.`,
  outputKey: "sentiment_analysis", // Key for storing sentiment results
});

const topicAgent = new LlmAgent({
  name: "topic_agent",
  description: "Categorizes feedback into relevant topics and themes",
  instruction: `Identify the main topics and themes in the user feedback. Categorize into areas like product features, customer service, pricing, usability, etc. List specific topics mentioned.`,
  outputKey: "topic_categories", // Key for storing topic results
});

const issueAgent = new LlmAgent({
  name: "issue_agent",
  description:
    "Identifies specific problems, bugs, or concerns mentioned in feedback",
  instruction: `Extract and categorize any specific issues, problems, or concerns mentioned in the feedback. Prioritize critical issues and suggest severity levels.`,
  outputKey: "identified_issues", // Key for storing issue results
});

const suggestionAgent = new LlmAgent({
  name: "suggestion_agent",
  description: "Extracts user suggestions and improvement ideas",
  instruction: `Identify any suggestions, recommendations, or improvement ideas mentioned in the feedback. Organize them by category and feasibility.`,
  outputKey: "user_suggestions", // Key for storing suggestion results
});

const satisfactionAgent = new LlmAgent({
  name: "satisfaction_agent",
  description: "Rates overall user satisfaction and likelihood to recommend",
  instruction: `Rate the user's overall satisfaction on a scale of 1-10. Assess likelihood to recommend and identify key satisfaction drivers or pain points.`,
  outputKey: "satisfaction_rating", // Key for storing satisfaction results
});

// Parallel analysis system - demonstrates concurrent execution pattern
const feedbackAgent = new ParallelAgent({
  name: "feedback_agent",
  description:
    "Comprehensive parallel analysis of user feedback across multiple dimensions",
  subAgents: [
    sentimentAgent,
    topicAgent,
    issueAgent,
    suggestionAgent,
    satisfactionAgent,
  ],
});

// Export the parallel agent for use
export { feedbackAgent };

Visual Flow

How Parallel Processing Works

Parallel agents maximize efficiency by running all sub-agents simultaneously:

⚡ Concurrent Execution

  1. All agents start together - No waiting for previous agents to finish
  2. Independent processing - Each agent works on the same input independently
  3. Simultaneous completion - Results become available as each agent finishes
  4. Non-deterministic order - Faster agents finish first, slower ones catch up

📊 Performance Benefits

  • Time savings: N agents running for T seconds = T total time (not N×T)
  • Resource utilization: Maximizes CPU/GPU usage across multiple agents
  • Scalability: Add more agents without increasing total processing time

🔄 Result Aggregation Each agent writes to unique keys in shared session state. Later agents (or your application) can access all results together for final processing.

State Management

Use unique outputKey values for each agent to prevent conflicts. Results are available immediately as each agent completes - perfect for real-time updates!

Real-World Use Cases

📝 Multi-Perspective Content Analysis
Sentiment + Topics + Keywords + Priority Assessment (all simultaneously)

🔍 Comprehensive Research
Web Search + Academic Papers + News + Social Media (parallel data gathering)

📊 Financial Analysis
Technical Analysis + Fundamental Analysis + News Sentiment + Risk Assessment

🛠️ Quality Assurance
Grammar Check + Fact Verification + Style Review + Compliance Check

🌍 Multi-Language Processing
Translation + Sentiment + Cultural Context + Localization (per language)

📊 Data Validation
Format Check + Business Rules + Data Quality + Duplicate Detection

When to Choose Parallel Agents

Perfect For Independent Tasks

  • Use when: Tasks don't depend on each other's results during execution
  • Benefit: Dramatic speed improvements through simultaneous processing

✅ Choose Parallel When:

  • Independent analysis - Multiple perspectives on the same data
  • Speed is critical - Need results as fast as possible
  • Resource optimization - Want to maximize processing power
  • Multi-source data - Gathering from different sources simultaneously
  • Comparative analysis - Need multiple approaches to the same problem

❌ Don't Use Parallel When:

  • Tasks depend on each other's intermediate results
  • You need guaranteed execution order
  • Sequential processing is part of the business logic
  • Resource constraints limit concurrent execution
  • Results from one agent affect how another should process

How is this guide?