// lesson: pipelines
Pipelines โ Sequential Handoff
The simplest way to compose agents is a pipeline: run them in order, each agent's output becoming the next agent's input. Researcher digs up the facts; writer turns the facts into prose. This is the workhorse pattern of multi-agent systems โ Anthropic's "Building Effective Agents" article calls it prompt chaining and recommends it as the first thing to reach for, CrewAI calls it a sequential process, and in LangGraph it's a graph whose nodes are connected in a straight line. All of them are this function:
def run_pipeline(agents, task):
transcript = []
current = task
for name, agent in agents:
current = agent(current)
transcript.append((name, current))
return transcript
agents is a list of (name, agent) pairs, so the transcript can say who
produced what. The function returns the whole transcript, not just the
final answer โ transcript[-1][1] โ because the intermediate steps are
where all the debugging happens. When the final article is wrong, the first
question is always "was the research wrong, or did the writer mangle good
research?" A transcript answers that in one glance; a system that only keeps
the final output can't.
Wire it into team.py and run a real handoff:
if __name__ == "__main__":
task = "Why do vector databases use approximate nearest neighbor search?"
steps = run_pipeline(
[(researcher.name, researcher), (writer.name, writer)],
task,
)
for name, output in steps:
print(f"--- {name} ---")
print(output)
print()
Run it. Read the researcher's brief, then the writer's article, and check: did the facts survive the handoff? You've just done your first transcript review โ the multi-agent equivalent of reading a stack trace, and a habit worth keeping.
Two things to notice about the handoff itself. First, the writer's system prompt says "the material you are given" โ it was written for the pipeline, where its input is a research brief, not a raw question. Role prompts and pipeline position are designed together. Second, everything the writer knows arrives through one string. That's message passing: explicit, loggable, testable dataflow. (The alternative โ a shared scratchpad all agents read and write โ is the blackboard pattern; we'll weigh the trade-offs in the last lesson.)
Try a three-stage pipeline before moving on: add a summarizer agent that
compresses the article to two sentences, append it to the list, run again.
Zero new plumbing โ that's the payoff of the uniform (name, agent) shape.
In the graded version the agents are plain lambdas, because run_pipeline
never cares that its agents call an LLM โ only that they're callables. The
tests pin down the threading (each agent sees exactly the previous output)
and the transcript shape.
โบ Run the Pipeline
15 ptsImplement run_pipeline(agents, task), where agents is a list of
(name, agent) pairs and each agent is a callable taking one string and
returning one string:
- Call the first agent with
task; call each subsequent agent with the previous agent's output. Each agent is called exactly once, in order. - Return a list of
(name, output)tuples, one per agent, in run order. - An empty
agentslist returns[].
Log in to submit a solution and earn points.