CrewAI Tutorial (TypeScript): running agents in parallel for intermediate developers
This tutorial shows you how to run multiple CrewAI agents in parallel from TypeScript and collect their results into one workflow. You need this when the work can be split cleanly, like having one agent summarize a policy, another extract risks, and another draft customer-facing language at the same time.
What You'll Need
- •Node.js 18+ and npm
- •A TypeScript project initialized with
tsconfig.json - •CrewAI for TypeScript installed in your project
- •A valid LLM API key, such as:
- •
OPENAI_API_KEY
- •
- •Basic familiarity with:
- •
Agent - •
Task - •
Crew - •async/await in TypeScript
- •
- •A terminal that can run
npm,ts-node, or compiled Node output
Step-by-Step
- •Set up the project and install the packages.
I’m using OpenAI here because it’s the most common setup, but the same pattern works with any provider supported by your CrewAI runtime.
npm init -y
npm install @crew-ai/crewai openai dotenv
npm install -D typescript ts-node @types/node
npx tsc --init
- •Add your API key and make sure TypeScript can read environment variables.
Keep secrets out of source control. Load them at runtime withdotenv.
OPENAI_API_KEY=your_openai_api_key_here
- •Create three agents that each do one job well.
Parallel execution only makes sense when tasks are independent. Here, each agent analyzes the same input from a different angle.
import "dotenv/config";
import { Agent } from "@crew-ai/crewai";
export const riskAgent = new Agent({
name: "Risk Analyst",
role: "Identify operational and compliance risks",
goal: "Return concise risk findings",
backstory: "You work in banking risk reviews.",
});
export const summaryAgent = new Agent({
name: "Policy Summarizer",
role: "Summarize policy text clearly",
goal: "Return a short plain-English summary",
backstory: "You write internal policy summaries for operations teams.",
});
export const actionAgent = new Agent({
name: "Action Planner",
role: "Turn findings into next steps",
goal: "Return practical follow-up actions",
backstory: "You translate analysis into execution plans.",
});
- •Create one task per agent and run them concurrently with
Promise.all.
This is the core pattern. Each task uses the same input, but each agent produces a different output at the same time.
import { Task } from "@crew-ai/crewai";
import { riskAgent, summaryAgent, actionAgent } from "./agents";
const policyText = `
All customer identity checks must be completed before account activation.
Any exception requires approval from compliance within 24 hours.
`;
async function runParallelTasks() {
const tasks = [
new Task({
description: `Analyze this policy for operational and compliance risks:\n\n${policyText}`,
expectedOutput: "A short list of risks",
agent: riskAgent,
}),
new Task({
description: `Summarize this policy in plain English:\n\n${policyText}`,
expectedOutput: "A concise summary",
agent: summaryAgent,
}),
new Task({
description: `List next actions based on this policy:\n\n${policyText}`,
expectedOutput: "A practical action list",
agent: actionAgent,
}),
];
return Promise.all(tasks.map((task) => task.execute()));
}
- •Combine the outputs into one result object and print it.
In production, this is where you’d pass results into your orchestration layer, store them, or feed them into a fourth synthesis step.
async function main() {
const [riskResult, summaryResult, actionResult] = await runParallelTasks();
const report = {
summary: summaryResult.output,
risks: riskResult.output,
actions: actionResult.output,
};
console.log(JSON.stringify(report, null, 2));
}
main().catch((error) => {
console.error(error);
process.exit(1);
});
- •If you want to keep everything inside a Crew object, use the crew for shared configuration and still execute independent tasks in parallel where it matters.
The important part is not forcing unrelated work through a sequential pipeline.
import { Crew } from "@crew-ai/crewai";
import { riskAgent, summaryAgent, actionAgent } from "./agents";
const crew = new Crew({
agents: [riskAgent, summaryAgent, actionAgent],
});
void crew;
Testing It
Run the script with npx ts-node src/main.ts or compile it first with npx tsc && node dist/main.js. You should see three distinct outputs in JSON format: a summary, a risk analysis, and an action list.
To confirm parallelism, add timestamps before and after each task call and compare total runtime against running them one by one. If all three calls take roughly as long as the slowest single call instead of adding up sequentially, you’ve got concurrency working.
If one task fails while others succeed, that’s normal behavior for parallel execution. In that case, switch from Promise.all to Promise.allSettled so you can capture partial results without dropping the entire batch.
Next Steps
- •Add a fourth “synthesizer” agent that merges all parallel outputs into one final recommendation.
- •Use
Promise.allSettledplus retry logic for production-grade resilience. - •Split parallel workloads by domain, like claims review, fraud signals, and customer communication drafts.
Keep learning
- •The complete AI Agents Roadmap — my full 8-step breakdown
- •Free: The AI Agent Starter Kit — PDF checklist + starter code
- •Work with me — I build AI for banks and insurance companies
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