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 SimpleCommand
This will create a new folder named SimpleCommand containing C# project named SimpleCommand, and a code file named Class1.cs.
- Rename the file
Class1.cs
toCommand.cs
-
Rename the class in the code to
Command
namespace SimpleCommand; public class Command { }
-
In the
SimpleCommand.csproj
file make sure theTargetFramework
isnet8.0
<TargetFramework>net8.0</TargetFramework>
-
In the
SimpleCommand.csproj
file add aTargetExt
field below theTargetFramework
line<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 --prerelease
This will add the reference to the
SimpleCommand.csproj
file<ItemGroup> <PackageReference Include="naquared.agents.api" /> </ItemGroup>
-
In the
Command.cs
file add ausing
to import thensquared.agents
namespaceusing nsquared.agents;
-
In the
Command.cs
file implement theIAgentCommand
interface in the Command classpublic class Command : IAgentCommand
-
Add the required methods to the
Command
classusing 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.Command
file 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
simple
in your request