AI agents are becoming capable of handling complex business operations that involve multiple steps, external services, and automated decisions. An agent can collect information, analyze documents, update records, generate reports, and communicate with other systems. However, not every operation should happen automatically.
Some actions require human approval before the agent can continue. For example, an AI agent might prepare a customer refund, generate a purchase order, approve an employee expense, or modify an important production configuration. Allowing an agent to execute these operations without verification can introduce financial, operational, or security risks.
This becomes more challenging when an agent workflow runs for several minutes or even hours. The application must pause execution, save its current state, notify the appropriate person, wait for a decision, and resume from the correct point after approval.
In this article, we will explore how to implement human approval in long-running AI agent workflows using C# and ASP.NET Core, including state management, approval requests, workflow recovery, and production best practices.
Why Human Approval Is Important in AI Agent Workflows
Consider an AI-powered finance assistant that processes employee expense claims.
The workflow might perform the following operations:
- Retrieve an employee's expense submission.
- Read the uploaded receipts.
- Analyze the expenses using an LLM.
- Check the organization's expense policies.
- Prepare an approval recommendation.
- Wait for a finance manager's decision.
- Update the expense management system.
- Notify the employee.
Most of these operations can be automated. However, the final financial approval should follow the organization's authorization rules.
If the agent continues without waiting for approval, it might execute an action that should have required human verification.
Human approval introduces a controlled decision point into the workflow. The agent can perform the preparation work automatically while leaving sensitive decisions to authorized people.
Common scenarios include:
- Approving financial transactions.
- Reviewing AI-generated contracts.
- Confirming customer refunds.
- Approving production deployments.
- Reviewing security-related actions.
- Validating AI-generated business reports.
- Authorizing changes to important application settings.
The goal is not to interrupt every agent operation. It is to identify actions where human judgment or authorization is required.
Understanding Human-in-the-Loop Architecture
Human-in-the-loop (HITL) architecture allows an automated system to pause and request human input before continuing execution.
In an AI agent workflow, the human approval process generally contains four components.
Agent Execution
The agent performs the operations that do not require manual authorization. It gathers information, calls available tools, and prepares a recommendation.
Approval Service
The approval service creates an approval request containing the required information, such as the workflow ID, requested action, approver, and expiration time.
Human Review Interface
The authorized user receives a notification and reviews the requested operation. The interface should provide enough information to make an informed decision.
Workflow Resumption
After receiving an approval or rejection, the application updates the workflow state and resumes execution from the appropriate step.
The following flow represents a typical implementation.
Agent Workflow Starts
|
v
Collect Information
|
v
Analyze With LLM
|
v
Prepare Requested Action
|
v
Save Workflow State
|
v
Create Approval Request
|
v
Wait for Human Decision
|
+----------------------+
| |
v v
Approved Rejected
| |
v v
Execute Action Stop Workflow
|
v
Save Final Result
|
v
Notify UserThe important architectural decision is that the workflow should not keep an application thread occupied while waiting for approval.
Instead, it should persist its state and allow the execution worker to process other requests.
Designing the Approval Data Model
Before implementing the approval service, define a model that represents the approval request.
The request should contain enough information to identify the workflow and understand the decision being requested.
public class ApprovalRequest
{
public Guid ApprovalId { get; set; }
public Guid WorkflowId { get; set; }
public string RequestedAction { get; set; } = string.Empty;
public string RequestedBy { get; set; } = string.Empty;
public string AssignedTo { get; set; } = string.Empty;
public string Status { get; set; } = "Pending";
public string? Comments { get; set; }
public DateTime CreatedAt { get; set; }
public DateTime ExpiresAt { get; set; }
public DateTime? DecisionAt { get; set; }
}Here, ApprovalId uniquely identifies the approval request, while WorkflowId connects it to the original AI workflow.
The AssignedTo property identifies the intended approver. In a production application, this should be linked to a verified identity or authorization system rather than treated as an ordinary user-supplied string.
The status property represents the current approval state.
Typical statuses include:
| Status | Meaning |
|---|---|
| Pending | Waiting for human review |
| Approved | Action has been authorized |
| Rejected | Action has been declined |
| Expired | Approval deadline has passed |
| Cancelled | Approval request has been withdrawn |
For production systems, use an enum or a database constraint to prevent invalid status values.
Creating an Approval Service in ASP.NET Core
The approval service should be responsible for creating and retrieving approval requests and recording human decisions.
Define an interface:
public interface IApprovalService
{
Task<ApprovalRequest> CreateAsync(
ApprovalRequest request,
CancellationToken cancellationToken);
Task<ApprovalRequest?> GetAsync(
Guid approvalId,
CancellationToken cancellationToken);
Task<bool> SubmitDecisionAsync(
Guid approvalId,
string approverId,
bool approved,
string? comments,
CancellationToken cancellationToken);
}An implementation can use Entity Framework Core to persist approval records.
public class ApprovalService : IApprovalService
{
private readonly AppDbContext _context;
public ApprovalService(AppDbContext context)
{
_context = context;
}
public async Task<ApprovalRequest> CreateAsync(
ApprovalRequest request,
CancellationToken cancellationToken)
{
request.ApprovalId = Guid.NewGuid();
request.Status = "Pending";
request.CreatedAt = DateTime.UtcNow;
_context.ApprovalRequests.Add(request);
await _context.SaveChangesAsync(cancellationToken);
return request;
}
public Task<ApprovalRequest?> GetAsync(
Guid approvalId,
CancellationToken cancellationToken)
{
return _context.ApprovalRequests
.AsNoTracking()
.FirstOrDefaultAsync(
x => x.ApprovalId == approvalId,
cancellationToken);
}
public async Task<bool> SubmitDecisionAsync(
Guid approvalId,
string approverId,
bool approved,
string? comments,
CancellationToken cancellationToken)
{
var request = await _context.ApprovalRequests
.FirstOrDefaultAsync(
x => x.ApprovalId == approvalId,
cancellationToken);
if (request == null ||
request.Status != "Pending" ||
request.ExpiresAt <= DateTime.UtcNow ||
request.AssignedTo != approverId)
{
return false;
}
request.Status = approved ? "Approved" : "Rejected";
request.Comments = comments;
request.DecisionAt = DateTime.UtcNow;
await _context.SaveChangesAsync(cancellationToken);
return true;
}
}
Join the conversation! Your thoughts help the community grow.