Checked other resources
Example Code
import { MemorySaver, Annotation, interrupt, Command, StateGraph } from "@langchain/langgraph";
// Define the graph state
const StateAnnotation = Annotation.Root({
some_text: Annotation<string>()
});
function humanNode(state: typeof StateAnnotation.State) {
const value = interrupt(
// Any JSON serializable value to surface to the human.
// For example, a question or a piece of text or a set of keys in the state
{
text_to_revise: "Do you wish to approve ?"
}
);
return {
// Update the state with the human's input
some_text: value
};
}
// Build the graph
const workflow = new StateGraph(StateAnnotation)
// Add the human-node to the graph
.addNode("human_node", humanNode)
.addEdge("__start__", "human_node")
// A checkpointer is required for `interrupt` to work.
const checkpointer = new MemorySaver();
const graph = workflow.compile({
checkpointer
});
const config = { configurable: { thread_id: "123" } };
// Using stream() to directly surface the `__interrupt__` information.
for await (const chunk of await graph.stream(
{ some_text: "Original text" },
config
)) {
console.log("Paused state", JSON.stringify(chunk));
}
// Resume using Command
for await (const chunk of await graph.stream(
new Command({ resume: "Edited text" }),
config
)) {
console.log(chunk);
}
This actually prints
Paused state {"__interrupt__":[{"value":{"text_to_revise":"Do you wish to approve ?"},"when":"during","resumable":true,"ns":["human_node:256ce302-2f0b-5ba8-8eba-ec02b2bb7a82"]}]}
{ human_node: { some_text: 'Edited text' } }
But when I use invoke for the execution
import { MemorySaver, Annotation, interrupt, Command, StateGraph } from "@langchain/langgraph";
// Define the graph state
const StateAnnotation = Annotation.Root({
some_text: Annotation<string>()
});
function humanNode(state: typeof StateAnnotation.State) {
const value = interrupt(
// Any JSON serializable value to surface to the human.
// For example, a question or a piece of text or a set of keys in the state
{
text_to_revise: "Do you wish to approve ?"
}
);
return {
// Update the state with the human's input
some_text: value
};
}
// Build the graph
const workflow = new StateGraph(StateAnnotation)
// Add the human-node to the graph
.addNode("human_node", humanNode)
.addEdge("__start__", "human_node")
// A checkpointer is required for `interrupt` to work.
const checkpointer = new MemorySaver();
const graph = workflow.compile({
checkpointer
});
const config = { configurable: { thread_id: "123" } };
const result = await graph.invoke({ some_text: "Original text" },config);
console.log("Paused state", JSON.stringify(result));
// Resume using Command
for await (const chunk of await graph.stream(
new Command({ resume: "Edited text" }),
config
)) {
console.log(chunk);
}
I am getting only the state where it is paused
Paused state {"some_text":"Original text"}
{ human_node: { some_text: 'Edited text' } }
Error Message and Stack Trace (if applicable)
No response
Description
- Using the streaming it is actually working
- But using invoke it is not working
System Info
Linux
TS
NodeJS 18
Checked other resources
Example Code
This actually prints
But when I use invoke for the execution
I am getting only the state where it is paused
Error Message and Stack Trace (if applicable)
No response
Description
System Info
Linux
TS
NodeJS 18