MentorAgent Docs
Menu

ConceptPackages: Novior.MentorAgent, Novior.MentorAgent.Server

Roles, confirmation and governance

Role checks and human-in-the-loop approval for AI agent tools in .NET, enforced in code on every channel and not in the prompt, and what stays in your code.

View as Markdown
On this page

You govern an AI agent the way you govern your .NET application, in your code. This page explains how MentorAgent decides whether an action may run: the role check, the user's confirmation (what other frameworks call tool approval, or human-in-the-loop), the rules of your own code, and how to keep a record of every decision. The rules live on the method's attribute, not in the prompt. A model can be persuaded to ignore a rule in a prompt, but it cannot skip a check that runs in your code.

CaseService.cs
public class CaseService(ICaseStore store)
{
    [MentorAction(
        Description = "Gets the status of a support case",
        ReadOnly = true)]
    public Task<string> GetStatus(string caseNumber)
        => store.GetStatusAsync(caseNumber);

    [MentorAction(
        Description = "Closes a support case with a resolution",
        RequiresConfirmation = true,
        RequiredRoles = ["Supervisors"])]
    public Task CloseCase(string caseNumber, string resolution)
        => store.CloseAsync(caseNumber, resolution);
}

GetStatus only reads, so it declares ReadOnly = true: it never asks for confirmation. CloseCase changes data: only a user in the Supervisors role may run it, and only after confirming. An action that has a role rule, a confirmation, or both is called gated. The Glossary also explains withheld and refused.

  1. Role. RequiredRoles lists the roles that may run the action: any one of them is enough. MentorAgent finds the signed-in user (see below) and checks the roles with ClaimsPrincipal.IsInRole. That method reads the ClaimTypes.Role claims, unless your authentication sets another role claim type. A user without the role is never offered the action: at the start of every turn, MentorAgent leaves out of the model's tools every action that the user may not run, on the coordinator, the specialists and the team members. The model is told that some actions are not available, without naming them or their roles. If the model calls such an action anyway, for example by repeating an earlier turn, the call is refused before anything else happens: no confirmation box appears, and the model receives an authorization error.
  2. Confirmation. RequiresConfirmation asks the user before the method runs. A [MentorAction] that is not read-only also asks: see Confirmation by default.
    • The widget shows a confirmation box. A front end of your own, such as a React, Angular, Vue or mobile app, receives the request and sends back the answer.
    • If the user cancels, the method does not run. The model is told that the user declined, that nothing was checked or changed, and that it must not give another reason.
    • After the user confirms, MentorAgent checks the roles again, so a user who lost the role while the box was open is refused.

If you register action policies, MentorAgent asks them between the two checks: after the roles, before the confirmation.

The rules come with the class. MentorAgent finds the class in the assemblies you list in ScanAssemblies, and calls it through dependency injection:

Program.cs
builder.Services.AddScoped<CaseService>();
builder.Services.AddMentorAgent(options =>
{
    options.AppName = "Case management";
    options.ChatClient = chatClient;
    options.ScanAssemblies = [typeof(CaseService).Assembly];
});

The role check needs to know who the user is. MentorAgent finds the user where the request comes from:

  • On the SignalR hub, on /mentor/chat and on Agent-to-Agent (A2A), the user is the caller of the request: the user of the hub connection, or HttpContext.User. MentorAgent reads it before it asks your AuthenticationStateProvider. This works in a Blazor Web App too, in any order of AddRazorComponents() and AddMentorAgentServer(): see Blazor WebAssembly and Auto.
  • In a Blazor circuit, the connection that Blazor Server keeps with each browser tab, the user is the one that your AuthenticationStateProvider reports.
  • If your own AuthenticationStateProvider adds claims or roles, MentorAgent does not see them on the hub, on /mentor/chat or on A2A. Add them with an IClaimsTransformation. ASP.NET Core applies it to HttpContext.User, and so to the user of the hub connection.
  • If nobody is signed in, an action with RequiredRoles is offered to nobody, and refused if called. This is also the case in a .NET MAUI app that has no AuthenticationStateProvider.

A [MentorAction] that declares neither ReadOnly = true nor RequiresConfirmation counts as an action that changes data. It asks for confirmation, like one declared RequiresConfirmation = true:

CaseDefaults.cs
public class CaseDefaults(ICaseStore store)
{
    // Declares nothing, so it counts as a write and asks for confirmation
    [MentorAction(Description = "Archives a support case")]
    public Task ArchiveCase(string caseNumber)
        => store.CloseAsync(caseNumber, "Archived");

