Why human-in-the-loop matters
AI agents are increasingly capable of taking autonomous actions, but certain operations require human judgement:- Safety: Prevent unintended consequences from AI decisions.
- Compliance: Meet regulatory requirements for human oversight in sensitive domains.
- Trust: Build user confidence by keeping humans in control of critical actions.
- Accountability: Create clear audit trails of who approved what actions.
- Clarification: Allow the agent to request more information or guidance from users before proceeding.
How it works
Human-in-the-loop authorization follows a request-approval pattern over Ably channels:- The AI agent determines a tool call requires human approval.
- The agent publishes an authorization request to the channel.
- An authorized user receives and reviews the request.
- The human approves or rejects the request.
- The agent receives the decision, verifies the responder’s identity or role and proceeds accordingly.
Request human approval
When an agent identifies an action requiring human oversight, it publishes a request to the channel. The request should include sufficient context for the approver to make an informed decision. ThetoolCallId in the message extras enables correlation between requests and responses when handling multiple concurrent approval flows.
The agent stores each pending request in some local state before publishing. When an approval response arrives, the agent uses the toolCallId to retrieve the original tool call details, verify the approver’s permissions for that specific action, execute the tool if approved, and resolve the pending approval.
Review and decide
Authorized humans subscribe to approval requests on the conversation channel and publish their decisions. ThetoolCallId correlates the response with the original request.
Use identified clients or user claims to establish a verified identity or role for the approver. For example, when a user authenticates with Ably, embed their identity and role in the JWT:
The clientId and user claims are automatically attached to every message the user publishes and cannot be forged, so agents can trust this identity and role information.
Process the decision
The agent listens for human decisions and acts accordingly. When a response arrives, the agent retrieves the pending request using thetoolCallId, verifies that the user is permitted to approve that specific action, and either executes the action or handles the rejection.
Verify by user identity
Use theclientId to identify the approver and look up their permissions in your database or access control system. This approach is useful when permissions are managed externally or change frequently.
