CrewAI Tutorial (TypeScript): running agents in parallel for beginners

By Cyprian AaronsUpdated 2026-04-21
crewairunning-agents-in-parallel-for-beginnerstypescript

This tutorial shows you how to run multiple CrewAI agents in parallel from TypeScript and collect their results in one place. You need this when one task can be split into independent subtasks, like researching three vendors at the same time instead of waiting for each agent to finish serially.

What You'll Need

  • Node.js 18+
  • A TypeScript project with tsconfig.json
  • @crewai/core installed
  • dotenv installed for local env loading
  • An OpenAI API key in .env
  • Basic familiarity with async/await in TypeScript

Install the packages first:

npm install @crewai/core dotenv
npm install -D typescript tsx @types/node

Create a .env file:

OPENAI_API_KEY=your_openai_api_key_here

Step-by-Step

  1. Create a small TypeScript entry file and load environment variables before you touch CrewAI. This keeps your API key out of code and makes the script runnable from the terminal.
import "dotenv/config";
import { Agent, Task, Crew, Process } from "@crewai/core";

if (!process.env.OPENAI_API_KEY) {
  throw new Error("OPENAI_API_KEY is missing");
}

console.log("Environment ready");
  1. Define two or more agents that can work independently. For parallel execution, the key is that their tasks should not depend on each other’s output.
import "dotenv/config";
import { Agent, Task, Crew, Process } from "@crewai/core";

const marketAnalyst = new Agent({
  role: "Market Analyst",
  goal: "Summarize market trends for a product category",
  backstory: "You are good at concise research summaries.",
});

const riskAnalyst = new Agent({
  role: "Risk Analyst",
  goal: "Identify major risks for a product category",
  backstory: "You focus on operational and compliance risks.",
});
  1. Create tasks that can be executed in parallel by setting the crew process to Process.parallel. Each task should be self-contained so the agents do not wait on each other.
import "dotenv/config";
import { Agent, Task, Crew, Process } from "@crewai/core";

const marketTask = new Task({
  description: "Summarize current market trends for small business cyber insurance in 5 bullets.",
  expectedOutput: "A short bullet list of trends.",
  agent: marketAnalyst,
});

const riskTask = new Task({
  description: "List the top 5 underwriting risks for small business cyber insurance.",
  expectedOutput: "A short bullet list of risks.",
  agent: riskAnalyst,
});
  1. Build the crew with both tasks and run it. The Process.parallel setting is what tells CrewAI to execute independent work at the same time instead of one after another.
import "dotenv/config";
import { Agent, Task, Crew, Process } from "@crewai/core";

const crew = new Crew({
  agents: [marketAnalyst, riskAnalyst],
  tasks: [marketTask, riskTask],
  process: Process.parallel,
});

async function main() {
  const result = await crew.kickoff();
  console.log(JSON.stringify(result, null, 2));
}

main().catch((error) => {
  console.error(error);
  process.exit(1);
});
  1. If you want cleaner output handling, capture each task result separately and print them with labels. This makes it easier to test parallel work when you are building workflows for internal tools.
import "dotenv/config";
import { Agent, Task, Crew, Process } from "@crewai/core";

async function main() {
  const result = await crew.kickoff();

  console.log("\n=== Parallel Results ===");
  console.log(result);
}

main().catch((error) => {
  console.error(error);
  process.exit(1);
});

Testing It

Run the script with tsx so you do not need a build step:

npx tsx src/index.ts

If it works, you should see one combined result object containing outputs from both tasks. To confirm parallelism in practice, make one task slower by asking for a longer analysis and compare total runtime against running them separately. If your API usage is correct and both agents are independent, the crew should finish faster than a strictly sequential setup.

If you get an auth error, check that OPENAI_API_KEY is set in the shell session where you launched the script. If you get type or import errors, verify your installed @crewai/core version matches the syntax used here.

Next Steps

  • Add task dependencies and compare Process.parallel with sequential execution.
  • Wrap this pattern inside an Express or Fastify route for API-driven agent workflows.
  • Add structured output parsing so each agent returns JSON instead of plain text

Keep learning

By Cyprian Aarons, AI Consultant at Topiax.

Want the complete 8-step roadmap?

Grab the free AI Agent Starter Kit — architecture templates, compliance checklists, and a 7-email deep-dive course.

Get the Starter Kit

Related Guides