liveBook · Manning

Parallel flow

As explained in Build an AI Agent (From Scratch)

A parallel workflow runs multiple constituent agents or steps concurrently and combines their results.

A parallel flow runs independent agents concurrently on the same input, then combines their analyses. It suits tasks that benefit from multiple viewpoints, such as business evaluation, code review, or research across subtopics. section 9.3 section 9.3.3

Implement the flow as an Agent with an asynchronous run() method. Capture the existing context length, invoke every agent with asyncio.gather(), and merge the returned events. Copy earlier context first, append only events generated after the captured boundary, remove duplicate user events, and use event.author to preserve each agent’s identity. Combine final outputs with an agent-name header. section 9.3.1 section 9.3.3

Three-perspective startup analysis

Create optimist, pessimist, and realist agents with focused instructions, place them in ParallelWorkflow, and run them on an AI education-platform startup idea. The resulting output preserves each perspective while presenting a single merged result. section 9.3.3

Listing 9.4 Workflow design: Agent inheritance
class SequentialWorkflow(Agent):
    async def run(self, user_input=None, context=None, verbose=False) -> AgentResult:
        ...

class ParallelWorkflow(Agent):
    async def run(self, user_input=None, context=None, verbose=False) -> AgentResult:
        ...

class LoopWorkflow(Agent):
    async def run(self, user_input=None, context=None, verbose=False) -> AgentResult:
        ...

Use the workflow inheritance listing to inspect the shared Agent interface and compose parallel flows inside larger workflows. section 9.3.1 section 9.3.5

How Build an AI Agent (From Scratch) covers it

How deep it goes
Explains asynchronous execution, context boundaries, duplicate-event removal, result merging, and workflow composition.
Examples
Uses optimistic, pessimistic, and realistic startup analysis plus security, performance, readability, and multi-subtopic research scenarios.
What it assumes
Assumes Agent, context, events, and asynchronous execution, while demonstrating workflow composition through a shared run() interface.
What you can do after
Build it from scratch as an asynchronous Agent-compatible workflow that runs agents concurrently and merges their results.
How it connects
Connects Agent, SequentialWorkflow, LoopWorkflow, ExecutionContext, asyncio.gather(), and explicit workflow orchestration.

Also explained in

Compare how 2 books explain parallel flow →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Build an AI Agent (From Scratch). The section links point to the parts of the book it draws on.