    // Only reads, so it never asks
    [MentorAction(
        Description = "Checks whether a support case is open",
        ReadOnly = true)]
    public Task<string> IsCaseOpen(string caseNumber)
        => store.GetStatusAsync(caseNumber);

    // A write that runs without asking, because you say so
    [MentorAction(
        Description = "Closes a duplicate support case",
        RequiresConfirmation = false)]
    public Task CloseDuplicate(string caseNumber)
        => store.CloseAsync(caseNumber, "Duplicate");
}
  • ArchiveCase declares nothing, so it asks.
  • IsCaseOpen only reads, so it never asks. Model Context Protocol (MCP) clients receive it with readOnlyHint, a hint that the tool only reads. Some of them skip their own confirmation for such a tool. Declare ReadOnly = true only on methods that really only read.
  • CloseDuplicate runs without asking, because RequiresConfirmation = false is your declaration.

An action that asks is not offered to MCP clients and is not on the A2A agent card (the description that A2A clients read), because nobody can answer there: see Every declaration, on every channel. Declare RequiresConfirmation = false on a write that must stay available on those channels.

This default covers [MentorAction] methods only. A method with only [Description] asks for nothing. The first time MentorAgent reads your actions, it logs a warning for the writes that run without confirmation. MentorAgent reads them:

  • at startup, when the host maps the A2A agent or the MCP endpoint, or turns on WarmUpAtStartup;
  • at the first request for the onboarding tour, the short guided tour of the widget (GET /mentor/tour);
  • otherwise, at the first message.

The warning lists the [MentorAction] methods that declare RequiresConfirmation = false, and the methods with only [Description] that are not declared read-only with IsReadOnlyAction.

To turn the default off, set RequireConfirmationForWrites to false. Then only RequiresConfirmation = true asks.

What a method declares decides whether it asks for confirmation, and where it is offered. This table is the whole rule in MentorAgent 1.5.0 for the methods of your classes and the actions registered in code, with the default options. An endpoint declared as an action follows its verb: see the 1.4.0 notes. The other pages link here instead of repeating it.

The method declaresAsks before it runsMCP serverA2A serverTool filtering, on a message that matches nothing
Only [Description]NeverPublishedOn the agent card, and runsCan be sent
Only [Description], and IsReadOnlyAction returns true for its tool nameNeverPublished with readOnlyHintOn the agent card, and runsCan be sent
[MentorAction], with neither ReadOnly nor RequiresConfirmationYes, by defaultWithheldLeft out of the card, and refused at onceNever sent
[MentorAction(ReadOnly = true)], or a [MentorAction] that declares nothing and that IsReadOnlyAction namesNeverPublished with readOnlyHintOn the agent card, and runsCan be sent
[MentorAction(RequiresConfirmation = false)]NeverPublished, with readOnlyHint if it also declares ReadOnly = trueOn the agent card, and runsCan be sent
[MentorAction(RequiresConfirmation = true)]YesWithheldLeft out of the card, and refused at onceNever sent
Any method whose tool name RequiresApproval matchesYesWithheldLeft out of the card, and refused at onceNever sent
[MentorAction(Enabled = false)], and no governor turns it onNever: it does not runNot listedLeft out of the card, and refused at onceNever sent
  • Asking. In the widget the user sees a confirmation box. On the hub and on Server-Sent Events (SSE), your front end receives the request and answers it. A MAUI app shows the box too.
  • Confirmation wins. An action that asks is never read-only: RequiresConfirmation = true and RequiresApproval override ReadOnly = true and IsReadOnlyAction.
  • Roles are a second rule. RequiredRoles adds the role check to any row. The MCP server withholds an action with roles unless McpCallerPrincipal identifies a caller that holds one, the agent card leaves it out, and tool filtering never sends it on a message that matches nothing. Where nobody can answer shows the roles on each channel.
  • A governor can change a row. An IMentorActionGovernor can turn an action on or off, and give it other roles or another confirmation, from outside your code. The MCP server follows its answers. The agent card follows the code and, since 1.5.0, your action policies.
  • RequireConfirmationForWrites = false turns off the default of the third row: such an action runs without asking, like one that declares RequiresConfirmation = false.
  • RequireConfirmation = false, the global switch, turns off every confirmation: the rows that ask run without asking, on A2A tasks too. The MCP server, the agent card and tool filtering still read the declaration, so they leave out the same actions.
  • MentorAgent trusts a read-only declaration. It does not check that the method only reads. Some MCP clients skip their own confirmation for a tool with readOnlyHint, so declare it only on methods that really only read.

