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;
}
}This example demonstrates the basic approval lifecycle.
However, production implementations should use authenticated user identities, database concurrency controls, and an audit record for every decision.
A decision must also be associated with the correct workflow and approval version. A request should not be approved again after it has already been processed.
Pausing the Agent Workflow
Once the approval service is available, integrate it into the agent execution process.
The workflow should save its current state before creating an approval request.
For example, consider a workflow that prepares a customer refund.
public async Task RequestRefundApprovalAsync(
Guid workflowId,
CancellationToken cancellationToken)
{
var state = await _repository.GetAsync(
workflowId, cancellationToken);
if (state == null)
{
throw new InvalidOperationException(
"Workflow not found.");
}
state.Status = "WaitingForApproval";
state.CurrentStep = "RefundApproval";
await _repository.SaveAsync(
state, cancellationToken);
var approval = await _approvalService.CreateAsync(
new ApprovalRequest
{
WorkflowId = workflowId,
RequestedAction = "Approve customer refund",
RequestedBy = "AI Agent",
AssignedTo = "finance-manager",
ExpiresAt = DateTime.UtcNow.AddHours(24)
},
cancellationToken);
await _notificationService.NotifyAsync(
approval.ApprovalId,
cancellationToken);
}The application saves the workflow state before notifying the approver.
After creating the request, the worker can finish its current execution. It does not need to wait continuously for the human decision.
This is important because keeping a background task alive for several hours wastes resources and makes recovery difficult.
Instead, the approval request becomes a durable dependency that can trigger workflow resumption later.
Resuming the Workflow After Approval
When an authorized person approves the request, the application should publish an event or enqueue a message to resume the workflow.
For example:
public async Task HandleApprovalAsync(
Guid approvalId,
CancellationToken cancellationToken)
{
var approval = await _approvalService.GetAsync(
approvalId, cancellationToken);
if (approval == null)
{
return;
}
if (approval.Status == "Rejected")
{
await StopWorkflowAsync(
approval.WorkflowId,
cancellationToken);
return;
}
if (approval.Status != "Approved")
{
return;
}
await _workflowQueue.EnqueueAsync(
approval.WorkflowId,
cancellationToken);
}The workflow worker retrieves the saved state and continues from the refund execution step.
An important production consideration is that approval handling and workflow resumption should be idempotent. A notification or queue message may be delivered more than once.
The application should therefore record whether the approval has already triggered the next operation.
It should also revalidate the action before execution. Approval does not automatically mean that the underlying data remains unchanged.
For example, a refund amount or customer order status might have changed while the request was waiting for review.
Best Practices for Long-Running Approval Workflows
Use Durable Workflow State
Never depend on in-memory objects to maintain approval progress.
Store the workflow state, approval request, and execution status in durable storage. This allows the application to recover after deployments, worker restarts, and infrastructure failures.
Apply Role-Based Authorization
Not every user should be able to approve every operation.
Use role-based or attribute-based access control to ensure that only authorized people can approve specific actions.
For financial operations, additional controls may require separate requesters and approvers.
Configure Approval Expiration
Approval requests should have a defined expiration period.
If no decision is received before the deadline, the application should mark the request as expired and follow a predefined business policy.
For sensitive operations, the safest default is generally to avoid executing the action without explicit approval.
Maintain an Audit Trail
Record who requested the approval, who made the decision, when it happened, and what comments were provided.
Audit records should be protected against unauthorized modification.
Use Message Queues for Resumption
For long-running workflows, use durable messaging to trigger the next execution step.
This separates the approval interface from the workflow worker and improves scalability.
Handle Changes While Waiting
The business data associated with an approval request may change before the decision arrives.
Store a reference or version of the original request and validate the relevant information again before executing the approved action.
Common Mistakes to Avoid
| Mistake | Problem | Better approach |
|---|---|---|
| Keeping a worker alive while waiting | Consumes resources unnecessarily | Persist state and resume later |
| Allowing any user to approve | Creates authorization risks | Validate approver identity and permissions |
| Not setting expiration | Workflows can remain pending indefinitely | Configure approval deadlines |
| Executing the same approval twice | Can create duplicate operations | Use idempotency and concurrency controls |
| Not recording approval history | Makes audits difficult | Maintain immutable decision records |
| Trusting old approval data | Business information may have changed | Revalidate before execution |
Advantages and Disadvantages of Human Approval
Human approval provides several benefits for AI-driven business processes.
Advantages:
- Adds human oversight to sensitive operations.
- Reduces the risk of unauthorized automated actions.
- Allows AI agents to automate preparation and analysis.
- Provides better accountability and auditability.
- Supports business-specific authorization policies.
- Improves control over long-running automated workflows.
Disadvantages:
- Increases the overall workflow completion time.
- Requires an approval interface and notification system.
- Depends on human availability.
- Introduces additional state management and recovery requirements.
- Can create operational delays when approval requests accumulate.
The objective is to introduce approval only where it adds meaningful business or security value.
Troubleshooting Common Approval Problems
Workflow Does Not Resume After Approval
Check whether the approval event was published successfully and whether the workflow queue contains the corresponding message.
Also verify that the workflow worker is processing pending messages.
Approval Request Remains Pending
Verify the notification process, approver assignment, expiration settings, and approval interface.
A notification being delivered does not necessarily mean the approval was submitted.
Multiple Approval Events Are Processed
Check whether the same approval can trigger multiple workflow messages.
Use a unique event identifier and maintain a durable record of completed approval processing.
Unauthorized Users Can Approve Requests
Verify that the application obtains the approver identity from the authenticated security context.
Never trust an approver ID supplied directly by an untrusted client without validating it against the authenticated user and authorization policies.
Summary
Human approval is an important capability when AI agents perform business operations that require human judgment or authorization. Instead of allowing an agent to execute every action automatically, applications can introduce approval checkpoints into long-running workflows.
A reliable ASP.NET Core implementation should save workflow state, create durable approval requests, validate approver permissions, configure expiration policies, and resume execution after receiving an approved decision.
The workflow should not keep a worker running while waiting for a person. Durable storage and message-based resumption provide a more reliable approach.
By combining human oversight with persistent workflow state, authorization controls, and idempotent execution, developers can build AI agent systems that automate routine work while keeping important business decisions under human control.

Join the conversation! Your thoughts help the community grow.