Class HITLApproval
java.lang.Object
com.tnsai.coordination.supervisor.HITLApproval
- All Implemented Interfaces:
Guardrail
Human-in-the-Loop guardrail that requires human approval for certain actions.
HITLApproval checks whether an action matches any of its configured patterns
that require approval. When a match is found, an HITLApproval.ApprovalRequest is sent
to the configured callback, and the guardrail blocks until the human responds.
Usage Example
HITLApproval hitl = new HITLApproval(
Set.of("delete", "deploy", "execute"),
request -> {
// Present to human for approval
boolean approved = showApprovalDialog(request);
request.approval().complete(approved);
}
);
supervisor.addGuardrail(hitl);
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordRequest for human approval of an agent action.Nested classes/interfaces inherited from interface com.tnsai.coordination.supervisor.Guardrail
Guardrail.GuardrailResult, Guardrail.GuardrailSeverity -
Constructor Summary
ConstructorsConstructorDescriptionHITLApproval(String name, Set<String> requiresApproval, Consumer<HITLApproval.ApprovalRequest> approvalCallback) Creates a new HITLApproval guardrail with a custom name.HITLApproval(Set<String> requiresApproval, Consumer<HITLApproval.ApprovalRequest> approvalCallback) Creates a new HITLApproval guardrail. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddPattern(String pattern) Adds an action pattern that requires approval.Checks whether an agent action is allowed.getName()Returns the name of this guardrail.Returns the set of action patterns requiring approval.booleanremovePattern(String pattern) Removes an action pattern from the approval requirement.
-
Constructor Details
-
HITLApproval
public HITLApproval(Set<String> requiresApproval, Consumer<HITLApproval.ApprovalRequest> approvalCallback) Creates a new HITLApproval guardrail.- Parameters:
requiresApproval- set of action patterns that require human approvalapprovalCallback- callback to invoke when approval is needed- Throws:
NullPointerException- if any argument is null
-
HITLApproval
public HITLApproval(String name, Set<String> requiresApproval, Consumer<HITLApproval.ApprovalRequest> approvalCallback) Creates a new HITLApproval guardrail with a custom name.- Parameters:
name- the guardrail namerequiresApproval- set of action patterns that require human approvalapprovalCallback- callback to invoke when approval is needed- Throws:
NullPointerException- if any argument is null
-
-
Method Details
-
getName
Description copied from interface:GuardrailReturns the name of this guardrail. -
check
Description copied from interface:GuardrailChecks whether an agent action is allowed. -
getRequiresApproval
Returns the set of action patterns requiring approval.- Returns:
- unmodifiable set of action patterns
-
addPattern
Adds an action pattern that requires approval.- Parameters:
pattern- the action pattern to add
-
removePattern
Removes an action pattern from the approval requirement.- Parameters:
pattern- the action pattern to remove- Returns:
- true if the pattern was removed
-