The confirmation box shows the description of the action, then the arguments that the model is about to pass:

  • The arguments follow the order of the method's parameters. For an MCP tool, they keep the order in which the model wrote them.
  • Each value is cleaned of control characters and of invisible formatting characters, such as those that change the direction of the text. A value longer than 200 characters is cut.
  • An empty argument is left out.

To write the text yourself, in your own words or in your users' language, set ConfirmationMessage. It returns the text for one call, or null for the default text. The title of the box does not change.

Your own code can read two properties of a [MentorAction] attribute, for example to list your writes. They report what the attribute declares, not whether the action asks:

  • RequiresConfirmation is the value written in the attribute, and false when nothing is written;
  • RequiresConfirmationDeclared is true when the attribute writes RequiresConfirmation, either true or false.

So RequiresConfirmation alone cannot tell the two writes of the example above apart. With the default for writes on, the two properties read:

  • ArchiveCase declares nothing: RequiresConfirmation is false and RequiresConfirmationDeclared is false. It asks for confirmation, by default.
  • CloseDuplicate declares RequiresConfirmation = false: false and true. It does not ask.
  • An action that declares RequiresConfirmation = true: true and true. It asks.
  • IsCaseOpen declares only ReadOnly = true: false and false, like ArchiveCase. It does not ask, because it only reads.

By default, a confirmation box waits until the user answers, presses Stop or closes the session. With ConfirmationTimeout, a box that nobody answers in time counts as rejected: the action does not run, and the model is told that nobody confirmed it in time, not that the user declined. An answer that comes later is ignored. The limit also applies to the actions of specialists and team members, and to a confirmation that a policy asks for.

Tools that come from an MCP server or from a skill have no attribute to put rules on. Two options make the user confirm before one of these tools runs:

Program.cs
// By tool name: an action's snake_case name, or the MCP server's tool name
options.RequiresApproval = tool =>
    tool.StartsWith("delete_", StringComparison.Ordinal)
    || tool is "send_email" or "write_file";

The predicate receives the tool name, not the method name. For an action it is the method name in snake case, with a trailing Async dropped first: CloseCaseAsync is close_case. For an MCP tool it is the name its server gives it. Renaming a method renames its tool, and a predicate written for the old name stops matching without any error.

Gate anything with side effects, anything that touches sensitive data and anything irreversible.

options.RequireConfirmation is true by default. It turns the confirmation boxes of every source on or off at once: attributes, the default for writes, MCP servers and RequiresApproval. With false, no action asks for confirmation. Role checks still run. The only approvals that still appear are those for the MCP servers that the model provider calls directly (HostedMcpServers).

Three names look alike:

NameWhere you set itWhat it does
RequiresConfirmationOn [MentorAction]Asks for confirmation before this action runs
RequireConfirmationForWritesIn AddMentorAgentMakes a [MentorAction] that is not read-only ask for confirmation by default
RequireConfirmationIn AddMentorAgentTurns all confirmation boxes on or off

A method behaves the same whether the coordinator calls it or a specialist or team member does. Specialists and team members call their tools themselves, inside an Agent Framework workflow, where the coordinator's middleware cannot see the calls. So MentorAgent wraps each of their tools. The wrapper keeps these four things working for them:

  • the role check and the confirmation;
  • the progress shown in the widget;
  • the navigation after the action (NavigateTo);
  • the metrics.

Tools named by an agent defined in YAML are wrapped in the same way.

Remote agents are different. They are agents on other hosts that your agent calls over A2A, listed in RemoteAgents. Their tools run on the other host, under that host's rules, so none of your roles applies to what they do. Any user who reaches your agent can reach them. To restrict a remote agent, do one of these:

  • protect the /a2a endpoint on the remote host and give roles to the actions there, as in A2A server;
  • leave the agent out of RemoteAgents on hosts whose users may not use it.

Some channels have no person at the other end to confirm anything. There, an action that needs confirmation is not left waiting: it is not offered to the caller (it is withheld), or it is refused when called. The table shows what happens on each channel:

