Class HumanCheckpointBehavior<T>
java.lang.Object
dev.agenor.runtime.behavior.BaseBehavior
dev.agenor.runtime.behavior.advanced.HumanCheckpointBehavior<T>
- Type Parameters:
T- type of the action payload
- All Implemented Interfaces:
Behavior
A ONE_SHOT behavior that suspends execution until a human approves, rejects, or
modifies the wrapped critical action.
Execution flow:
- Notifier fires (fire-and-forget) to alert an external observer.
ApprovalGate.requestApproval(dev.agenor.core.hitl.ApprovalRequest)is called; the virtual thread parks.- When
ApprovalService.submit(java.lang.String, dev.agenor.core.hitl.ApprovalDecision)completes the future, the behavior resumes and dispatches todecisionHandler.
Example:
new HumanCheckpointBehavior<>(
"payment-checkpoint",
approvalGate,
notifier,
paymentPayload,
"process-payment",
Duration.ofMinutes(30),
decision -> switch (decision) {
case ApprovalDecision.Approved a -> processPayment(paymentPayload);
case ApprovalDecision.Rejected r -> log.warn("Rejected: {}", r.reason());
case ApprovalDecision.Modified m -> processPayment((PaymentRequest) m.newPayload());
}
)
Timeout: if no decision arrives within timeout,
ApprovalTimeoutException is thrown inside action() and routed
to BaseBehavior.onError(java.lang.Exception) by BaseBehavior (which swallows all throwables and
completes the future normally). Override BaseBehavior.onError(java.lang.Exception) to add custom fallback
or escalation logic.
- Since:
- 0.13.0
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionHumanCheckpointBehavior(String behaviorId, ApprovalGate gate, ApprovalNotifier notifier, T payload, String actionName, Duration timeout, Consumer<ApprovalDecision> decisionHandler) Creates a newHumanCheckpointBehavior.HumanCheckpointBehavior(String behaviorId, ApprovalGate gate, ApprovalNotifier notifier, T payload, String actionName, Duration timeout, Consumer<ApprovalDecision> decisionHandler, AgenorTelemetry telemetry) Creates a newHumanCheckpointBehaviorwith telemetry support. -
Method Summary
Modifier and TypeMethodDescriptionprotected voidaction()The main action to be performed by this behavior.Methods inherited from class dev.agenor.runtime.behavior.BaseBehavior
activate, execute, getAgent, getBehaviorId, getInterval, getType, isActive, onError, onStop, setAgent, stopMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface dev.agenor.core.Behavior
getInitialDelay
-
Constructor Details
-
HumanCheckpointBehavior
public HumanCheckpointBehavior(String behaviorId, ApprovalGate gate, ApprovalNotifier notifier, T payload, String actionName, Duration timeout, Consumer<ApprovalDecision> decisionHandler) Creates a newHumanCheckpointBehavior.- Parameters:
behaviorId- unique identifier for this behaviorgate- gate used to park the virtual thread until a decision arrivesnotifier- notifier invoked before the gate parks (fire-and-forget)payload- data describing the action to be approvedactionName- human-readable action name included in theApprovalRequesttimeout- maximum wait time for a human decisiondecisionHandler- called with theApprovalDecisionwhen one is received; responsible for executing or skipping the critical action
-
HumanCheckpointBehavior
public HumanCheckpointBehavior(String behaviorId, ApprovalGate gate, ApprovalNotifier notifier, T payload, String actionName, Duration timeout, Consumer<ApprovalDecision> decisionHandler, AgenorTelemetry telemetry) Creates a newHumanCheckpointBehaviorwith telemetry support.- Parameters:
behaviorId- unique identifier for this behaviorgate- gate used to park the virtual thread until a decision arrivesnotifier- notifier invoked before the gate parks (fire-and-forget)payload- data describing the action to be approvedactionName- human-readable action name included in theApprovalRequesttimeout- maximum wait time for a human decisiondecisionHandler- called with theApprovalDecisionwhen one is receivedtelemetry- telemetry instance for emittinghitl.approvalspans;nulluses noop- Since:
- 0.19.0
-
-
Method Details
-
action
protected void action()Description copied from class:BaseBehaviorThe main action to be performed by this behavior. Must be implemented by subclasses.- Specified by:
actionin classBaseBehavior
-