Class AgentRecoveryManager

java.lang.Object
com.tnsai.coordination.supervisor.AgentRecoveryManager

public final class AgentRecoveryManager extends Object
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

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:
  • Constructor Details

  • Method Details

    • addHealthCheck

      public void addHealthCheck(String agentId, AgentRecoveryManager.HealthCheck check)
      Registers a health check for a specific agent.
      Parameters:
      agentId - the agent ID to monitor
      check - the health check to run
    • removeHealthCheck

      public void removeHealthCheck(String agentId)
      Removes the health check for an agent.
      Parameters:
      agentId - the agent ID to stop monitoring
    • start

      public void start(Duration checkInterval)
      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

      public List<AgentRecoveryManager.HealthStatus> runHealthChecks()
      Runs all registered health checks immediately (also called periodically by scheduler).
      Returns:
      list of health statuses for all checked agents
    • triggerRecovery

      public AgentRecoveryManager.RecoveryResult triggerRecovery(String agentId, String reason)
      Triggers recovery for a specific agent manually.
      Parameters:
      agentId - the agent to recover
      reason - the reason for recovery
      Returns:
      the recovery result
    • addListener

      public void addListener(AgentRecoveryManager.RecoveryListener listener)
      Adds a recovery listener.
      Parameters:
      listener - the listener to add
    • removeListener

      public void removeListener(AgentRecoveryManager.RecoveryListener listener)
      Removes a recovery listener.
      Parameters:
      listener - the listener to remove
    • getRecoveryHistory

      public List<AgentRecoveryManager.RecoveryResult> getRecoveryHistory()
      Returns the recovery history (most recent entries last).
      Returns:
      unmodifiable list of recovery results
    • getRetryCount

      public int getRetryCount(String agentId)
      Returns the retry count for an agent.
      Parameters:
      agentId - the agent ID
      Returns:
      number of recovery retries, or 0 if none
    • resetRetryCounter

      public void resetRetryCounter(String agentId)
      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