Class AgentStateRestorer

java.lang.Object
io.agentscope.spring.boot.admin.snapshot.AgentStateRestorer

public final class AgentStateRestorer extends Object
Copies the mutable fields of a snapshotted AgentState back into a live one.

Why a copy instead of a swap: ReActAgent holds its AgentState in a private final field, so we cannot replace the instance from outside. The next best thing is a field-by-field overwrite of everything that has a setter or is itself mutable.

Coverage:

  • summary — overwritten via setter
  • replyId — overwritten via setter
  • curIter — overwritten via setter
  • shutdownInterrupted — overwritten via setter
  • context — cleared and refilled in-place

The sub-context records (permissionContext, toolContext, tasksContext, planModeContext) are not restored — they would need additional core support to be swappable mid-run. Currently this matches the scope of session:compact (which only mutates summary + context); broader undo coverage tracks the AgentState refactor in project_java-agentstate-refactor.md.

  • Method Details

    • restore

      public static void restore(io.agentscope.core.state.AgentState live, String snapshotJson)
      Restore the live AgentState from a snapshot.
      Parameters:
      live - the agent's current state (mutated in place)
      snapshotJson - JSON produced by AgentState.toJson()
      Throws:
      IllegalArgumentException - if the JSON is invalid or targets a different session