ChannelAction with RequiredRolesAction with RequiresConfirmation
Widget in Blazor Server, WebAssembly or AutoOffered and run only if the signed-in user holds one of the roles; otherwise left out, and refused if calledConfirmation box before it runs
Widget in .NET MAUIRefused, unless your app registers an AuthenticationStateProvider that returns the signed-in userConfirmation box before it runs
SignalR hub and Server-Sent Events (SSE), from your own front endChecked on the user of the request: offered only to a caller who holds the role; anonymous callers are refusedRequest to the client, answered on POST /mentor/approve
MCP serverWithheld, unless McpCallerPrincipal identifies a caller that holds the roleNever published
A2A serverNot on the agent card (the description that A2A clients read). The turn of the task offers it only to an authenticated caller who holds the role. For any other caller it is left out, and refused if calledLeft out of the agent card, and refused at once if the model calls it

Channels describes each channel.

The hub, SSE, /mcp and /a2a endpoints are open until you protect them. A confirmation raised over SSE, or on a hub connection with no signed-in user, has no owner: whoever holds its actionId can answer it. Keep those endpoints authenticated and treat the actionId as a secret.

A role says who may use an action. Some rules depend on your own data: a permission per company or per record, a rule on the arguments, the state of a record. Write them as an action policy, a class that implements IMentorActionPolicy:

CaseTeamPolicy.cs
public class CaseTeamPolicy : IMentorActionPolicy
{
    // Whether the user may use the action: only the support team closes cases
    public ValueTask<bool> IsAllowedAsync(
        MentorActionRequest request, CancellationToken cancellationToken)
        => ValueTask.FromResult(
            request.ToolName != "close_case"
            || request.User?.HasClaim("team", "support") == true);

    // Before each call: a case that is already closed is not closed again
    public async ValueTask<MentorActionVerdict> BeforeActionAsync(
        MentorActionRequest request, CancellationToken cancellationToken)
    {
        if (request.ToolName != "close_case"
            || request.Arguments?.GetValueOrDefault("caseNumber")?.ToString()
                is not { } caseNumber)
            return MentorActionVerdict.Proceed;

        var store = request.Services.GetRequiredService<ICaseStore>();
        var status = await store.GetStatusAsync(caseNumber);
        return status.Contains("closed", StringComparison.OrdinalIgnoreCase)
            ? MentorActionVerdict.Stop($"Case {caseNumber} is already closed.")
            : MentorActionVerdict.Proceed;
    }
}

Register it in Program.cs, next to an observer:

Program.cs
builder.Services.AddMentorActionPolicy<CaseTeamPolicy>();
builder.Services.AddMentorActionObserver<ActionAuditLog>();
  • IsAllowedAsync decides whether the user may use the action at all. MentorAgent asks it before it offers the actions to the model, on every turn, for the coordinator and for every other agent that works in the turn. An action that it does not allow is left out, like one the user has no role for, and a call to it is refused. It is asked again before every call, and after the user confirms.
  • BeforeActionAsync decides on one call, with its arguments. It answers Proceed, Confirm or Stop. Confirm asks the user even for an action that asks for no confirmation. Stop keeps the call from running, and the model reads your reason. With several policies, the strictest answer wins.
  • A policy that fails stops the call. A policy that throws, or that does not answer within ActionPolicyTimeout, 5 seconds by default, stops the call.

Policies apply on every channel: the widget, the hub, /mentor/chat, the MCP server and A2A tasks. Since 1.3.1, they also decide what specialists, team members and agent sources are offered. Where nobody can confirm, a Confirm refuses the call. Every type and property is in Action policies and observers.

The tools of the MCP servers that your agent uses are written by other people. Since 1.5.0, each request that MentorAgent sends to a policy says who provides the tool, in Provenance. A policy can use it to give those tools stricter rules:

McpToolsPolicy.cs
// Stricter with the tools that your application does not provide itself
public class McpToolsPolicy : IMentorActionPolicy
{
    // The MCP servers that your users may use, by their Name in McpServers
    private static readonly HashSet<string> Trusted =
        new(["docs-search"], StringComparer.OrdinalIgnoreCase);

    // Offered and called only by a signed-in user, from a trusted server
    public ValueTask<bool> IsAllowedAsync(
        MentorActionRequest request, CancellationToken cancellationToken)
        => ValueTask.FromResult(request.Provenance switch
        {
            MentorActionProvenance.Application => true,
            MentorActionProvenance.McpServer =>
                request.ProvenanceName is { } server
                && Trusted.Contains(server)
                && request.User?.Identity?.IsAuthenticated == true,
            // Unknown, or a value of a later version: not trusted
            _ => false,
        });

