Multi-LLM Workflows
Simple Sequential Chains used one ChatOpenAI for both steps. Here you use two — gpt-4o-mini to pick a tag, gpt-4o to write the explanation. Same pipe layout; you change which model sits on each step.
Two model variables
Create fast_model and smart_model, then plug each into the step that needs it. One chain.invoke — step 1 calls mini, step 2 calls gpt-4o.
Each step can call a different model:
input
{ feature: "links" }
step 1
gpt-4o-mini
string
"a"
step 2
gpt-4o
output
explanation
ChatOpenAI on each step.Compared to Simple Sequential
The chain line is the same. Instead of reusing one model, you attach fast_model to pick and smart_model to explain.
model = ChatOpenAI(
model="gpt-4o-mini"
)
chain = pick_chain
| explain_prompt
| model
| parserSame model for every step
Multi-LLM Workflow
fast_model = ChatOpenAI(
model="gpt-4o-mini"
)
smart_model = ChatOpenAI(
model="gpt-4o"
)
chain = pick_chain
| explain_prompt
| smart_model
| parsermini on pick, gpt-4o on explain
ChatOpenAI instance you attach changes per step.Model split in this demo
Pick returns a single tag name. Explain asks for two sentences and an example — worth the larger model. Temperature and token limits per client are covered in Model Parameters.
| Step | Model | Task |
|---|---|---|
| Pick tag | gpt-4o-mini | Return one tag name |
| Explain tag | gpt-4o | Two sentences + HTML example |
What each step does
pick_chain—pick_prompt | fast_model | parser. Input{"feature": "links"}, output tag string.explain_prompt | smart_model | parser— input that string as{tag}, output the explanation.
The demo script
multi_llm_workflows_demo.py runs the chain for links and images.
Download the code
multi_llm_workflows_demo.py
gpt-4o-mini → gpt-4o
langchain-course folder. Needs venv, .env, and packages from Project Setup.Run it
Activate the venv from Project Setup, then:
python multi_llm_workflows_demo.pygpt-4o-mini. Step 2: gpt-4o.When to split models
- The first step is short or mechanical (pick a tag, classify, extract a value) — mini keeps the bill down.
- The second step needs longer or clearer writing — put gpt-4o (or similar) only on that step.
- OpenAI client options: ChatOpenAI integration.
What's Next
Next: Output Formatting — parse model output into structured data.