Class AgentRecoveryManager
java.lang.Object
com.tnsai.coordination.supervisor.AgentRecoveryManager
Manages agent health monitoring and recovery within a supervised group.
AgentRecoveryManager continuously monitors agents for health issues and
applies recovery policies when problems are detected. It integrates with
SupervisorAgent to coordinate guardrail enforcement during recovery.
Recovery Actions
AgentRecoveryManager.RecoveryAction.RESTART— Restart the agent preserving stateAgentRecoveryManager.RecoveryAction.RESTART_CLEAN— Restart with a clean slateAgentRecoveryManager.RecoveryAction.EJECT— Remove the agent from the groupAgentRecoveryManager.RecoveryAction.ESCALATE— Escalate to supervisor for manual interventionAgentRecoveryManager.RecoveryAction.REPLACE— Remove and request a replacement agent
Usage Example
RecoveryPolicy policy = RecoveryPolicy.builder()
.maxRetries(3)
.cooldown(Duration.ofSeconds(5))
.escalateAfter(3)
.build();
AgentRecoveryManager recovery = new AgentRecoveryManager(supervisor, policy);
recovery.addHealthCheck("agent-1", agent -> agent.llm() != null);
recovery.start(Duration.ofSeconds(10));
// Later...
recovery.stop();
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceFunctional interface for agent health checks.static final recordAgent health status snapshot.static enumAction to take when an agent is unhealthy.static interfaceListener notified of recovery events.static final classPolicy governing recovery behavior.static final recordResult of a recovery attempt. -
Constructor Summary
ConstructorsConstructorDescriptionAgentRecoveryManager(SupervisorAgent supervisor, AgentRecoveryManager.RecoveryPolicy policy) Creates a new AgentRecoveryManager. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddHealthCheck(String agentId, AgentRecoveryManager.HealthCheck check) Registers a health check for a specific agent.voidAdds a recovery listener.Returns the recovery policy.Returns the recovery history (most recent entries last).intgetRetryCount(String agentId) Returns the retry count for an agent.booleanReturns whether the recovery manager is currently running.voidremoveHealthCheck(String agentId) Removes the health check for an agent.voidRemoves a recovery listener.voidresetRetryCounter(String agentId) Resets the retry counter for an agent (e.g., after it recovers successfully).Runs all registered health checks immediately (also called periodically by scheduler).voidStarts periodic health monitoring.voidstop()Stops the health monitoring.triggerRecovery(String agentId, String reason) Triggers recovery for a specific agent manually.
-
Constructor Details
-
AgentRecoveryManager
Creates a new AgentRecoveryManager.- Parameters:
supervisor- the supervisor agent managing the grouppolicy- the recovery policy to apply- Throws:
NullPointerException- if supervisor or policy is null
-
-
Method Details
-
addHealthCheck
Registers a health check for a specific agent.- Parameters:
agentId- the agent ID to monitorcheck- the health check to run
-
removeHealthCheck
Removes the health check for an agent.- Parameters:
agentId- the agent ID to stop monitoring
-
start
Starts periodic health monitoring.- Parameters:
checkInterval- how often to run health checks- Throws:
IllegalStateException- if already running
-
stop
public void stop()Stops the health monitoring. -
isRunning
public boolean isRunning()Returns whether the recovery manager is currently running.- Returns:
- true if running
-
runHealthChecks
Runs all registered health checks immediately (also called periodically by scheduler).- Returns:
- list of health statuses for all checked agents
-
triggerRecovery
Triggers recovery for a specific agent manually.- Parameters:
agentId- the agent to recoverreason- the reason for recovery- Returns:
- the recovery result
-
addListener
Adds a recovery listener.- Parameters:
listener- the listener to add
-
removeListener
Removes a recovery listener.- Parameters:
listener- the listener to remove
-
getRecoveryHistory
Returns the recovery history (most recent entries last).- Returns:
- unmodifiable list of recovery results
-
getRetryCount
Returns the retry count for an agent.- Parameters:
agentId- the agent ID- Returns:
- number of recovery retries, or 0 if none
-
resetRetryCounter
Resets the retry counter for an agent (e.g., after it recovers successfully).- Parameters:
agentId- the agent ID
-
getPolicy
Returns the recovery policy.- Returns:
- recovery policy
-