Sequential Pattern

A linear workflow where each agent processes the output from the previous agent, ideal for intent refinement, multi-step validation, or staged content creation.

Overview

Sequential compositions shine when work must pass through clearly defined stages. Each agent can tighten the scope, enrich the data, or validate the previous step before passing the baton.

Demo Scenario: Refine Then Answer

Two lightweight agents collaborate on a user question using gllm-pipeline:

  1. Intent refiner โ€“ rewrites the user's short prompt into a clear question

  2. Answerer โ€“ provides the final response using the refined question

The pipeline automatically passes the output from the refiner as input to the answerer, eliminating manual data passing.

Diagram

spinner

Implementation Steps

  1. Create agents

    from glaip_sdk import Agent
    
    refiner_agent = Agent(
        name="refiner_agent",
        instruction="Rewrite ambiguous input as clear question...",
        model="openai/gpt-5-mini"
    )
    
    answerer_agent = Agent(
        name="answerer_agent",
        instruction="Answer coding questions with code...",
        model="openai/gpt-5-mini"
    )
  2. Chain steps with pipe operator

    from gllm_pipeline.steps import step
    
    pipeline = refine_step | answer_step
    pipeline.state_type = State
  3. Run the pipeline

    result = await pipeline.invoke(state)
    print(result['final_answer'])

Full implementation: See sequential/main.py for complete code with State definition and step configuration.

AgentComponent: See the Agent as Component guide for details on the .to_component() pattern.

How to Run

From the glaip/examples/multi-agent-system-patterns directory in the GL SDK Cookbookarrow-up-right:

Set the usual environment variables in .env:

Output

  1. List of non-strings (integers) โ€” convert elements first

  1. Quick Python-looking representation โ€” use str()

  1. JSON output โ€” use json.dumps()

...

Demo completed

Last updated