Time Travel
Rewinding an agent.
An agent refunded nine hundred dollars by mistake. What went wrong? With a normal program, you'd read logs, and guess. But we saved every step. So we can rewind to the moment before the mistake, change one thing, and run it again.

- A $900 mistake
- We saved every step
- Rewind, change, rerun
Rewind and fix
This agent decides on nine hundred dollars. We can list every saved step. We find the moment just before it acted. We change the amount to forty, which creates a new branch of history. Then we continue from there. Run it. The first run refunded nine hundred. Then, from the same point, with one change, forty. The original history is still there. It's like version control for an agent's decisions.
from typing import TypedDict
from langgraph.checkpoint.memory import InMemorySaver
from langgraph.graph import StateGraph, START, END
class State(TypedDict):
amount: int
note: str
g = StateGraph(State)
g.add_node("decide", lambda s: {"amount": 900})
g.add_node("act", lambda s: {"note": f"Refunded {s['amount']}"})
g.add_edge(START, "decide")
g.add_edge("decide", "act")
g.add_edge("act", END)
app = g.compile(checkpointer=InMemorySaver())
t = {"configurable": {"thread_id": "1"}}
print("First run:", app.invoke({"amount": 0, "note": ""}, t)["note"])
history = list(app.get_state_history(t))
print("Saved steps:", len(history))
before_act = next(s for s in history if s.next == ("act",))
fixed = app.update_state(before_act.config, {"amount": 40})
print("Rerun:", app.invoke(None, fixed)["note"])First run: Refunded 900 Saved steps: 4 Rerun: Refunded 40
What time travel is for
This isn't just a party trick. You can debug by replaying a failed run, and seeing the state at each step. You can test a new prompt from a certain point, without repeating the costly early steps. You can try what if questions. And support people can fix a stuck case by hand. But remember, it rewinds the agent's state, not the real world. A refund that's been paid stays paid.
Summary
Graphs give you pause, resume, streaming, and time travel. That's LangGraph. You can now build one very capable agent. So what about many of them? Next, multi-agent systems.
Key takeaways- Every step can be replayed
- update_state creates a branch
- The real world doesn't rewind