Building a Simple Command
In order to build a new activity for nsquared agents you will need to build a .NET 8.0 assembly that contains a class that implements the IAgentCommand interface.
Step-by-Step creating a simple nsquared agent Command
-
Start by creating a new C# class library project named SimpleCommand.
dotnet new classlib --name SimpleCommandThis will create a new folder named SimpleCommand containing C# project named SimpleCommand, and a code file named Class1.cs.
- Rename the file
Class1.cstoCommand.cs -
Rename the class in the code to
Commandnamespace SimpleCommand; public class Command { } -
In the
SimpleCommand.csprojfile make sure theTargetFrameworkisnet8.0<TargetFramework>net8.0</TargetFramework> -
In the
SimpleCommand.csprojfile add aTargetExtfield below theTargetFrameworkline<TargetExt>.Command</TargetExt> -
Add a package reference to the nsquared.agents NuGet package, from PowerShell you can do this with the following command.
dotnet add package nsquared.agents.api --prereleaseThis will add the reference to the
SimpleCommand.csprojfile<ItemGroup> <PackageReference Include="naquared.agents.api" /> </ItemGroup> -
In the
Command.csfile add ausingto import thensquared.agentsnamespaceusing nsquared.agents; -
In the
Command.csfile implement theIAgentCommandinterface in the Command classpublic class Command : IAgentCommand -
Add the required methods to the
Commandclassusing nsquared.agents; namespace SimpleCommand; public class Command : IAgentCommand { public string Name => "SimpleCommand"; public bool HasSettings => false; public AgentCommandType CommandType => AgentCommandType.KeywordLocal; Task<string?> IAgentCommand.Perform(string commandRequest, IAgentAnimations? animations) { if (commandRequest.Contains("simple", StringComparison.CurrentCultureIgnoreCase)) { return Task.FromResult<string?>("I am doing a simple command!"); } return Task.FromResult<string?>(null); } } -
Build the SimpleCommand project. It should build the
SimpleCommand.Commandfile in a bin folder. -
Run the nsquared agents application and open Settings, and then go to
Manage Commands
-
In the Commands select Add

-
Find the SimpleCommand.Command file you have built.

- Invoke the SimpleCommand by using the keyword
simplein your request
