Class FailureTracker

java.lang.Object
uno.anahata.ai.tools.FailureTracker

public class FailureTracker extends Object
Tracks consecutive failures of tool calls and implements a temporary blocking mechanism.

If a specific tool (identified by its name and arguments) fails repeatedly within a short time window, this tracker will block subsequent calls to that tool to prevent infinite loops or excessive resource consumption.

  • Constructor Summary

    Constructors
    Constructor
    Description
    Constructs a new FailureTracker for the given Chat instance.
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    isBlocked(com.google.genai.types.FunctionCall functionCall)
    Checks if a specific function call is currently blocked due to repeated failures.
    void
    recordFailure(com.google.genai.types.FunctionCall functionCall, Exception e)
    Records a failure for a specific function call.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • FailureTracker

      public FailureTracker(Chat chat)
      Constructs a new FailureTracker for the given Chat instance.
      Parameters:
      chat - The Chat instance.
  • Method Details

    • recordFailure

      public void recordFailure(com.google.genai.types.FunctionCall functionCall, Exception e)
      Records a failure for a specific function call.
      Parameters:
      functionCall - The function call that failed.
      e - The exception that occurred.
    • isBlocked

      public boolean isBlocked(com.google.genai.types.FunctionCall functionCall)
      Checks if a specific function call is currently blocked due to repeated failures.

      This method also performs cleanup of expired failure records based on the configured time window.

      Parameters:
      functionCall - The function call to check.
      Returns:
      true if the call is blocked, false otherwise.