    // Before each call of a server's tool, the user confirms it
    public ValueTask<MentorActionVerdict> BeforeActionAsync(
        MentorActionRequest request, CancellationToken cancellationToken)
        => ValueTask.FromResult(
            request.Provenance == MentorActionProvenance.Application
                ? MentorActionVerdict.Proceed
                : MentorActionVerdict.Confirm(
                    $"A tool of the server {request.ProvenanceName}"));
}
  • Application is your application: your actions on any agent and on your MCP server, UI actions, forms and recipes.
  • McpServer is a tool of a server in McpServers, and ProvenanceName is that server's Name. When two servers offer a tool with the same name, ProvenanceName is the Name of the first server.
  • Library is one of MentorAgent's own tools, such as navigate_to or remember. Policies are not asked about these tools, and not about the tool of a team either. Observers receive the decisions about both. The decisions about the tool of a team carry Application.
  • Unknown is never trusted. It is the default of a request that you build by hand, and MentorAgent never sends it. Treat Unknown, and any value that a later version adds, as not trusted. The example does this with _ => false.

A server cannot take the name of one of your actions, or of MentorAgent's tools: since 1.4.1 such a tool is left out, with a warning, before any policy sees it. That is the rule mcp.reserved-names. Every decision that an observer receives has the same Provenance and ProvenanceName.

Turn actions on and off from outside the code

Section titled “Turn actions on and off from outside the code”

Your code decides which methods are actions. After a release, you may need to change which actions are on for a customer, which roles they need, and whether they ask for a confirmation, for example from an administration console. Turn an action off in the code with Enabled = false, and decide at run time with an IMentorActionGovernor:

ConsoleGovernor.cs
public class CaseArchive
{
    // Shipped off: it runs only where the governor turns it on
    [MentorAction(Description = "Archives a closed support case",
        Enabled = false, RequiresConfirmation = true)]
    public string ArchiveCase(string caseNumber) =>
        $"Case {caseNumber} archived.";
}

public class ConsoleGovernor(IActionSettings settings)
    : IMentorActionGovernor
{
    // null: what the code says; false: off; true: on
    public ValueTask<bool?> IsEnabledAsync(
        MentorActionRequest request, CancellationToken cancellationToken)
        => settings.IsEnabledAsync(request.ToolName, cancellationToken);

    // null: the code's roles; an empty list: no role needed
    public ValueTask<IReadOnlyList<string>?> GetRequiredRolesAsync(
        MentorActionRequest request, CancellationToken cancellationToken)
        => settings.GetRolesAsync(request.ToolName, cancellationToken);

    // Code: what the code says; Required: ask; None: do not ask
    public ValueTask<MentorConfirmationChoice> GetConfirmationAsync(
        MentorActionRequest request, CancellationToken cancellationToken)
        => ValueTask.FromResult(MentorConfirmationChoice.Code);

    // null: the code's description
    public ValueTask<string?> GetDescriptionAsync(
        MentorActionRequest request, CancellationToken cancellationToken)
        => ValueTask.FromResult<string?>(null);
}

Register it in Program.cs. There can be one per application: a second registration throws.

Program.cs
builder.Services.AddMentorActionGovernor<ConsoleGovernor>();
  • Four answers, each one optional. IsEnabledAsync says whether the action is on, GetRequiredRolesAsync gives its roles, GetConfirmationAsync decides whether the user confirms it, and GetDescriptionAsync gives the description that the model reads. null, or MentorConfirmationChoice.Code, keeps what the code says.
  • An action that is off is nowhere. No agent is offered it, no model reads about it, the MCP server does not list it, and a call to it does not run. The catalog still lists it, with EnabledByDefault set to false.
  • When it is asked. MentorAgent asks the governor when a session builds its tools, on every tools/list of the MCP server, and before every call. The answer comes before the roles, the policies and the confirmation. MentorActionRequest.SessionId names the session, so an answer can stay the same for a whole session.
  • A restriction applies at once, and a widening applies from the next session. A session keeps the tools it was built with. An action turned off is refused at its next call. An action turned on, or a confirmation taken away, applies from the next session. A confirmation added applies from the next call.
  • The governor can widen what the code allows. It can turn on an action that ships off, require no role, or take a confirmation away. Whoever implements it holds that power: check there what may be widened, when, and with whose approval.
  • What the user sees stays the code's. The confirmation box and the bar of the running action keep the description in your code. A description from the governor speaks to the model only.
  • A governor that fails stops the action. A governor that throws, or does not answer within ActionPolicyTimeout, stops the action. Only the type of the exception is logged.
  • The agent card follows the code, not the governor. It is one card for every caller: an action declared with Enabled = false is not on it, even when a governor turns it on. Since 1.5.0, MentorAgent also asks your action policies when it builds the card, and builds the card again when it is older than 30 seconds: see Action policies and observers.
  • Your actions only. The governor decides the actions that IMentorActionCatalog lists, not the tools of the MCP servers that you consume nor MentorAgent's own tools.

