Package com.tnsai.eval.hooks
Class EvalHookManager
java.lang.Object
com.tnsai.eval.hooks.EvalHookManager
- All Implemented Interfaces:
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 -
Method Summary
Modifier and TypeMethodDescriptionvoidaddHook(com.tnsai.eval.hooks.EvalHook hook) Adds a hook to the manager.voidClears all hooks.voidfireOnAfterChat(com.tnsai.eval.hooks.EvalContext ctx, String response, long latencyMs) Fires onAfterChat event.voidfireOnAfterToolCall(com.tnsai.eval.hooks.EvalContext ctx, String toolName, Object result, boolean success, long latencyMs) Fires onAfterToolCall event.voidfireOnAgentCommunication(com.tnsai.eval.hooks.EvalContext ctx, String fromAgent, String toAgent, String messageType, long latencyMs) Fires onAgentCommunication event.voidfireOnAgentStart(com.tnsai.eval.hooks.EvalContext ctx, String agentId, String sessionId) Fires onAgentStart event.voidfireOnAgentStop(com.tnsai.eval.hooks.EvalContext ctx, String reason) Fires onAgentStop event.voidfireOnBeforeChat(com.tnsai.eval.hooks.EvalContext ctx, String message) Fires onBeforeChat event.voidfireOnBeforeToolCall(com.tnsai.eval.hooks.EvalContext ctx, String toolName, Map<String, Object> arguments) Fires onBeforeToolCall event.voidfireOnError(com.tnsai.eval.hooks.EvalContext ctx, Throwable error, String phase) Fires onError event.voidfireOnGoalCompleted(com.tnsai.eval.hooks.EvalContext ctx, String goalId, boolean success, Map<String, Object> details) Fires onGoalCompleted event.voidfireOnMemoryAccess(com.tnsai.eval.hooks.EvalContext ctx, String operation, String key, int resultCount, long latencyMs) Fires onMemoryAccess event.voidfireOnPlanCompleted(com.tnsai.eval.hooks.EvalContext ctx, boolean success, int totalSteps, int executedSteps, long totalLatencyMs) Fires onPlanCompleted event.voidfireOnPlanFailed(com.tnsai.eval.hooks.EvalContext ctx, String goalId, String reason) Fires onPlanFailed event.voidfireOnPlanGenerated(com.tnsai.eval.hooks.EvalContext ctx, String goalId, List<com.tnsai.planning.PlannerHandle.PlanStep> steps, long latencyMs) Fires onPlanGenerated event.voidfireOnPlanStepExecuted(com.tnsai.eval.hooks.EvalContext ctx, String actionName, boolean success, long latencyMs) Fires onPlanStepExecuted event.intGets the number of registered hooks.booleanChecks if hooks are enabled.booleanremoveHook(com.tnsai.eval.hooks.EvalHook hook) Removes a hook from the manager.voidsetEnabled(boolean enabled) Enables or disables hook execution.
-
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:
addHookin interfacecom.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:
removeHookin interfacecom.tnsai.eval.hooks.EvalHandle- Parameters:
hook- hook to remove- Returns:
- true if removed
-
clearHooks
public void clearHooks()Clears all hooks.- Specified by:
clearHooksin interfacecom.tnsai.eval.hooks.EvalHandle
-
hookCount
public int hookCount()Gets the number of registered hooks.- Specified by:
hookCountin interfacecom.tnsai.eval.hooks.EvalHandle- Returns:
- hook count
-
setEnabled
public void setEnabled(boolean enabled) Enables or disables hook execution.- Specified by:
setEnabledin interfacecom.tnsai.eval.hooks.EvalHandle- Parameters:
enabled- true to enable
-
isEnabled
public boolean isEnabled()Checks if hooks are enabled.- Specified by:
isEnabledin interfacecom.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:
fireOnAgentStartin interfacecom.tnsai.eval.hooks.EvalHandle
-
fireOnBeforeChat
Fires onBeforeChat event.- Specified by:
fireOnBeforeChatin interfacecom.tnsai.eval.hooks.EvalHandle
-
fireOnAfterChat
Fires onAfterChat event.- Specified by:
fireOnAfterChatin interfacecom.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:
fireOnBeforeToolCallin interfacecom.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:
fireOnAfterToolCallin interfacecom.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:
fireOnGoalCompletedin interfacecom.tnsai.eval.hooks.EvalHandle
-
fireOnAgentStop
Fires onAgentStop event.- Specified by:
fireOnAgentStopin interfacecom.tnsai.eval.hooks.EvalHandle
-
fireOnError
Fires onError event.- Specified by:
fireOnErrorin interfacecom.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:
fireOnMemoryAccessin interfacecom.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:
fireOnAgentCommunicationin interfacecom.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
Fires onPlanFailed event.
-