MentorAgent Docs
Menu

Questa pagina non è ancora tradotta in italiano: qui la trovi in inglese.

ReferencePackage: Novior.MentorAgent

MentorActionRegistrations class

The MentorActionRegistrations class of Novior.MentorAgent.Options: The actions the application registers in code, without attributes: MentorOptions.Actions…

On this page

The actions the application registers in code, without attributes: MentorOptions.Actions. Each one is a public instance method of a class the application registers in its services, with what [MentorAction] would declare.

A registered action is one of the coordinator's actions, like a [MentorAction] method found in MentorOptions.ScanAssemblies: it is named after its method, and the same roles, confirmations, IMentorActionGovernor, MCP server and A2A card apply. The registrations are read once, when MentorAgent first discovers the actions. A mistake — a method that is not there, a registration without a description, a method that is already an action by its attributes — stops the application when it starts, naming the method.

Example
options.Actions.Add<OrderActions>(nameof(OrderActions.CancelOrderAsync), action => action
    .Describe("Cancels an order that has not shipped yet")
    .RequireRoles("Manager")
    .RequireConfirmation());

A command or a query is registered the same way, as a type of its own with its handler: MentorActionRegistrations.AddCommand and MentorActionRegistrations.AddQuery.

Namespace: Novior.MentorAgent.Options. Package: Novior.MentorAgent.

public sealed class MentorActionRegistrations

Terminal
dotnet add package Novior.MentorAgent

public int Count { get; }

How many actions are registered.

public MentorActionRegistrations Add<T>(string method, Action<MentorActionBuilder> configure)

Registers method of T as an action of the coordinator.

Parameters

  • method: The name of a public instance method declared on T itself, not generic and the only one with that name — written with nameof, it follows a rename.
  • configure: What the action declares; MentorActionBuilder.Describe is required.

Returns: These registrations, to add the next one.

Exceptions

  • ArgumentException: T is not a concrete class, it has no such method or more than one, the method is static or generic, or the action has no description.

public MentorActionRegistrations Add(Type type, string method, Action<MentorActionBuilder> configure)

Registers method of type as an action of the coordinator: the form for code that is generated, where the type is known by name.

Parameters

  • type: A class the application registers in its services: MentorAgent asks them for the instance.
  • method: The name of a public instance method declared on type itself, not generic and the only one with that name.
  • configure: What the action declares; MentorActionBuilder.Describe is required.

Returns: These registrations, to add the next one.

Exceptions

  • ArgumentException: type is not a concrete class, it has no such method or more than one, the method is static or generic, or the action has no description.

public MentorActionRegistrations AddCommand<TCommand, THandler>(Action<MentorActionBuilder> configure)

Story 1286 — registers the command TCommand as an action of the coordinator, run by THandler: a request that changes data, written as a type of its own. The action is named after the type in snake_case (CancelOrder is cancel_order) unless MentorActionBuilder.Name names it; its parameters are the type's public properties, which the model gives; it is a write, so the default confirmation for writes applies, and the same roles, governor, policies, MCP server, A2A card and teams apply as to a method registered with MentorActionRegistrations.Add.

Example
public sealed record CancelOrder(int OrderId, string Reason);
public sealed class CancelOrderHandler(OrderStore store) : IMentorCommandHandler<CancelOrder>
{
    public Task HandleAsync(CancelOrder command, CancellationToken ct) => store.CancelAsync(command.OrderId, command.Reason, ct);
}

builder.Services.AddScoped<CancelOrderHandler>();
options.Actions.AddCommand<CancelOrder, CancelOrderHandler>(a => a.Describe("Cancels an order that has not shipped"));

Parameters

Returns: These registrations, to add the next one.

Exceptions

  • ArgumentException: TCommand is not an object with properties, THandler is not a concrete class or does not handle the command once, the action has no description, its name is not a tool name, or it is declared MentorActionBuilder.ReadOnly.

public MentorActionRegistrations AddQuery<TQuery, THandler>(Action<MentorActionBuilder> configure)

Story 1286 — registers the query TQuery as an action of the coordinator, answered by THandler: a request that only reads, written as a type of its own. The action is named after the type in snake_case unless MentorActionBuilder.Name names it; its parameters are the type's public properties; it is always read-only, and the model reads what the handler returns. The same roles, confirmation, governor, policies, MCP server, A2A card and teams apply as to a method registered with MentorActionRegistrations.Add.

Example
public sealed record FindOrder(int OrderId);
public sealed class FindOrderHandler(OrderStore store) : IMentorQueryHandler<FindOrder, OrderView?>
{
    public Task<OrderView?> HandleAsync(FindOrder query, CancellationToken ct) => store.FindAsync(query.OrderId, ct);
}

builder.Services.AddScoped<FindOrderHandler>();
options.Actions.AddQuery<FindOrder, FindOrderHandler>(a => a.Describe("Reads one order"));

Parameters

Returns: These registrations, to add the next one.

Exceptions

  • ArgumentException: TQuery is not an object with properties, THandler is not a concrete class or does not answer the query once, the action has no description, or its name is not a tool name.