# Parallelisation as an Agentic Workflow

Source: https://tpiros.dev/blog/parallelisation-as-an-agentic-workflow

Parallelisation is one of the oldest tricks in computing. It turns out it works brilliantly with LLMs too.

The idea: break a task into independent, persona-based prompts, fire them all at once, then stitch the results together. You get faster responses and richer perspectives.

We'll build this pattern using the `@google/genai` SDK, framed through a Star Wars scenario:

> "Was the destruction of the Death Star justified?"

Four personas (a Rebel pilot, an Imperial officer, a neutral citizen, and a droid analyst) will each answer simultaneously. Then a separate LLM call aggregates everything into one balanced summary.

# What Is an Agentic Workflow?

An agentic workflow treats an LLM as a cooperative set of agents, each contributing to a more complex reasoning process. These agents can operate:

- [Sequentially (e.g. prompt chaining)](https://tpiros.dev/blog/prompt-chaining-building-step-by-step-ai-reasoning/)
- [Via Routing](https://tpiros.dev/blog/routing-building-step-by-step-ai-reasoning/)
- Or, as we'll see here, in parallel

Parallelisation gives you two things:

- Lower latency (all agents think at once)
- Greater diversity (each prompt carries a unique voice or role)

This shines in multi-role decision making, creative brainstorming, and opinion synthesis.

# Code Walkthrough: Multi-Perspective Reasoning

We'll build a Node.js script that prompts four LLM "personas" in parallel, collects their opinions, displays each response, then aggregates them into a single summary. The example here is playful, but the pattern transfers directly to real use cases: stakeholder debates, decomposing RAG queries into sub-queries, or running map-reduce style operations.

## Setup

We'll be using the official `@google/genai` SDK to interact with Google Gemini models via Node.js.

```javascript

const ai = new GoogleGenAI({ apiKey: process.env.GEMINI_API_KEY });
```

## Step 1: The `generateContent` helper

This function sends a prompt to the LLM using Gemini 2.0 Flash and returns the response text. It also logs the prompt for visibility.

```javascript
async function generateContent(prompt) {
  const model = 'gemini-2.0-flash';
  console.log(`\n📝 Prompt:\n${prompt}\n`);
  const result = await ai.models.generateContent({ model, contents: prompt });
  return result.text;
}
```

## Step 2: Define our personas

Each perspective is represented by an object with a role and prompt. The roles cover diverse viewpoints to generate well-rounded answers. All prompts orbit the central question:

> "Was the destruction of the Death Star justified?"

You could further customise these personas by giving the LLM a more detailed character description.

```javascript
const baseQuestion = 'Was the destruction of the Death Star justified?';

const personaPrompts = [
  {
    role: 'Rebel pilot',
    emoji: '🚀',
    prompt: `As a Rebel pilot who fought in the Battle of Yavin, answer: ${baseQuestion}`,
  },
  {
    role: 'Imperial officer',
    emoji: '🛡️',
    prompt: `As an Imperial officer loyal to the Empire, answer: ${baseQuestion}`,
  },
  {
    role: 'Neutral galactic citizen',
    emoji: '🌌',
    prompt: `As a neutral galactic citizen with no allegiance, answer: ${baseQuestion}`,
  },
  {
    role: 'Droid analyst',
    emoji: '🤖',
    prompt: `As a logical droid analyst evaluating from an ethical and strategic standpoint, answer: ${baseQuestion}`,
  },
];
```

## Step 3: Run the LLM calls in parallel

We map over the persona prompts and fire all LLM requests concurrently using `Promise.all()`.

```javascript
const tasks = personaPrompts.map((p) => generateContent(p.prompt));
const responses = await Promise.all(tasks);
// We also time the whole process for benchmarking:

const startTime = Date.now();
// ... run tasks
const endTime = Date.now();
console.log(`\n⏱️ Time taken: ${(endTime - startTime) / 1000} seconds`);
```

## Step 4: Display each perspective

Once we've collected the responses, we output each one matched with its emoji and role:

```javascript
console.log('\n--- Individual Perspectives ---');
responses.forEach((res, i) => {
  const { role, emoji } = personaPrompts[i];
  console.log(`${emoji} ${role}:\n${res}\n`);
});
```

This step isn't strictly necessary, but it lets us inspect the individual responses before aggregation.

## Step 5: Aggregate the viewpoints

We prepare a single prompt that combines all four responses and asks another LLM to synthesise the perspectives:

```javascript
const aggregationInput = responses
  .map(
    (res, i) => `${personaPrompts[i].emoji} ${personaPrompts[i].role}:\n${res}`
  )
  .join('\n\n');

const aggregationPrompt = `Combine the following four perspectives into a thoughtful, balanced summary of the debate over whether the destruction of the Death Star was justified:\n\n${aggregationInput}`;
```

We then call a slightly more capable model (Gemini 2.5 Flash) to generate this summary. You could swap in a pro model for richer output:

```javascript
const aggregationModel = 'gemini-2.5-flash-preview-04-17';

const summary = await ai.models.generateContent({
  model: aggregationModel,
  contents: aggregationPrompt,
});
console.log('\n🧠 --- Aggregated Summary ---');
console.log(`🌀 Summary:\n${summary.text}\n`);
```

Here's what a typical run looks like:

# Conclusion

This pattern shows how parallelisation in LLM workflows can simulate rich, multi-voice reasoning. Rather than leaning on a single model run, we treat each agent as an independent contributor, then aggregate their insights into something cohesive.

The same approach works well for:

- Multi-stakeholder feedback (e.g. HR, legal, product)
- Cross-role decision simulations
- Tone and perspective testing
- Ethical or philosophical debates
- AI-powered brainstorming with diverse "personas"
