langgraph4j icon indicating copy to clipboard operation
langgraph4j copied to clipboard

Unexpected Behavior in updateState During 'Wait for User Input' Scenario

Open hide212131 opened this issue 1 year ago • 6 comments
trafficstars

I have created a Java Notebook based on LangGraph's 'Wait for user input - Simple Usage' page. However, after interrupting once and then receiving user feedback, functions like updateState and getNext do not seem to behave as expected.

I have uploaded the Java Notebook here. The expected value for graph.getState(config).getNext() is 'step_3', but it remains 'human_feedback' regardless of the config value.

hide212131 avatar Sep 06 '24 15:09 hide212131

@hide212131 thanks for this valuable feedback.

You must change:

var updateConfig = graph.updateState(invokeConfig, mapOf("user_feedback", userInput), "human_feedback");

With

var updateConfig = graph.updateState(invokeConfig, mapOf("user_feedback", userInput), null);

the last argument to graph.updateState is asNode which applies the update as if it were performed by the specified node

bsorrentino avatar Sep 06 '24 16:09 bsorrentino

@bsorrentino could you help me with the same problem? I didn't want to create a new issue. I tried converting the "Wait for User Input — Simple Usage" page to a REST API and created this repository: https://github.com/thrkrdk/langgraph4j-agent-interrupt.

I want to try this scenario:

User: How is the weather today? Agent: Which country do you live in? User: Germany Agent: For which city would you like the forecast? User: Berlin Agent: The temperature in Berlin is 35 °C.

I'm having trouble with the second step. I could not pass the "For which city would you like the forecast?" step.

in postman: first request and response:

Image

second request and response:

Image

third request and response:

Image

krdk01 avatar May 23 '25 12:05 krdk01

@bsorrentino could you help me with the same problem? I didn't want to create a new issue. I tried converting the "Wait for User Input — Simple Usage" page to a REST API and created this repository: https://github.com/thrkrdk/langgraph4j-agent-interrupt

I want to try this scenario:

User: How is the weather today? Agent: Which country do you live in? User: Germany Agent: For which city would you like the forecast? User: Berlin Agent: The temperature in Berlin is 35 °C.

I'm having trouble with the second step. I could not pass the "For which city would you like the forecast?" step.

in postman: first request and response:

Image

second request and response:

Image

third request and response:

Image

here is application log:

assistant: com.langgraph4j.agent.interrupt.langgraph.QAAssistant@43de2fac question: what's the weather today? askCountry node is working. State: {country=, messages=, question=what's the weather today?, city=} data: {country=, messages=, question=what's the weather today?, city=} data: {country=, messages=Which country do you live in?, question=what's the weather today?, city=} snap: StateSnapshot{node=ask_country, state={country=, messages=Which country do you live in?, question=what's the weather today?, city=}, config=RunnableConfig{ threadId=e7eea8b4-8d93-4b8e-bd3c-674f51f0b85a, checkPointId=95c8a55b-95be-4814-aa0d-8700ed82eaf8, nextNode=wait_for_country, streamMode=SNAPSHOTS }} assistant: com.langgraph4j.agent.interrupt.langgraph.QAAssistant@43de2fac assistant: com.langgraph4j.agent.interrupt.langgraph.QAAssistant@43de2fac input: Germany config after updateState: RunnableConfig{ threadId=e7eea8b4-8d93-4b8e-bd3c-674f51f0b85a, checkPointId=95c8a55b-95be-4814-aa0d-8700ed82eaf8, nextNode=null, streamMode=SNAPSHOTS } waitForCountry node is working. State: {country=Germany, messages=Which country do you live in?, question=what's the weather today?, city=} askCity node is working. State: {country=Germany, messages=Which country do you live in?, question=what's the weather today?, city=} data: {country=Germany, messages=Which country do you live in?, question=what's the weather today?, city=} data: {country=Germany, messages=For which city would you like the forecast?, question=what's the weather today?, city=} snap: StateSnapshot{node=ask_country, state={country=Germany, messages=Which country do you live in?, question=what's the weather today?, city=}, config=RunnableConfig{ threadId=e7eea8b4-8d93-4b8e-bd3c-674f51f0b85a, checkPointId=95c8a55b-95be-4814-aa0d-8700ed82eaf8, nextNode=wait_for_country, streamMode=SNAPSHOTS }} assistant: com.langgraph4j.agent.interrupt.langgraph.QAAssistant@43de2fac assistant: com.langgraph4j.agent.interrupt.langgraph.QAAssistant@43de2fac input: Berlin config after updateState: RunnableConfig{ threadId=e7eea8b4-8d93-4b8e-bd3c-674f51f0b85a, checkPointId=95c8a55b-95be-4814-aa0d-8700ed82eaf8, nextNode=null, streamMode=SNAPSHOTS } waitForCountry node is working. State: {country=Germany, messages=Which country do you live in?, question=what's the weather today?, city=Berlin} askCity node is working. State: {country=Germany, messages=Which country do you live in?, question=what's the weather today?, city=Berlin} data: {country=Germany, messages=Which country do you live in?, question=what's the weather today?, city=Berlin} data: {country=Germany, messages=For which city would you like the forecast?, question=what's the weather today?, city=Berlin} snap: StateSnapshot{node=ask_country, state={country=Germany, messages=Which country do you live in?, question=what's the weather today?, city=Berlin}, config=RunnableConfig{ threadId=e7eea8b4-8d93-4b8e-bd3c-674f51f0b85a, checkPointId=95c8a55b-95be-4814-aa0d-8700ed82eaf8, nextNode=wait_for_country, streamMode=SNAPSHOTS }}

krdk01 avatar May 23 '25 12:05 krdk01

Hi @thrkrdk I'm working on to provide you the fix. the problem there, is get always the last snapshot

bsorrentino avatar May 23 '25 14:05 bsorrentino

Hi @thrkrdk I've create a PR#1 on your project with the fix.

Now we have also discord channel for discuss about it

bsorrentino avatar May 24 '25 13:05 bsorrentino

Thank you for your support, @bsorrentino. It's working as expected.

In my country, Discord is banned due to attempts at serial killing. So I am unable to join the Discord channel.

krdk01 avatar May 25 '25 06:05 krdk01