AS AgentScopeAPI 手册 / API Reference

AgentStateRestorer

public final class AgentStateRestorer
源码Source io/agentscope/spring/boot/admin/snapshot/AgentStateRestorer.java:43–82

智能体状态 Restorer,承载智能体的部署、调度与服务化运行。位于 io.agentscope.spring.boot.admin.snapshot 包。核心成员包括 restore。

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 Summary

方法Method说明Description
public static void restore(AgentState live, String snapshotJson)
static
执行 `restore` 方法。
Restore the live `AgentState` from a snapshot.

方法详情Method Detail

restore

public static void restore(AgentState live, String snapshotJson)
static

执行 restore 方法。

Restore the live AgentState from a snapshot.

参数Parameters
名称Name类型Type说明Description
liveAgentStatelive(类型 `AgentState`)。the agent's current state (mutated in place)
snapshotJsonString快照 JSON(类型 `String`)。JSON produced by `AgentState#toJson()`
抛出Throws
  • IllegalArgumentException 可能抛出 `IllegalArgumentException`。if the JSON is invalid or targets a different session
源码Source io/agentscope/spring/boot/admin/snapshot/AgentStateRestorer.java:54–81
基于官方固定版本源码静态生成Generated from pinned official sources · Python 2.0.11 · Java 2.0.4
签名与文档为静态抽取;如有疑问请以源码为准。Signatures and docs are extracted statically; verify against the source when in doubt.