Pipeline Overview

Input: topic keyword
  │
  ├─ 1. KW Research  → top 20 keywords + search volumes
  ├─ 2. SERP Analysis → top 5 ranking articles analyzed
  ├─ 3. Outline      → H2/H3 structure with word targets per section
  │
  ├─ 4. [Parallel] Writing × sections
  │
  ├─ 5. Assembly     → merge + ensure flow between sections
  ├─ 6. Editing      → grammar, clarity, tone consistency
  ├─ 7. SEO Polish   → meta title, description, internal links
  │
  ├─ [Human approval gate] ← STOPS here for review
  │
  └─ 8. Publish      → POST to WordPress/Ghost CMS API

Pipeline YAML

# content-pipeline.yaml
name: content-production
version: "2.0"

steps:
  - id: kw_research
    agent: keyword-researcher
    input: {keyword: "{{ input.topic }}"}
    
  - id: serp_analysis
    agent: serp-analyzer
    input: {keywords: "{{ kw_research.top_5_keywords }}"}
    
  - id: outline
    agent: content-outliner
    input:
      topic: "{{ input.topic }}"
      keywords: "{{ kw_research.all_keywords }}"
      competitor_angles: "{{ serp_analysis.angles_not_covered }}"
      target_word_count: "{{ input.word_count | default(2000) }}"
    
  - id: write_sections
    type: parallel_for_each
    iterate_over: "{{ outline.sections }}"
    as: section
    agent: section-writer
    input:
      section_title: "{{ section.title }}"
      section_word_target: "{{ section.word_target }}"
      keywords_to_include: "{{ section.keywords }}"
      context: "{{ outline.brief }}"
    max_parallel: 4
    collect_as: raw_sections
    
  - id: assemble
    agent: content-assembler
    input:
      sections: "{{ raw_sections }}"
      intro_required: true
      conclusion_required: true
    
  - id: edit
    agent: editor
    input: {content: "{{ assemble.full_article }}"}
    
  - id: seo
    agent: seo-optimizer
    input:
      content: "{{ edit.polished_content }}"
      primary_keyword: "{{ input.topic }}"
      secondary_keywords: "{{ kw_research.top_5_keywords }}"
    
  - id: human_approval
    type: human_approval
    message: |
      Article ready for review:
      Title: {{ seo.meta_title }}
      Word count: {{ seo.word_count }}
      SEO score: {{ seo.score }}/100
      
      Preview: {{ seo.content[:500] }}...
    options: [approve, reject, edit]
    timeout_hours: 24
    
  - id: publish
    condition: "{{ human_approval.decision == 'approve' }}"
    tool: cms_publish
    params:
      title: "{{ seo.meta_title }}"
      content: "{{ seo.content }}"
      meta_description: "{{ seo.meta_description }}"
      categories: "{{ input.categories | default(['Blog']) }}"
      status: published

Running the Pipeline

openclaw pipeline run content-pipeline.yaml \
  --input '{
    "topic": "best python async frameworks 2025",
    "word_count": 2500,
    "categories": ["Python", "Frameworks"]
  }'

# Pipeline pauses at human_approval step
# You receive a Slack/email notification
# Approve at: openclaw pipeline approve <run-id>

What This Agent Does

This tutorial builds an agent that executes multi-step workflows — sequences of actions where the output of each step informs the next. The example workflow is a content pipeline: fetch a topic from a backlog, research it, write a draft, review the draft for quality, and save the final version. This same pattern applies to approval workflows, data transformation pipelines, and automated reporting chains.

Step 1 — Agent Configuration

Create workflow-agent.yaml:

agent:
  name: content-pipeline
  description: Executes a research-write-review content workflow
  system_prompt: |
    You are a content pipeline coordinator. You execute a structured
    workflow with the following stages:

    STAGE 1 — RESEARCH: Search for and read sources on the topic.
    Gather at least 5 relevant facts or data points.

    STAGE 2 — OUTLINE: Create a structured outline based on research.
    Get confirmation before drafting (unless auto-approve is set).

    STAGE 3 — DRAFT: Write a complete first draft following the outline.

    STAGE 4 — REVIEW: Review the draft against these criteria:
    - Is it factually accurate based on your research?
    - Does every claim have evidence from a source?
    - Is it clear and well-structured?
    Score each criterion 1-5 and provide a total quality score.

    STAGE 5 — FINALIZE: If quality score >= 12/15, save the final version.
    If below threshold, improve weak areas and re-review.

    Report your current stage at the start of each stage.

