diagram-projectMulti-Model & Multi-Step

Multi-step workflows, leveraging different models' strengths, and building reusable pipeline templates.

🎭 Multi-Step Workflows

Pipelines excel at orchestrating distinct phases, where each stage has a focused role.

Draft-Refine Pattern

Use a fast model for initial drafts, then refine with a stronger model:

// Stage 1: fast draft
drafter = aiMessage()
    .system( "Generate quick content drafts" )
    .user( "Write about: ${topic}" )
    .to( aiModel( "openai", { model: "gpt-4o-mini" } ) )
    .transform( r => r.content )

// Stage 2: quality refinement
refiner = aiMessage()
    .system( "Improve and expand content while maintaining the core message" )
    .user( "Enhance this draft: ${draft}" )
    .to( aiModel( "openai", { model: "gpt-4o" } ) )
    .transform( r => r.content )

topic  = "AI in healthcare"
draft  = drafter.run( { topic: topic } )
refined = refiner.run( { draft: draft } )

Benefits:

  • Faster initial generation (cheap model)

  • Higher quality final output (stronger model)

  • Cost optimization — only use the expensive model for refinement

Analysis-Enhancement Pattern

Analyze content first, then generate a tailored response:

Validation Pipeline

Generate, validate, then retry if needed:


🔀 Multi-Model Pipelines

Model Specialization

Use each model for what it does best:

Dynamic Model Selection

Choose the model at runtime based on task characteristics:


♻️ Reusable Templates

One of the most powerful features of pipelines is reusability — define once, execute with different inputs.

Parameterized Pipelines

Create templates that accept different inputs on every run:

Pipeline Factories

Generate customized pipelines on demand:

Composable Building Blocks

Build complex pipelines from small, reusable components:

Last updated