Resuming and Restoring Agent State

Lesson 2 of 4

Resume from the Confirmed Point

Estimated time: 10 minutes

Resume a session without replaying everything

A session that is dropped mid run can usually be picked up again, but the value of a resume depends on knowing what was already done. Resuming from the last message received replays work that already happened.

Store what was confirmed

Keep a record of what the session has confirmed, not of what it last received. The confirmed point is the one place a resume can trust.

Apply each effect once

A resumed run has to treat its effects the same way a fresh run does, applied once. Without that, the same step is carried out twice while the caller sees only one reply, so the duplicate is invisible from outside.

def resume_point(session):
    return session.confirmed_at or None

Expire a stale session

A saved point that is very old describes a world that has moved on. Starting fresh is safer than resuming into a view that no longer holds.