liveBook · Manning

Pipeline

As explained in AI Agents and Applications

A multi-step workflow is a process composed of several ordered or coordinated operations that collectively accomplish a task.

A pipeline turns a task into connected operations. Each step receives input, does a specific job, and passes its output onward. In LangChain, a sequence of these operations is a chain. This is useful when one LLM call cannot reasonably do the whole job—for example, when a research report requires searches, page extraction, summaries, and a final synthesis. section 3.0 section 4.8

Build a chain by connecting components that implement the Runnable interface. LCEL’s pipe operator (`|`) passes each component’s output to the next. Prompt templates prepare model input; output parsers turn model responses into usable text; `RunnableLambda` brings a Python function into the chain. Check the shape of each intermediate output: the next step must receive the fields it expects. section 3.1.2 section 3.1.3 section 4.7.1

Choose the arrangement that fits the task:

  • Sequential: split a large document, summarize its chunks, then combine the summaries. A refinement variant updates a running summary one document at a time. section 3.1.3 section 3.2.5
  • Parallel: use `RunnableParallel` for operations on the same input, or `.map()` to run a sub-chain for each item in a list. Gather the results before writing the final report. section 4.8 section 4.7.4
  • Two-stage: ingest documents by splitting, embedding, and storing chunks; later retrieve relevant chunks to supply context for an LLM answer. section 6.1.3 section 6.4

A research pipeline

A travel question first selects suitable instructions, then generates web searches. Each result is scraped and summarized; the partial summaries become a research report. Test the sub-chains before combining them, and preserve the original question where later steps need it. The final chain can be run with `.invoke()`; its sub-chains can be changed without rebuilding every step. section 5.5.1 section 4.7.4 section 4.8

Listing 4.13 Web Research chain
web_research_chain = (
    assistant_instructions_chain 
    | web_searches_chain 
    | search_and_summarization_chain.map() # parallelize for each web search
    | RunnableLambda(lambda x:
       {
           'research_summary': '\n\n'.join([i['summary'] for i in x]),
           'user_question': x[0]['user_question'] if len(x) > 0 else ''
        })
    | RESEARCH_REPORT_PROMPT_TEMPLATE | get_llm() | StrOutputParser()
)

Follow the LCEL expression from instruction selection through searches, parallel summaries, result gathering, and report generation. section 4.7.4

A straight chain is not always enough. Its linear flow makes it awkward to retry a search because too few summaries are relevant; implicit state also makes failures harder to track. For limited choices between next steps, a workflow can route work to a processor or have a controller assign tasks to workers. Whatever the arrangement, inspect ingestion and answering separately: poor chunking or retrieval can weaken the final answer even when later steps work. section 5.5.1 section 5.1.1 section 6.4

How AI Agents and Applications covers it

How deep it goes
Builds sequential and parallel LCEL chains from runnable components, then identifies where linear flow and implicit state make adaptation difficult.
Examples
Works through chunk-by-chunk summarization, a parallel web-research report, and document ingestion followed by retrieval-based question answering.
What it assumes
Introduces the Runnable interface and basic LCEL composition while assuming familiarity with Python functions and passing data between components.
What you can do after
Build it from scratch with LCEL and Runnable components, then test sub-chains and inspect intermediate results when behavior is brittle.
How it connects
Connects chains to prompt templates, output parsers, MapReduce, retrieval-augmented generation, and routed workflows.

Also explained in

Compare how 48 books explain pipeline →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of AI Agents and Applications. The section links point to the parts of the book it draws on.