Fix final state extraction for LangGraph

This commit is contained in:
2026-03-12 21:11:11 +00:00
parent 411c4c100d
commit a0175056bd
+6 -8
View File
@@ -492,17 +492,15 @@ Write ~{plan.word_count_target} words. Begin with chapter title.
config = {"configurable": {"thread_id": thread_id}}
# LangGraph stream returns dict of node_name -> state
# LangGraph stream - accumulate final state
result_state = initial_state
for node_output in self.graph.stream(initial_state, config):
# Get the state (last output is final)
# node_output is {node_name: state}
for key, state in node_output.items():
if isinstance(state, OpusGraphState):
final_state = state
if hasattr(state, 'stage'): # It's an OpusGraphState
result_state = state
if final_state:
return final_state
return initial_state
return result_state
def run_opus(