llm:
  model: claude-3-5-sonnet-20241022
  temperature: 0.4
  max_tokens: 8192

tools:
  - name: web_search
    enabled: true
  - name: web_fetch
    enabled: true
  - name: file_write
    enabled: true
    config:
      allowed_dirs:
        - ./output

agent:
  max_steps: 30

Step 2 — Run the Full Pipeline

openclaw run --config workflow-agent.yaml   --task "Execute the full content pipeline for this topic:
  'Best practices for securing AI agent deployments in 2024'
  Target: 600-word article for a technical blog audience.
  Auto-approve the outline stage and proceed through all stages automatically.
  Save the final article to output/ai-security-article.md"

As the agent runs, you'll see it announce each stage transition. The multi-stage process with self-review produces significantly better output than asking for a direct one-shot article.

Step 3 — Add Human-in-the-Loop Gates

For workflows where human review matters at specific points, use a gate mechanism. The agent writes its output to a file and waits for a confirmation flag file:

  system_prompt: |
    ...
    STAGE 2 — OUTLINE: Create the outline and save it to output/outline.md.
    Then check if output/outline-approved.txt exists. If not, output WAITING_FOR_APPROVAL
    and stop. Only proceed to drafting if the approval file exists.

Your deployment script creates the approval file after a human reviews the outline, then restarts the agent run for the remaining stages.

Step 4 — Error Handling and Recovery

Robust workflows need to handle partial failures. Add recovery logic to the system prompt:

    If any tool call fails, note the error, attempt an alternative approach
    (e.g., try a different search query if one returns no results), and
    continue the pipeline. If a stage cannot complete after 2 attempts,
    write a partial results file and report what was completed vs what failed.

Step 5 — Parameterized Workflow Templates

Make your workflow reusable by parameterizing it. Create a wrapper script that injects topic, audience, length, and output path into the task template. This lets anyone on your team trigger the full pipeline with a single command by just specifying the topic — the workflow handles everything else consistently every time it runs.

Troubleshooting

If the agent skips stages or collapses them together, break the system prompt into more explicit stage headers with numbered steps. If the quality gate is too strict and loops excessively, lower the threshold or add a maximum review iteration count. If the agent runs out of steps before completing all stages, increase max_steps — complex multi-source research pipelines can need 20–40 steps for quality output.

State Management Across Steps

In a multi-step workflow, each step may produce information that later steps need. Rather than passing everything through the LLM context (which gets expensive for long workflows), use structured state files. After each stage, have the agent write its findings to a JSON state file: workflow-state.json. Later stages read this file to access earlier results. This pattern keeps the LLM context focused on the current stage's work rather than carrying the full history of all previous stages, reducing token usage and improving performance for long workflows.

Define a workflow state schema at the start. Include fields for current stage, completed stages, intermediate results, and error state. A consistent schema means you can resume a partially completed workflow after an interruption by reading the state file and continuing from the last completed stage, rather than restarting from scratch. For expensive workflows (those with many LLM calls or slow tool operations), this resumability is valuable — a network interruption or API error halfway through shouldn't mean losing all completed work.

Conditional Branching

Real workflows have branches: if the research stage finds that the topic has been covered recently, skip the draft stage and output a note instead. If the quality review score is below threshold, route to a revision stage rather than finalize. Implement branching by having the agent evaluate a condition and write a decision to the state file, then making later stages conditional on that decision. The agent's natural language understanding makes condition evaluation straightforward — you describe conditions in plain English rather than writing code to evaluate them.

Workflow Observability

For production workflows, log each stage transition with its result and duration. A workflow that normally completes in 3 minutes but suddenly takes 15 minutes indicates a problem — probably a slow API response or a stuck tool call. Stage-level timing data reveals where time is spent, allowing you to optimize the slow stages first. Add a lightweight timing wrapper around each stage: record the start time, run the stage, record the end time, and append to the workflow log. This operational visibility is essential when workflows run automatically without human supervision.

Scaling Up Workflow Complexity

As you build confidence with simple linear workflows, progressively increase complexity. Add parallel stages for independent subtasks that don't depend on each other's output. Add conditional stages that only execute when previous stages produce certain results. Add retry logic for stages that interact with external services and may encounter transient failures. Each increase in complexity should be introduced one step at a time and tested thoroughly before the next addition — a complex workflow with multiple interacting components is hard to debug when multiple things change simultaneously. Build up from a simple linear workflow that works reliably to a complex orchestrated workflow with confidence at every step.