Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3841,8 +3841,9 @@ public static Builder builder() {

@Override
public void close() {
// No-op for the core ReActAgent. Subclasses / wrappers (HarnessAgent) may release
// additional resources here.
// Release the ShutdownStateSaver registered in the constructor so that ephemeral /
// per-call agent instances are not retained by GracefulShutdownManager.stateSavers.
shutdownManager.unbindStateSaver(this);
}

// ==================== Builder ====================
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,22 @@ public void bindStateSaver(Agent agent, ShutdownStateSaver saver) {
stateSavers.put(agent.getAgentId(), saver);
}

/**
* Remove the {@link ShutdownStateSaver} previously registered for the given agent.
*
* <p>Must be called from {@link io.agentscope.core.ReActAgent#close()} (or equivalent
* lifecycle hook) so that ephemeral / per-call agent instances do not accumulate
* indefinitely in {@link #stateSavers}.
*
* @param agent the agent whose saver should be removed; no-op if {@code null}
*/
public void unbindStateSaver(Agent agent) {
if (agent == null) {
return;
}
stateSavers.remove(agent.getAgentId());
}

/**
* Check whether the agent was previously interrupted by shutdown, and clear the flag.
*
Expand Down