AgentStateRestorer
public final class AgentStateRestorer
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)
执行 restore 方法。
Restore the live AgentState from a snapshot.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
live | AgentState | live(类型 `AgentState`)。the agent's current state (mutated in place) |
snapshotJson | String | 快照 JSON(类型 `String`)。JSON produced by `AgentState#toJson()` |
IllegalArgumentException可能抛出 `IllegalArgumentException`。if the JSON is invalid or targets a different session
io/agentscope/spring/boot/admin/snapshot/AgentStateRestorer.java:54–81