Skip to course content
Free LangGraph course

LangGraph for Agentic Workflows

Unit 07.01: Letting a person edit the state

Review is more useful when the reviewer can change something. update_state lets them edit the state directly, and whatever runs next sees the correction.

Editing the value, not commenting on it

The reviewer reads the paused state, changes a field, and the graph continues from the corrected value. No re-prompting, no re-running earlier nodes.

The code pauses, reads a draft containing a factual error, and fixes it.

from typing import TypedDict
from langgraph.graph import StateGraph, START, END
from langgraph.checkpoint.memory import InMemorySaver


class State(TypedDict):
    draft: str
    approved: bool


g = StateGraph(State)
g.add_node("write", lambda s: {"draft": "refunds take 30 days"})
g.add_node("publish", lambda s: {"approved": True})
g.add_edge(START, "write")
g.add_edge("write", "publish")
g.add_edge("publish", END)
app = g.compile(checkpointer=InMemorySaver(), interrupt_before=["publish"])

config = {"configurable": {"thread_id": "edit-1"}}
app.invoke({"draft": "", "approved": False}, config)
print("before edit:", app.get_state(config).values["draft"])

app.update_state(config, {"draft": "refunds take 7 days"})
print("after edit :", app.get_state(config).values["draft"])

# The reviewer corrected a factual error in the state itself, not in a prompt.
# Whatever runs next sees the corrected value -- which is the difference between
# a review step and a comment box.

The draft said thirty days; the corrected state says seven. Whatever publish does next operates on the corrected string.

Compare this with the common alternative - showing the draft, collecting a comment, and asking the model to revise. That costs another model call, may introduce a new error while fixing the old one, and gives the reviewer no guarantee that their correction was applied. Editing the state applies it by construction.

The mistake this prevents

The mistake is letting a reviewer edit any field. Some state - the original question, the retry counter, a guard flag - is not theirs to change, and an edited counter can re-open a loop that had terminated. Decide which fields are editable and enforce it on the way in.

Takeaway

update_state makes review an edit rather than a comment. Restrict which fields a reviewer may change: guard flags and counters are not among them.