The decisions say where an answer came from: MentorActionDecision.RolesFromOutside and ConfirmationFromOutside, and the reason codes disabled and governor-failed. The rules behind these answers, by name, are in How methods become actions.

Filtering the data that a method returns stays in your method, as it does without an agent: a policy decides whether a call runs, not what it returns.

The roles, the confirmation boxes and your policies can be checked by automated tests, with a fake model instead of the real one: see Test without a model.

Every decision of the gate, such as allowed, denied, confirmed, rejected, stopped, run or failed, reaches the observers that you register with AddMentorActionObserver<T>(). Each decision carries the action, the user, who confirmed, the channel, the session and a reason code that stays the same across versions. It never carries the arguments of the call. An observer runs outside the path of the action, so it delays and stops nothing. Use it for an audit trail: see IMentorActionObserver.

Inside an action, MentorActionConfirmation.Current says who confirmed this call, and when. So a ledger of your writes can record who approved each one: see MentorActionConfirmation.

The traces carry the same facts: each mentor.tool.* span has the outcome, the reason code, the confirmation and the channel. See EnableObservability.

In a regulated sector you may have to show who asked for an action, who confirmed it and when. MentorAgent gives your application these facts when the gate decides, but it keeps no durable record of them: it stores no user and no time. Your application builds the record.

What each source holds about a confirmation:

SourceWhat it holdsWhat it does not do
An observer, IMentorActionObserverEvery decision: the action, who asked, who confirmed, when, the channel, the session, the turn and a reason codeIt stores nothing. MentorAgent hands over each decision and keeps no copy, and a decision can be lost (see below)
MentorActionConfirmation.Current, inside your actionWho confirmed this call, and whenIt exists only for a call that runs. A rejected or stopped confirmation never reaches your method
Traces: the mentor.tool.* spansThe outcome, the reason code, the confirmation and the channel of each callThey name no user, and they last as long as your OpenTelemetry backend keeps them
LogsSome events, such as a refused role check or a call to the MCP serverThe user appears only as a fingerprint, caller#…, and the text of log messages can change in any version
OnToolResultThe name of the tool and its result, before the model reads itIt does not know who asked or who confirmed. Use it to remove data from a result
IMentorStateService events, such as OnConfirmationRequired and OnActionStartedThe confirmations and actions of one session, for the component that shows the chatThey exist only where the turn runs, for that session alone

This observer keeps every decision that belongs to a confirmation, one line each, in a store of your own:

ConfirmationLedger.cs
using System.Security.Claims;
using System.Text.Json;
using Novior.MentorAgent.Abstractions.Interfaces;   // IMentorActionObserver
using Novior.MentorAgent.Abstractions.Models;       // MentorActionDecision
using Novior.MentorAgent.Extensions;                // AddMentorActionObserver
ConfirmationLedger.cs
// One line of the record: a decision that belongs to a confirmation
public sealed record ConfirmationRecord(
    DateTimeOffset At, string Tool, string Outcome, string Reason,
    string? AskedBy, string? ConfirmedBy, Guid ConfirmationId,
    string Surface, string? SessionId, string? TurnId);

public interface IConfirmationStore
{
    Task AppendAsync(
        ConfirmationRecord record, CancellationToken cancellationToken);
}

public sealed class ConfirmationLedger(IConfirmationStore store)
    : IMentorActionObserver
{
    public async ValueTask OnDecisionAsync(
        MentorActionDecision decision, CancellationToken cancellationToken)
    {
        // Asked, confirmed, rejected or stopped, and the run that followed
        if (decision.ConfirmationId is not { } confirmationId)
            return;

        await store.AppendAsync(new ConfirmationRecord(
            decision.Timestamp, decision.ToolName,
            decision.Outcome.ToString(), decision.ReasonCode,
            UserId(decision.User), UserId(decision.ConfirmedBy),
            confirmationId, decision.Surface.ToString(),
            decision.SessionId, decision.TurnId), cancellationToken);
    }

    static string? UserId(ClaimsPrincipal? user) =>
        user?.FindFirst(ClaimTypes.NameIdentifier)?.Value
        ?? user?.Identity?.Name;
}

The store of the example appends one JSON line per decision to a file:

