liveBook · Manning

Agent flow

As explained in AI Agents in Action, Second Edition

An agent flow pattern is a multi-agent collaboration pattern in which specialized agents are arranged sequentially to perform a multistep task.

An agent flow is an assembly line for a multistep task. Specialized agents work in sequence: each handles a defined role, then passes work to the next. It is a useful starting point when one agent struggles to complete a well-defined chain of work. section 1.4.1

A flow resembles prompt chaining, but each agent can use tools and make decisions within its role. Unlike an orchestrator, a basic flow has no central agent deciding which worker runs next. That simplicity makes it easier to implement and debug, but a failed step can stop the whole flow. section 4.2.2 section 4.1.1

To turn an overloaded single agent into a flow:

  • Identify distinct jobs, especially where a growing prompt or tool list makes the agent unreliable. section 4.2.1
  • Give each agent instructions and only the tools needed for its job. Arrange the roles in task order. section 4.2.2
  • Choose what travels between steps. A shared thread preserves context but can grow noisy; a structured blackboard organizes intermediate results; a direct chain passes only the needed output. section 1.4.1

Research-plan flow

A research agent finds sources, a planning agent turns them into a plan, and a filesystem agent writes the plan to a text file. Each role owns its relevant tools rather than requiring one agent to operate every tool. section 4.2.1 section 4.2.2

Keep hard pass/fail rules outside an agent when repeatability matters. For example, return research sources as a typed list and check in code that it is not empty before continuing. Validate inputs, outputs, and transfers; use inexpensive schema or code checks for rules they can express, reserving LLM-based guardrails for genuinely semantic judgments. These checks matter because an agent’s output can vary, and a bad handoff can affect every later step. section 4.2.3 section 4.4

Listing 4.2 02_agent_to_agent_flow.py
research_agent = Agent(
    name="Research Agent",    #1
    instructions="""
You are a research assistant.
Your role is to find research sources.
""",
)
thinking_agent = Agent(
    name="Thinking Agent",    #1
    instructions="""
You are a research assistant.
Your role is to plan the research.
""",
)
filesystem_agent = Agent(
    name="Filesystem Agent",    #1
    instructions="""
You are a research assistant.
Your role is to write the research plan as a text file.
""",
)
# MCP server setup remains the same
async with (
    servers[0] as research_srv,
    servers[1] as thinking_srv,
    servers[2] as fs_srv,
):
    goal = """
Produce a research plan to find the book 'The Hitchhiker's Guide to the Galaxy'
"""
    print("Running...", goal)
    research_agent.mcp_servers = [research_srv]    #2
    result = await Runner.run(research_agent, goal)
    thinking_agent.mcp_servers = [thinking_srv]    #2
    result = await Runner.run(thinking_agent, result.final_output) 
    filesystem_agent.mcp_servers = [fs_srv]    #3
    result = await Runner.run(filesystem_agent, result.final_output)    #4
    print(result.final_output)    #4

Inspect the three-agent listing to see role-specific instructions, tool-server assignment, and sequential execution in a small working flow. section 4.2.2

How AI Agents in Action, Second Edition covers it

How deep it goes
Develops role-based decomposition through an implementation example, then adds typed outputs, coded decisions, and validation.
Examples
Builds a research-source, planning, and file-writing pipeline, then tests a coded decision against variable source counts.
What it assumes
Starts from a single-agent design and explains why separate roles and handoffs become useful as tools and instructions grow.
What you can do after
Build it from scratch by splitting a single agent into focused stages and validating uncertain handoffs.
How it connects
Connects prompt chaining and single-agent decomposition to orchestration, communication patterns, structured outputs, and guardrails.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of AI Agents in Action, Second Edition. The section links point to the parts of the book it draws on.