Table of Contents

๐Ÿ‘‰ Try the demo: https://github.com/LM-Kit/lm-kit-net-samples/tree/main/console_net/ai-agents/permissions/approval_and_resume

Approval and Resume for C# .NET Applications


๐ŸŽฏ Purpose of the Demo

An interactive console app where an agent stops before every refund it wants to issue. The run is saved as a JSON file; a person approves or denies the refund now, or after closing and reopening the program, and a fresh executor continues the run exactly where it stopped.

All inference runs on-device.


๐Ÿ‘ฅ Industry Target Audience

  • Support and back-office teams whose agents may propose payments, refunds or account changes but never execute them alone.
  • Platform engineers building approval inboxes where a decision comes minutes or days later, from another process.
  • Compliance-minded teams who need every write to be decided by a person, bound to the exact arguments shown.

๐Ÿš€ Problem Solved

An approval event that blocks the conversation works only while one process waits for one person. Real approvals come later, from elsewhere, after restarts. Resumable runs turn the wait into data: the run stops, its state is stored, and any process resumes it with the decision. A decision cannot be replayed onto other arguments, a denied call never runs, and a write in flight at a crash is never sent twice blindly.


๐Ÿ’ป Application Overview

Interactive menu (no command-line arguments):

Option What it does
A customer asks Runs a request with DeferToolApprovals; a refund stops the run before the call and saves it under runs/.
Review Lists the runs waiting for an approval, shows each pending call with its arguments, and resumes the run with your decision.

โœจ Key Features

  • AgentExecutionOptions.DeferToolApprovals: a call that needs approval ends the run as AwaitingApproval.
  • AgentRunState and FileAgentRunStore: a versioned, model-independent snapshot (history, pending round, budgets), saved at every checkpoint.
  • AgentExecutor.ResumeAsync with ToolApprovalDecision: approve, deny with a reason, or approve edited arguments; each decision is bound to its call and arguments hash.
  • Idempotency keys: AgentRunContext.Current.IdempotencyKey is stable across resumes, for tools that write to systems which deduplicate.

๐Ÿง  Models

  • qwen3.5:4b (about 3 GB of VRAM, tool calling).

๐Ÿ› ๏ธ Getting Started

๐Ÿ“‹ Prerequisites

  • .NET 8.0 or later

โ–ถ๏ธ Running the Application

git clone https://github.com/LM-Kit/lm-kit-net-samples
cd lm-kit-net-samples/console_net/ai-agents/permissions/approval_and_resume
dotnet run

Type 1 and a customer request, then 2 to approve or deny. Quit before deciding and start again: the run is still waiting.

Share