JsonLinesConfirmationStore.cs
// Appends one JSON line per record. Decisions can arrive at the same time.
public sealed class JsonLinesConfirmationStore(string path) : IConfirmationStore
{
    readonly SemaphoreSlim _gate = new(1, 1);

    public async Task AppendAsync(
        ConfirmationRecord record, CancellationToken cancellationToken)
    {
        var line = JsonSerializer.Serialize(record) + Environment.NewLine;
        await _gate.WaitAsync(cancellationToken);
        try
        {
            await File.AppendAllTextAsync(path, line, cancellationToken);
        }
        finally
        {
            _gate.Release();
        }
    }
}
Program.cs
builder.Services.AddSingleton<IConfirmationStore>(
    new JsonLinesConfirmationStore(
        builder.Configuration["Audit:Path"] ?? "confirmations.jsonl"));
builder.Services.AddMentorActionObserver<ConfirmationLedger>();
  • What one confirmation leaves. A confirmed call leaves ConfirmationRequested, Confirmed and the outcome of the run: Executed, Failed, Stopped, or Denied when a role was taken away while the box was open. A rejected call leaves ConfirmationRequested and Rejected. Each line has the same ConfirmationId, so you can group the lines of one confirmation.
  • Who is who. User is who asked for the action. ConfirmedBy, on Confirmed, is who confirmed: the caller of POST /mentor/approve, or the signed-in user of the session in a circuit and in a MAUI app. The example keeps the NameIdentifier claim, or the name.
  • No arguments. A decision never carries the arguments of the call, so the record does not say which case was refunded. Record the arguments in the action, as below.
  • The record can miss a decision. No action waits for an observer. Each observer has a queue of 10,000 decisions, and when the queue is full its decisions are dropped, with a warning in the log. A call that takes longer than 5 seconds is no longer awaited. Keep the store fast, and watch for that warning.
  • A record that must be complete is written in the action itself, in the same transaction as the change, with the arguments: MentorActionConfirmation.Current gives who confirmed and when. The observer adds what never reaches your method: rejections, stops and refusals.
  • Where to keep it. A file is enough for the example. In production, use a store that your application can only add to, such as a database table without the right to update or delete, and keep it as long as your rules require.
  • UI actions are in it, since 1.4.0. On Path A, the decisions about the UI actions of a page reach the observers too, with Kind set to UI and the page in PageName.
  • What is not in it. A hosted tool runs at the model provider: for a hosted MCP server that asks for approval, the confirmation is its last decision. On the MCP server, a tool name that nothing defines raises no decision.

The limit, in short. MentorAgent 1.5.0 keeps no durable record of who confirmed what. It gives the decisions to your observers and to MentorActionConfirmation.Current. Storing them, and keeping them complete, is up to your application.

The next three sections cover options that are off by default: tool filtering, the Native mode and RequireActionForChangeRequests.

EnableToolFiltering sends the model only the tools that match the message. The match is by meaning, and it can be wrong: a question about your data can match worse than a greeting. So two rules apply, within ToolFilterMaxTools:

  • When no action matches well enough, MentorAgent still sends the three best-matching actions that need no confirmation and no role. An action without confirmation can therefore reach the model on any message.
  • When every selected action needs confirmation, MentorAgent also sends up to three of the best-matching actions that do not. An action that needs confirmation therefore never travels alone.

The filter uses what you declare, even when the global option RequireConfirmation is false. The last column of Every declaration, on every channel says which actions can be sent when a message matches nothing: a write that declares RequiresConfirmation = false can, and so can a method with only [Description]. Use [MentorAction] for any method that changes data.

You need this section only if you use Agent Framework workflows or hosts, or want AutoApprovalRules. HitlMode chooses how a confirmation travels inside the server. The name comes from human in the loop (HITL): a person confirms an action before it runs. Agent Framework calls a confirmation an approval. The confirmation box and the client protocol are the same in both modes. So are the model calls, with one exception since 1.4.0: in Native mode, CheckAnnouncedActions does not check a turn that asked for a confirmation, so in Blocking mode that turn makes one more call.

Blocking (default)Native
MechanismMentorAgent waits for the answer inside its own codeAgent Framework's own approval mechanism (ApprovalRequiredAIFunction)
Agent runsOne run for the whole turn. The run waits for the answerOne more run after each round of confirmations, approved or declined
Why choose itSimplerWorks with Agent Framework workflows and hosts

