Human in the Loop
Learn how to implement human approval flows in your Inferable applications
Overview
Human-in-the-loop (HITL) allow you to require human approval before certain actions are executed. This is useful for:
- Reviewing and approving high-risk operations
- Validating model outputs before taking action
Inferable provides a simple API for creating approval requests and approving them. It accomplishes this by returning a special result type as a result from either a Tool or Workflow.
It is important to note that the Interrupt.approval()
is applicable in
both Tools and Workflows. It’s usage is the same within each.
Implementation
The Interrupt.approval()
function is currently not available in the .Net
SDK. Please see .Net
Issue.
To implement HITL in Inferable, use the Interrupt.approval()
helper when you need approval within your functions:
Approval Request result
By returning the Interrupt.approval()
result, you are in fact returning a special result type that the execution engine can handle.
In this case, the parent Run or Workflow will be paused and the approval request will be created.
Approval Flow
When Interrupt.approval()
is returned from a Tool or Workflow:
-
The Workflow or Run is
paused
. -
The approval request is created.
-
An authorized user must approve or reject the request using the API or the App UI.
-
If the approval is successful,
4.1 The workflow will resume execution, and will call the handler again with the same input.
4.2 At this point, since the
context.approved
istrue
, the handler will continue without entering thereturn Interrupt.approval()
block. -
If the approval is rejected
5.1 The tool / workflow will be rejected. If this is a tool, the agent will be notified that the tool call was rejected.
Pausing a Workflow
When a Workflow is paused, Inferable’s durable execution engine will save the state and resume when the approval is resolved.
Since humans can take a long time to approve, the run or workflow can be paused for an indefinite amount of time. There’s no theoretical upper limit on how long a run can be paused for.
Notifications
By default, approvals can be provided within the Workflow or Run’s UI. If enabled, the Slack integration can also be used to notify users / channels of approval requests.
Modeling the Approval Block
It’s important to reiterate that the function may be called multiple times with the same input, if the request is approved.
Anything that sits before the if (context.approved) { ... }
block will be executed at least twice.
Example:
Was this page helpful?