Performance: Sequential chains
Sequential chains affect the latency and throughput of processing multiple steps in a language model workflow, impacting user wait time and responsiveness.
Jump into concepts and practice - no test required
from langchain.schema.runnable import RunnableParallel chain = RunnableParallel({"a": chainA, "b": chainB, "c": chainC}) result = chain.invoke(input_data)
chain1 = SequentialChain(chains=[chainA, chainB, chainC]) result = chain1.run(input_data)
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Sequential chain (one after another) | Minimal DOM changes | 0 reflows | Low paint cost | [!] OK but blocks input responsiveness |
| Concurrent chain (parallel execution) | Minimal DOM changes | 0 reflows | Low paint cost | [OK] Improves input responsiveness |
SequentialChain in Langchain?SequentialChain with two chains named chain1 and chain2?from langchain.chains import SequentialChain
chain1 = SomeChain() # outputs {'intermediate': 'hello'}
chain2 = SomeChain() # expects input 'intermediate' and outputs {'final': 'hello world'}
seq_chain = SequentialChain(chains=[chain1, chain2], input_variables=['input'], output_variables=['final'])
result = seq_chain.run({'input': 'start'})
print(result)seq_chain = SequentialChain(chains=[chain1, chain2], input_variables=['input'])
result = seq_chain.run({'input': 'data'})