A declined confirmation looks the same to the model in both modes. Stop is safe in both modes, too.

  • With Native, Stop pressed while a box waits leaves that request open. The next message answers it as not run, in the same model call as the new question. The conversation then goes on.
  • A snapshot saved after such a Stop, or after a failed run, carries the requests left open and their answers. The first turn after the snapshot is restored answers them.
  • If the run that carried the user's answer fails, MentorAgent marks the outcome of the action as unknown and never runs the action again.

In Native mode, AutoApprovalRules can approve a call before any box appears. The rules run in order, and the first one that returns true approves the call:

Program.cs
options.HitlMode = MentorHitlMode.Native;
options.AutoApprovalRules =
[
    // Approve reads without asking; every other gated tool still prompts.
    ctx => ValueTask.FromResult(
        ctx.FunctionCallContent.Name.StartsWith("get_", StringComparison.Ordinal)),
];

Setting a rule also switches on Agent Framework's "don't ask again": after the user approves a call, matching calls stop asking for the rest of the session. A rule can skip the confirmation question, but it can never skip the role check. MentorAgent checks RequiredRoles in its own tool wrapper, and approval rules do not run there. A call that RequireActionForChangeRequests requires is never approved by a rule: the box always appears. Calls that the model chooses to make on its own can still be approved by a rule.

The tools of specialists and team members always use the blocking flow, even with HitlMode = Native. So AutoApprovalRules never approve them, and "don't ask again" does not remember them. If a rule must approve a tool without showing a box, make it an action of the coordinator, not a tool of a specialist or a team member.

When the model claims a change that it did not make

Section titled “When the model claims a change that it did not make”

The checks on this page run when the model calls an action. A model can also answer "Stock updated" without calling anything. Then no box appears, and nothing changes.

RequireActionForChangeRequests closes this gap. It is off by default. A classifier model reads each message. When the message asks for one of your actions that need confirmation and that the user may run, and gives every input that the action needs, the first model call must call that action. The box then comes before any sentence. A request that leaves an input out is not forced, and the agent may ask for it.

The option needs EnableToolFiltering and an EmbeddingGenerator, and it adds one small classifier call to most turns.

CheckAnnouncedActions, on by default, covers the other side: a reply that claims an action that did not run. After the turn, a classifier reads the reply. When the reply announces an action, such as "I'm adding the note", or reports one as done, and no tool of the turn did it, the agent gets one more request in the same turn, with the same tools. Since 1.4.0 the check also reads turns that called tools: a reply that reports what they did or returned is not an announced action. A turn handed to a specialist, a team or a remote agent is not checked. That request tells the agent to call the tool now, or to say that it was not done. The call passes every check on this page, and the reply already shown stays on screen. The check works on Path A with the history kept by MentorAgent. It costs a few hundred tokens after each turn that it checks: see Cost and latency.

Article 50 of the EU AI Act asks that people know when they are talking to an AI system, and that AI-generated content be marked in a machine-readable way. MentorAgent gives you two tools for it. Whether the article applies to your application, and which words to show, is yours to decide.

  • A notice. The widget shows, under its header, "You are talking to an AI assistant: its replies are generated automatically.", in the language of Language, for the whole conversation. Write your own text with AiDisclosureMessage, or turn the notice off with ShowAiDisclosure.
  • A mark on every reply of the model. data-ai-generated="true" on the reply in the widget, "aiGenerated": true on the frames of /mentor/chat, the hub event ReplyStarted before each reply, and aiGenerated in the metadata of an A2A reply. The mark stays when the notice is off. A front end of your own reads it to show its own notice: see Any front end.

The results of the MCP server, the spoken replies, and the images and files of hosted tools carry no mark.

OWASP lists the risk behind these checks as LLM06:2025 Excessive Agency (external site): damaging actions that an agent takes because the model's output was unexpected, ambiguous or manipulated. Two of its mitigations are the two checks on this page: run actions in the user's context, with the user's own roles, and ask the user to approve an action before it runs. Another mitigation, checking every access to a single record (complete mediation), is done in your code, in your methods or in an action policy: see What stays in your code.

  • Attributes — The parameters of MentorAction, MentorAgent, MentorTeam, TeamMember, MentorPage, MentorSkill and MentorExclude, with their defaults and rules.
  • Action policies and observers — The types that let your code decide on each action, record every decision of the gate, know who confirmed a call, and list the actions.
  • Configuration options — Every MentorOptions property with its type, default and effect, grouped by area, plus the options of the WebAssembly client and the YAML loader.
  • Secure the endpoints — Protect the SignalR hub, Server-Sent Events, /mcp and /a2a endpoints with authentication and CORS before you expose them.