Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

updated state can not be catched during workflow execution #3618

Open
4 tasks done
funnykeke opened this issue Feb 27, 2025 · 3 comments
Open
4 tasks done

updated state can not be catched during workflow execution #3618

funnykeke opened this issue Feb 27, 2025 · 3 comments
Labels
invalid This doesn't seem right

Comments

@funnykeke
Copy link

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?

@vbarda
Copy link
Collaborator

vbarda commented 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 vbarda added the invalid This doesn't seem right label Feb 27, 2025
@funnykeke
Copy link
Author

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?

@vbarda
Copy link
Collaborator

vbarda commented 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/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
invalid This doesn't seem right
Projects
None yet
Development

No branches or pull requests

2 participants