Class EvalHookManager

java.lang.Object
com.tnsai.eval.hooks.EvalHookManager
All Implemented Interfaces:
com.tnsai.eval.hooks.EvalHandle

public final class EvalHookManager extends Object implements com.tnsai.eval.hooks.EvalHandle
Manager for coordinating multiple evaluation hooks.

EvalHookManager maintains a list of hooks and dispatches lifecycle events to all registered hooks. It handles errors gracefully to ensure one failing hook doesn't affect others.

Usage


 EvalHookManager manager = new EvalHookManager();
 manager.addHook(new LatencyHook());
 manager.addHook(new QualityHook());

 EvalContext ctx = EvalContext.create("session-1", "agent-1");
 manager.fireOnAgentStart(ctx, "agent-1", "session-1");
 manager.fireOnBeforeChat(ctx, "Hello");
 // ... agent execution ...
 manager.fireOnAfterChat(ctx, "Hi there!", 150);
 manager.fireOnAgentStop(ctx, "COMPLETED");
 
Author:
TnsAI Team
  • Nested Class Summary

    Nested classes/interfaces inherited from interface com.tnsai.eval.hooks.EvalHandle

    com.tnsai.eval.hooks.EvalHandle.Factory
  • Field Summary

    Fields inherited from interface com.tnsai.eval.hooks.EvalHandle

    NOOP
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    addHook(com.tnsai.eval.hooks.EvalHook hook)
    Adds a hook to the manager.
    void
    Clears all hooks.
    void
    fireOnAfterChat(com.tnsai.eval.hooks.EvalContext ctx, String response, long latencyMs)
    Fires onAfterChat event.
    void
    fireOnAfterToolCall(com.tnsai.eval.hooks.EvalContext ctx, String toolName, Object result, boolean success, long latencyMs)
    Fires onAfterToolCall event.
    void
    fireOnAgentCommunication(com.tnsai.eval.hooks.EvalContext ctx, String fromAgent, String toAgent, String messageType, long latencyMs)
    Fires onAgentCommunication event.
    void
    fireOnAgentStart(com.tnsai.eval.hooks.EvalContext ctx, String agentId, String sessionId)
    Fires onAgentStart event.
    void
    fireOnAgentStop(com.tnsai.eval.hooks.EvalContext ctx, String reason)
    Fires onAgentStop event.
    void
    fireOnBeforeChat(com.tnsai.eval.hooks.EvalContext ctx, String message)
    Fires onBeforeChat event.
    void
    fireOnBeforeToolCall(com.tnsai.eval.hooks.EvalContext ctx, String toolName, Map<String,Object> arguments)
    Fires onBeforeToolCall event.
    void
    fireOnError(com.tnsai.eval.hooks.EvalContext ctx, Throwable error, String phase)
    Fires onError event.
    void
    fireOnGoalCompleted(com.tnsai.eval.hooks.EvalContext ctx, String goalId, boolean success, Map<String,Object> details)
    Fires onGoalCompleted event.
    void
    fireOnMemoryAccess(com.tnsai.eval.hooks.EvalContext ctx, String operation, String key, int resultCount, long latencyMs)
    Fires onMemoryAccess event.
    void
    fireOnPlanCompleted(com.tnsai.eval.hooks.EvalContext ctx, boolean success, int totalSteps, int executedSteps, long totalLatencyMs)
    Fires onPlanCompleted event.
    void
    fireOnPlanFailed(com.tnsai.eval.hooks.EvalContext ctx, String goalId, String reason)
    Fires onPlanFailed event.
    void
    fireOnPlanGenerated(com.tnsai.eval.hooks.EvalContext ctx, String goalId, List<com.tnsai.planning.PlannerHandle.PlanStep> steps, long latencyMs)
    Fires onPlanGenerated event.
    void
    fireOnPlanStepExecuted(com.tnsai.eval.hooks.EvalContext ctx, String actionName, boolean success, long latencyMs)
    Fires onPlanStepExecuted event.
    int
    Gets the number of registered hooks.
    boolean
    Checks if hooks are enabled.
    boolean
    removeHook(com.tnsai.eval.hooks.EvalHook hook)
    Removes a hook from the manager.
    void
    setEnabled(boolean enabled)
    Enables or disables hook execution.

    Methods inherited from class java.lang.Object

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

    • EvalHookManager

      public EvalHookManager()
  • Method Details

    • addHook

      public void addHook(com.tnsai.eval.hooks.EvalHook hook)
      Adds a hook to the manager.
      Specified by:
      addHook in interface com.tnsai.eval.hooks.EvalHandle
      Parameters:
      hook - hook to add
    • removeHook

      public boolean removeHook(com.tnsai.eval.hooks.EvalHook hook)
      Removes a hook from the manager.
      Specified by:
      removeHook in interface com.tnsai.eval.hooks.EvalHandle
      Parameters:
      hook - hook to remove
      Returns:
      true if removed
    • clearHooks

      public void clearHooks()
      Clears all hooks.
      Specified by:
      clearHooks in interface com.tnsai.eval.hooks.EvalHandle
    • hookCount

      public int hookCount()
      Gets the number of registered hooks.
      Specified by:
      hookCount in interface com.tnsai.eval.hooks.EvalHandle
      Returns:
      hook count
    • setEnabled

      public void setEnabled(boolean enabled)
      Enables or disables hook execution.
      Specified by:
      setEnabled in interface com.tnsai.eval.hooks.EvalHandle
      Parameters:
      enabled - true to enable
    • isEnabled

      public boolean isEnabled()
      Checks if hooks are enabled.
      Specified by:
      isEnabled in interface com.tnsai.eval.hooks.EvalHandle
      Returns:
      true if enabled
    • fireOnAgentStart

      public void fireOnAgentStart(com.tnsai.eval.hooks.EvalContext ctx, String agentId, String sessionId)
      Fires onAgentStart event.
      Specified by:
      fireOnAgentStart in interface com.tnsai.eval.hooks.EvalHandle
    • fireOnBeforeChat

      public void fireOnBeforeChat(com.tnsai.eval.hooks.EvalContext ctx, String message)
      Fires onBeforeChat event.
      Specified by:
      fireOnBeforeChat in interface com.tnsai.eval.hooks.EvalHandle
    • fireOnAfterChat

      public void fireOnAfterChat(com.tnsai.eval.hooks.EvalContext ctx, String response, long latencyMs)
      Fires onAfterChat event.
      Specified by:
      fireOnAfterChat in interface com.tnsai.eval.hooks.EvalHandle
    • fireOnBeforeToolCall

      public void fireOnBeforeToolCall(com.tnsai.eval.hooks.EvalContext ctx, String toolName, Map<String,Object> arguments)
      Fires onBeforeToolCall event.
      Specified by:
      fireOnBeforeToolCall in interface com.tnsai.eval.hooks.EvalHandle
    • fireOnAfterToolCall

      public void fireOnAfterToolCall(com.tnsai.eval.hooks.EvalContext ctx, String toolName, Object result, boolean success, long latencyMs)
      Fires onAfterToolCall event.
      Specified by:
      fireOnAfterToolCall in interface com.tnsai.eval.hooks.EvalHandle
    • fireOnGoalCompleted

      public void fireOnGoalCompleted(com.tnsai.eval.hooks.EvalContext ctx, String goalId, boolean success, Map<String,Object> details)
      Fires onGoalCompleted event.
      Specified by:
      fireOnGoalCompleted in interface com.tnsai.eval.hooks.EvalHandle
    • fireOnAgentStop

      public void fireOnAgentStop(com.tnsai.eval.hooks.EvalContext ctx, String reason)
      Fires onAgentStop event.
      Specified by:
      fireOnAgentStop in interface com.tnsai.eval.hooks.EvalHandle
    • fireOnError

      public void fireOnError(com.tnsai.eval.hooks.EvalContext ctx, Throwable error, String phase)
      Fires onError event.
      Specified by:
      fireOnError in interface com.tnsai.eval.hooks.EvalHandle
    • fireOnMemoryAccess

      public void fireOnMemoryAccess(com.tnsai.eval.hooks.EvalContext ctx, String operation, String key, int resultCount, long latencyMs)
      Fires onMemoryAccess event.
      Specified by:
      fireOnMemoryAccess in interface com.tnsai.eval.hooks.EvalHandle
    • fireOnAgentCommunication

      public void fireOnAgentCommunication(com.tnsai.eval.hooks.EvalContext ctx, String fromAgent, String toAgent, String messageType, long latencyMs)
      Fires onAgentCommunication event.
      Specified by:
      fireOnAgentCommunication in interface com.tnsai.eval.hooks.EvalHandle
    • fireOnPlanGenerated

      public void fireOnPlanGenerated(com.tnsai.eval.hooks.EvalContext ctx, String goalId, List<com.tnsai.planning.PlannerHandle.PlanStep> steps, long latencyMs)
      Fires onPlanGenerated event.
    • fireOnPlanStepExecuted

      public void fireOnPlanStepExecuted(com.tnsai.eval.hooks.EvalContext ctx, String actionName, boolean success, long latencyMs)
      Fires onPlanStepExecuted event.
    • fireOnPlanCompleted

      public void fireOnPlanCompleted(com.tnsai.eval.hooks.EvalContext ctx, boolean success, int totalSteps, int executedSteps, long totalLatencyMs)
      Fires onPlanCompleted event.
    • fireOnPlanFailed

      public void fireOnPlanFailed(com.tnsai.eval.hooks.EvalContext ctx, String goalId, String reason)
      Fires onPlanFailed event.