In this walkthrough, you'll learn how to create a basic Assistant extension using the Greeting extension as an example. The Greeting extension takes a user's name as input and generates a personalized greeting message. You'll go through the following steps:
Add an Assistant Extension Task: Go to Assistant's development mode and click the "Create" button. Choose the default template and give your extension a name; for this example, name it "GreetingExtension." This step initializes the extension project and provides you with the required files to get started.
For detailed instructions, refer to the Create Assistant Extension guide.
The template includes a default GreetingArgs class. This class defines the input parameters for your extension. In this case, we've added a single parameter, Name, which will capture the user's name.
public class GreetingArgs
{
// This property captures the user's name.
[Description("Your Name")]
[ControlData(ToolTip = "Enter your name")]
public string Name { get; set; }
}
The template also includes a default GreetingCommand class. This class defines the behavior of your extension when executed. In this example, we've created a command that greets the user using their provided name.
public class GreetingCommand : IAssistantExtension<GreetingArgs>
{
public async Task<IExtensionResult> RunAsync(IAssistantExtensionContext context, GreetingArgs args, CancellationToken cancellationToken)
{
// Check if the provided arguments are valid.
if (string.IsNullOrWhiteSpace(args.Name))
{
// If the name is not provided, return a failure result with a message.
return Result.Text.Failed("Please provide your name.");
}
// If the name is provided, return a success result with a personalized greeting message.
return Result.Text.Succeeded($"Hello, {args.Name}! Welcome to Assistant!");
}
}
You can test your extension in Assistant by entering your name. When you execute the extension, it will use your name to generate a personalized greeting message.