Fix/sequential chain intermediate outputs#1476
Draft
Conversation
SequentialChain.Call() was replacing the inputs map with each chain's output (inputs = outputs), losing all intermediate values. This meant intermediate outputs like 'synopsis' were nil when accessed from the final result, even if declared in outputKeys. The fix accumulates all known values (original inputs + each chain's outputs) through the execution loop, then returns only the declared outputKeys from the accumulated map. Fixes tmc#1095 Co-Authored-By: ljluestc <ljluestc@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
fix: accumulate intermediate outputs in SequentialChain
Fixes #1095
Problem
When using
SequentialChain, intermediate chain outputs are lost and returnnil. For example:Root Cause
In
SequentialChain.Call(), the lineinputs = outputsreplaces the entire accumulated state with only the current chain's output map:Execution trace:
{title, era}→ outputs{synopsis}inputs = {synopsis}— title and era are lost{synopsis}→ outputs{review}inputs = {review}— synopsis is lost{review}— synopsis isnilThis also means a later chain cannot reference an earlier (non-adjacent) chain's output. For example, if chain3 needed both
titleandreview, it would fail with a missing input key error.Fix
Accumulate all known values (original inputs + each chain's outputs) through the loop, then return only the declared
outputKeys:This is consistent with how Python LangChain's
SequentialChainworks — it accumulates all known variables and passes the full dict to each sub-chain.Diff
What Changed
chains/sequential.go— FixedSequentialChain.Call()to accumulate values across chainschains/sequential_test.go— AddedTestSequentialChainIntermediateOutputsreproducing issue how to get chain1.output in sequentialChainExample #1095How to Test
1. Build
2. Run the new + existing tests
Expected output:
3. Manual verification
4. Full test suite
go test ./chains/ -count=1 -timeout 60sUser Impact
outputKeyswill now correctly receive those valuesoutputKeyscontract is preserved