Class HITLApproval

java.lang.Object
com.tnsai.coordination.supervisor.HITLApproval
All Implemented Interfaces:
Guardrail

public class HITLApproval extends Object implements 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:
  • 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 approval
      approvalCallback - 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 name
      requiresApproval - set of action patterns that require human approval
      approvalCallback - callback to invoke when approval is needed
      Throws:
      NullPointerException - if any argument is null
  • Method Details

    • getName

      public String getName()
      Description copied from interface: Guardrail
      Returns the name of this guardrail.
      Specified by:
      getName in interface Guardrail
      Returns:
      guardrail name, must be unique within a supervisor
    • check

      public Guardrail.GuardrailResult check(String agentId, String action, Map<String,Object> context)
      Description copied from interface: Guardrail
      Checks whether an agent action is allowed.
      Specified by:
      check in interface Guardrail
      Parameters:
      agentId - the ID of the agent attempting the action
      action - the action being attempted
      context - additional context about the action
      Returns:
      result indicating whether the action is allowed
    • getRequiresApproval

      public Set<String> getRequiresApproval()
      Returns the set of action patterns requiring approval.
      Returns:
      unmodifiable set of action patterns
    • addPattern

      public void addPattern(String pattern)
      Adds an action pattern that requires approval.
      Parameters:
      pattern - the action pattern to add
    • removePattern

      public boolean removePattern(String pattern)
      Removes an action pattern from the approval requirement.
      Parameters:
      pattern - the action pattern to remove
      Returns:
      true if the pattern was removed