Fix return bug - use invoke + stream fallback
This commit is contained in:
@@ -492,17 +492,34 @@ Write ~{plan.word_count_target} words. Begin with chapter title.
|
|||||||
|
|
||||||
config = {"configurable": {"thread_id": thread_id}}
|
config = {"configurable": {"thread_id": thread_id}}
|
||||||
|
|
||||||
# LangGraph stream - accumulate final state
|
# Use invoke instead of stream for clean return
|
||||||
result_state = initial_state
|
try:
|
||||||
for node_output in self.graph.stream(initial_state, config):
|
result = self.graph.invoke(initial_state, config)
|
||||||
# node_output is {node_name: state}
|
if isinstance(result, OpusGraphState):
|
||||||
# Last node should be 'complete' with full state
|
print(f"\n✅ COMPLETE! Chapters: {len(result.chapters)}, Words: {result.total_word_count}")
|
||||||
for key, state in node_output.items():
|
return result
|
||||||
if hasattr(state, 'stage'):
|
elif isinstance(result, dict):
|
||||||
result_state = state
|
# Get the state from dict
|
||||||
|
for key, value in result.items():
|
||||||
|
if isinstance(value, OpusGraphState):
|
||||||
|
print(f"\n✅ COMPLETE! Chapters: {len(value.chapters)}, Words: {value.total_word_count}")
|
||||||
|
return value
|
||||||
|
except Exception as e:
|
||||||
|
print(f"Error with invoke: {e}")
|
||||||
|
|
||||||
# Debug: print what we got
|
# Fallback: try stream
|
||||||
print(f"\n[DEBUG] Final state - chapters: {len(result_state.chapters)}, words: {result_state.total_word_count}")
|
result_state = initial_state
|
||||||
|
try:
|
||||||
|
for node_output in self.graph.stream(initial_state, config):
|
||||||
|
for key, state in node_output.items():
|
||||||
|
if hasattr(state, 'stage'):
|
||||||
|
result_state = state
|
||||||
|
if hasattr(state, 'manuscript') and state.manuscript:
|
||||||
|
print(f"\n[STREAM] Chapter {state.current_chapter}: {state.total_word_count} words")
|
||||||
|
except Exception as e:
|
||||||
|
print(f"Stream error: {e}")
|
||||||
|
|
||||||
|
print(f"\n[DEBUG] Returning state - chapters: {len(result_state.chapters)}, words: {result_state.total_word_count}")
|
||||||
|
|
||||||
return result_state
|
return result_state
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user