nsquared agents

Downloads and guides for the nsquared agents desktop characters.

View on GitHub

Building a Simple Command

To build a command for nsquared agents, create a .NET 10 class library with a class that implements the IAgentCommand interface. Use the latest stable nsquared.agents.api NuGet package.

The full source code for this example

Step-by-Step creating a simple nsquared agent Command

  1. Start by creating a new C# class library project named SimpleCommand.

     dotnet new classlib --name SimpleCommand
    

    This will create a new folder named SimpleCommand containing C# project named SimpleCommand, and a code file named Class1.cs.

  2. Rename the file Class1.cs to Command.cs
  3. Rename the class in the code to Command

     namespace SimpleCommand;
     public class Command
     {
     }
    
  4. In the SimpleCommand.csproj file set the framework and command file extension:

     <TargetFramework>net10.0</TargetFramework>
     <TargetExt>.Command</TargetExt>
    
  5. Add the API package:

    dotnet add package nsquared.agents.api
    
  6. In the Command.cs file add a using to import the nsquared.agents namespace

     using nsquared.agents;
    
  7. In the Command.cs file implement the IAgentCommand interface in the Command class

     public class Command : IAgentCommand
    
  8. Add the required methods to the Command class

     using nsquared.agents;
    
     namespace SimpleCommand;
     public class Command : IAgentCommand
     {
         public string Name => "SimpleCommand";
    
         public bool HasSettings => false;
         public AgentCommandType CommandType => AgentCommandType.KeywordLocal;
    
         public Task<string?> Perform(string commandRequest, IAgentAnimations? animations)
         {
             if (commandRequest.Contains("simple", StringComparison.CurrentCultureIgnoreCase))
             {
                 animations?.Animate("Announce");
                 return Task.FromResult<string?>("I am doing a simple command!");
             }
             return Task.FromResult<string?>(null);
         }
     }
    
  9. Build the SimpleCommand project. It produces SimpleCommand.Command in the build output folder. This example has no additional dependencies and can be installed as a single file. If your command uses additional NuGet packages, include its assembly and required dependency DLLs in a flat .zip file with exactly one .Command file at the archive root. The running application accepts either the .Command file or ZIP from Settings > Manage Commands.

  10. Run the nsquared agents application and open Settings, and then go to Manage Commands

    Manage Commands Menu in Settings

  11. In the Commands select Add

    Remove SimpleCommand from Commands

  12. Find the SimpleCommand.Command file you have built.

    Remove SimpleCommand from Commands

  13. Invoke the SimpleCommand by using the keyword simple in your request

Doing a simple command

The full source code for this example

Building a Command with Settings

Building a Skill