Orchestration Patterns for Agents

How to Structure Multi-Step Workflows

Orchestration is how you decide which tool runs when. There are three main patterns.

Pattern 1: Sequential Orchestration

Steps happen in a fixed order. Code controls the flow.

Flow: Step 1 -> Step 2 -> Step 3 -> Done

When to use: The workflow is always the same. Example: data pipeline (extract -> validate -> transform -> load).

Pros:

  • Simple and predictable
  • Cheap (LLM runs once)
  • Easy to debug

Cons:

  • Rigid, cannot adapt
  • If step 1 fails, you might not need steps 2 and 3

Example:

def sequential_workflow(csv_file):
  # Step 1: Read CSV
  data = read_csv(csv_file)
  
  # Step 2: Validate
  data = validate_data(data)
  
  # Step 3: Transform
  data = clean_data(data)
  
  # Step 4: Load
  save_to_database(data)
  
  return "Complete"

Pattern 2: Router Orchestration

The model picks which tool to call based on the input. The code does not decide.

Flow: Model looks at input -> Model picks Tool A or Tool B or Tool C -> Execute -> Done

When to use: Different inputs need different handling. Example: customer support (question about orders -> order lookup; question about shipping -> shipping tool; etc.).

Pros:

  • Flexible, adapts to input
  • Model decides based on context

Cons:

  • Model might pick the wrong tool
  • More expensive (LLM runs multiple times)
  • Harder to debug

Example:

def router_workflow(user_question):
  # Let the LLM decide which tool to use
  tool_choice = model.decide_tool(
    question=user_question,
    tools=["order_lookup", "shipping_info", "billing_help"]
  )
  
  if tool_choice == "order_lookup":
    return lookup_order(user_question)
  elif tool_choice == "shipping_info":
    return get_shipping_info(user_question)
  elif tool_choice == "billing_help":
    return handle_billing(user_question)

Pattern 3: Planner Orchestration

The model creates a plan first, then executes it step by step.

Flow: Model creates plan -> Step 1 -> Step 2 -> Step 3 -> Done

When to use: Complex tasks where the model needs to think through the problem. Example: research (plan: search background, search recent, search competitors, then synthesize).

Pros:

  • Model can handle complex tasks
  • Model can adjust the plan mid-execution
  • More intelligent than sequential

Cons:

  • More expensive (multiple LLM calls)
  • More complex to implement
  • Harder to debug

Example:

def planner_workflow(goal):
  # Step 1: Create a plan
  plan = model.create_plan(goal)
  # plan = ["search background", "search recent", "search competitors", "synthesize"]
  
  results = []
  
  # Step 2: Execute the plan
  for step in plan:
    if step == "search background":
      results.append(search("background on " + goal))
    elif step == "search recent":
      results.append(search("latest " + goal))
    elif step == "search competitors":
      results.append(search("competing " + goal))
    elif step == "synthesize":
      results.append(synthesize(results))
  
  return results[-1]  # Return final result

Comparison Table

PatternCostComplexityFlexibilityUse When
SequentialLowLowLowSteps always the same
RouterMediumMediumMediumPick a tool based on input
PlannerHighHighHighComplex multi-step task

Hybrid: Sequential with Branching

You can combine patterns. Example: mostly sequential, but with conditional branches.

Flow: Step 1 -> Check result -> If A, do Step 2A; If B, do Step 2B -> Step 3 -> Done

Example:

def hybrid_workflow(user_question):
  # Step 1: Search
  results = web_search(user_question)
  
  # Branch: Check if we found enough results
  if len(results) < 3:
    # Try a different search
    results = web_search(user_question, num_results=10)
  
  # Step 2: Fetch
  for result in results[:3]:
    content = fetch_webpage(result["url"])
  
  # Step 3: Summarize and return
  return summarize_all(content)

When to Use Each Pattern

Sequential:

  • ETL pipeline (Extract -> Transform -> Load)
  • Content workflow (Write -> Review -> Publish)
  • Data processing (Read -> Validate -> Clean -> Save)

Router:

  • Customer support (route to right department)
  • Classification (categorize user input)
  • API routing (send to right API based on request)

Planner:

  • Research assistant (plan: search, read, synthesize)
  • Project planning (break goal into tasks, execute)
  • Complex automation (multi-step with decision points)

Start Simple, Add Complexity

  1. Start with sequential (simplest).
  2. If too rigid, try a router.
  3. If you need planning, use planner.

Don't use a complex pattern if simple one works.

Discussion

  • Loading…

← Back to Tutorials