updated state can not be catched during workflow execution #478

Closed
opened 2026-02-20 17:40:19 -05:00 by yindo · 4 comments
Owner

Originally created by @funnykeke on GitHub (Feb 27, 2025).

Checked other resources

  • This is a bug, not a usage question. For questions, please use GitHub Discussions.
  • I added a clear and detailed title that summarizes the issue.
  • I read what a minimal reproducible example is (https://stackoverflow.com/help/minimal-reproducible-example).
  • I included a self-contained, minimal example that demonstrates the issue INCLUDING all the relevant imports. The code run AS IS to reproduce the issue.

Example Code

def main():
    graph = entity_extract_workflow.build_workflow()
    state = {
        "document_path": PDF_PATH,
        "schema_tool": schema_reader_tool,
    }
    try:
        events = graph.stream(state, config={"recursion_limit": 5000000000})
        for s in events:
            print(s)
        print("----")
    except Exception as e:
        logger.get_logger().error(f"An error occurred: {e}")
        now = datetime.datetime.now()
        output_data = {'entities': state.get('entities', [])}
        path = Path(__file__).resolve().parent / 'knowledge_data' / f'{now.strftime("%Y_%m_%d_%H_%M_")}entities.json'
        with open(path, 'w', encoding='utf-8') as f:
            json.dump(output_data, f, ensure_ascii=False, indent=2)
        logger.get_logger().info(f"Entities saved to {path}")

Error Message and Stack Trace (if applicable)


Description

I have encountered an issue where the state variable remains unchanged from its initial values and does not get updated during the execution of the workflow. As a result, when I try to access the state in the try block, it does not reflect the updates from the workflow.

Here is a simplified version of my code:
how can i catch the updated state outside?

System Info

how can i catch the updated state?

Originally created by @funnykeke on GitHub (Feb 27, 2025). ### Checked other resources - [x] This is a bug, not a usage question. For questions, please use GitHub Discussions. - [x] I added a clear and detailed title that summarizes the issue. - [x] I read what a minimal reproducible example is (https://stackoverflow.com/help/minimal-reproducible-example). - [x] I included a self-contained, minimal example that demonstrates the issue INCLUDING all the relevant imports. The code run AS IS to reproduce the issue. ### Example Code ```python def main(): graph = entity_extract_workflow.build_workflow() state = { "document_path": PDF_PATH, "schema_tool": schema_reader_tool, } try: events = graph.stream(state, config={"recursion_limit": 5000000000}) for s in events: print(s) print("----") except Exception as e: logger.get_logger().error(f"An error occurred: {e}") now = datetime.datetime.now() output_data = {'entities': state.get('entities', [])} path = Path(__file__).resolve().parent / 'knowledge_data' / f'{now.strftime("%Y_%m_%d_%H_%M_")}entities.json' with open(path, 'w', encoding='utf-8') as f: json.dump(output_data, f, ensure_ascii=False, indent=2) logger.get_logger().info(f"Entities saved to {path}") ``` ### Error Message and Stack Trace (if applicable) ```shell ``` ### Description I have encountered an issue where the state variable remains unchanged from its initial values and does not get updated during the execution of the workflow. As a result, when I try to access the state in the try block, it does not reflect the updates from the workflow. Here is a simplified version of my code: how can i catch the updated state outside? ### System Info how can i catch the updated state?
yindo added the invalid label 2026-02-20 17:40:19 -05:00
yindo closed this issue 2026-02-20 17:40:19 -05:00
Author
Owner

@vbarda commented on GitHub (Feb 27, 2025):

i am not sure i understand the problem, perhaps you can add a better example that illustrates the issue? if you are just trying to stream updates, you can specify stream_mode = "updates" https://langchain-ai.github.io/langgraph/how-tos/streaming/#updates

@vbarda commented on GitHub (Feb 27, 2025): i am not sure i understand the problem, perhaps you can add a better example that illustrates the issue? if you are just trying to stream updates, you can specify stream_mode = "updates" https://langchain-ai.github.io/langgraph/how-tos/streaming/#updates
Author
Owner

@funnykeke commented on GitHub (Feb 27, 2025):

i am not sure i understand the problem, perhaps you can add a better example that illustrates the issue? if you are just trying to stream updates, you can specify stream_mode = "updates" https://langchain-ai.github.io/langgraph/how-tos/streaming/#updates

I would like to save the latest state when the graph encounters an error. The nodes in the graph update this state as part of the process. However, based on my current code, I noticed that the state always remains as its initial value:

state = {
    "document_path": PDF_PATH,
    "schema_tool": schema_reader_tool,
}

Even when debugging, I found that the value of the state variable never changes. I would like to capture the latest updates made by the nodes. How can I retrieve the most recent state?

@funnykeke commented on GitHub (Feb 27, 2025): > i am not sure i understand the problem, perhaps you can add a better example that illustrates the issue? if you are just trying to stream updates, you can specify stream_mode = "updates" https://langchain-ai.github.io/langgraph/how-tos/streaming/#updates I would like to save the latest state when the graph encounters an error. The nodes in the graph update this state as part of the process. However, based on my current code, I noticed that the state always remains as its initial value: ``` state = { "document_path": PDF_PATH, "schema_tool": schema_reader_tool, } ``` Even when debugging, I found that the value of the state variable never changes. I would like to capture the latest updates made by the nodes. How can I retrieve the most recent state?
Author
Owner

@vbarda commented on GitHub (Feb 28, 2025):

it would be helpful to see minimal reproducible example of the issue. if you want to recover from the errors you need to use a checkpointer https://langchain-ai.github.io/langgraph/how-tos/persistence/ https://langchain-ai.github.io/langgraph/concepts/persistence/

@vbarda commented on GitHub (Feb 28, 2025): it would be helpful to see minimal reproducible example of the issue. if you want to recover from the errors you need to use a checkpointer https://langchain-ai.github.io/langgraph/how-tos/persistence/ https://langchain-ai.github.io/langgraph/concepts/persistence/
Author
Owner

@vbarda commented on GitHub (Mar 11, 2025):

Closing due to inactivity - feel free to reopen or create a new issue with more information

@vbarda commented on GitHub (Mar 11, 2025): Closing due to inactivity - feel free to reopen or create a new issue with more information
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langchain-ai/langgraph#478