AssistantSettings Class

Assembly: CodeEffects.Rule.Repository.dll
Namespace: CodeEffects.Rule.Repository

Summary

Holds the AI models that you register for the AI Assistant and the AI Rule Editor of the Rule Repository, and settings for how the two features behave: steps per turn, attached files, conversation retention, your own instructions, and callbacks for usage and limits.

Syntax

public class AssistantSettings

Remarks

Set an instance on the Assistant property of your IRepositoryConfiguration, for example on a Configuration object. Like the rest of the configuration, you supply it on every request, so you may give different users different models, or none.

When Assistant is null, or Models is empty, neither feature exists for the request: there is no AI button, no AI Rule Editor tab, and every AI request is refused. With at least one model, a user still needs the AiAssistantUse action permission to use the AI Assistant and the AiRuleEditorUse permission to use the AI Rule Editor. Users who hold AiConversationViewAll may also read the conversations of other users.

The AI features act for the signed-in person. The current user of the request must be of type UserType.User and must have no CurrentAgentId; otherwise the request is refused. The assistant works under that person's permissions and under the same rules as other AI agents: its instructions tell it never to make anything live, approve, or delete, and every rule version it saves requests approval. The user activity names the assistant as the AI agent acting for the person, using AgentId and AgentName. See also AgentSettings, which applies to the assistant as it does to other agents.

The repository checks the settings when it uses them. A model without a valid Key or without a ChatClient, two models with the same key, and a MaxSteps, MaxAttachmentBytes, or ConversationRetentionDays below 1 are refused with the control number CE10252.

Every step of a turn is one repository request that lasts one model call and its tools: usually seconds, sometimes a minute. The request timeout of your host must allow that.

Constructors

  • AssistantSettings()

    Initializes a new instance of the AssistantSettings class with the default values of all properties.

Properties

  • AgentId

    Type: System.String

    Gets or sets the ID that identifies the assistant in the user activity: the ID of the AI agent that acts for the person. The default value is "rr-assistant", which is also used when the value is empty.

  • AgentName

    Type: System.String

    Gets or sets the assistant's display name in the user activity. The default value is "AI Assistant", which is also used when the value is empty.

  • AllowAttachments

    Type: System.Boolean

    Gets or sets whether users may attach files in the AI Assistant. The default value is true. When it is false, the paperclip is not shown, uploads are refused, and your endpoint needs no room for a file. Files that were attached before stay readable.

  • AttachmentStore

    Type: CodeEffects.Rule.Repository.IAttachmentStore

    Gets or sets where attached files are kept. The default value is null: the repository's own database. FolderAttachmentStore keeps them in a folder, or you can supply your own implementation, for example for Azure Blob Storage or Amazon S3.

  • CanStep

    Type: System.Func<CodeEffects.Rule.Repository.AssistantStepInfo, System.String>

    Gets or sets an optional callback that the repository calls before every model call of a turn, after it has checked MaxSteps. Return null to let the step run. Return a message to stop the turn: the message is shown to the user, for example "You have used this month's AI quota". The default value is null.

  • ConversationRetentionDays

    Type: System.Int32

    Gets or sets how many days a conversation is kept after it was last used. The default value is 90. Conversations of both the AI Assistant and the AI Rule Editor that were not used for longer are deleted, with their files, when a new conversation is started.

  • Instructions

    Type: System.String

    Gets or sets optional instructions of your own to the model. They are added after the repository's own instructions, under the heading "The application's own instructions". Use them for your company's terms, what your rules are for, or what the assistant should not do. The default value is null.

  • KeepAttachments

    Type: System.Boolean

    Gets or sets whether attached files are kept with their conversation after the turn that used them. The default value is false: a file is kept only until its turn ends, and a reopened conversation tells the model that the file is no longer available.

  • MaxAttachmentBytes

    Type: System.Int32

    Gets or sets the size of the largest file that a user may attach, in bytes. The default value is 10485760 (10 MB). A file arrives in one request as base64 text, which is a third larger, so your endpoint must accept requests that large. The request limit of RequestLimits.RequestLength is raised for the request as far as needed.

  • MaxSteps

    Type: System.Int32

    Gets or sets the most model calls that one turn makes before it stops and offers the user to continue. A turn starts when the user sends a message or continues. The default value is 25.

  • Models

    Type: System.Collections.Generic.IList<CodeEffects.Rule.Repository.AssistantModel>

    Gets or sets the models that the user picks from. The first model is the default, and it is also used when a conversation names a model that this request no longer has. The default is an empty list, which means that the AI features do not exist.

  • OnUsage

    Type: System.Action<CodeEffects.Rule.Repository.AssistantUsage>

    Gets or sets an optional callback that the repository calls with the tokens that a model call used, for your own logging, billing, or charts. It is called once for each model call, after the step has been stored. The repository keeps the same numbers either way. The default value is null.

    Example

      using System;
      using System.Collections.Generic;
      using CodeEffects.Rule.Repository;
      using Microsoft.Extensions.AI;
    
      var configuration = new Configuration
      {
      	Assistant = new AssistantSettings
      	{
      		Models = new List<AssistantModel>
      		{
      			new AssistantModel { Key = "main", DisplayName = "Main model", ChatClient = chatClient } // chatClient: the IChatClient you built with your vendor's package
      		},
      		MaxSteps = 15,
      		AttachmentStore = new FolderAttachmentStore("/var/data/assistant-files"),
      		KeepAttachments = true,
      		Instructions = "Our rules decide loan approvals. Never suggest changing a credit limit.",
      		OnUsage = usage => Console.WriteLine(usage.UserId + " used " + (usage.InputTokens + usage.OutputTokens) + " tokens"),
      		CanStep = step => step.Step > 10 && step.UserId == "guest" ? "Guests are limited to ten steps a turn." : null
      	}
      };
    

Ask on Stack Overflow - Yes, it's still active
Ask in GitHub Discussions

p102

l097 --

l102

p101

×