Create your own skill
A skill is a class that can be added to an agent to extend its capabilities.
Create the csharp class
To create a new skill, you should add a new class that implements the IAISkill interface.
You can add a 'GroupeIsa.Neos.Application.AI.Skills.SkillDescriptionAttribute' above the class declaration to describe the skill. The description should reference a resource key and a resource class.
[SkillDescription(typeof(Properties.Resources), "MySkillDescription")]
public class MySkill : IAISkill
Add instructions
Your skill can add some instructions to the agent
To add instructions to the agent, you should implements the Instructions property from the IAISkill interface.
You can use plain text for instruction or markdown.
These instructions will be added after the agent instructions.
Note
In instructions the assistant refers to himself in the first person singular.
public string Instructions => @"- I can create a maximum of 50 items at a time, if the user wants to create more items, he must do it in several steps.
- In my final answer :
- I explain my thinking and the choices I made.";
To reference a function of a skill in the instruction of the agent, you should use the following syntax: {SkillName}-{FunctionName} :
public string Instructions => @"To create an item, you must follow these steps:
1. I call the {nameof(EntitiesExplorerSkill)}-{nameof(EntitiesExplorerSkill.GetWritableEntityViews)} function to get the list of entities that can be created to find the entity name.
2. I call the {nameof(DataCreatorSkill)}-{nameof(DataCreatorSkill.GetEntityViewJsonSchema)} function to get the JSON schema needed to create an item with the entity name obtain in previous step.
3. I call the {nameof(DataCreatorSkill)}-{nameof(DataCreatorSkill.CreateEntityViewAsync)} function create the item with the JSON created with the JSON schema obtain in previous step.";
Or you can use the AITool attribute to explicitly give a name to the function.
[AITool("CreateOrder")])]
public async Task CreateOrderAsync()
{
// Your code here
}
public string Instructions => @"To create an order, you must call the 'CreateOrder' function.";
When DependencyInstructions is not defined or return null, the main instructions are used. If you want to remove the instructions, you should return an empty string.
public string DependencyInstructions => string.Empty;
Note
If a dependency skill is directly assigned to an agent, the dependency instructions are not used.
Add AI functions
Your skill can add AI functions to the agent. These functions can be called by the agent to perform specific tasks.
A AI function is a method decorated with the AITool attribute.
[AITool]
public async Task CreateOrderAsync()
{
// Your code here
}
You can add a name to the AI function else the name of the method will be used.
[AITool("CreateOrder")]
public async Task CreateOrderAsync()
{
// Your code here
}
You should add descriptions to your AI functions to help the agent to understand the purpose of the function.
[AITool]
Description("Create an order")]
public async Task CreateOrderAsync()
{
// Your code here
}
If your function needs parameters, you should add them to the method and you should describe them.
[AITool]
Description("Create an order")]
public async Task MySkillFunctionAsync([Description("The ID of the order")] string id, [Description("The customer name ")] string customerName)
{
// Your code here
}
If your function returns a value, you should add the return type to the method and you should describe it.
[AITool]
[Description("Create an order")]
[return: Description("The result of the creation")]
public async Task<string> MySkillFunctionAsync([Description("The ID of the order")] string id, [Description("The customer name ")] string customerName)
{
// Your code here
return "Order created";
}
Note
It is important to add descriptions to your AI functions to help the LLM to understand the purpose of the function. You can reference a function of a skill in the instructions when you want the LLM to follow certain steps.
Add dependencies
Your skill can have dependencies on other skills, which means that your skill needs to use the AI functions of other skills.
For example, if your skill needs to use the DataCreator Skill and the EntitiesExplorer Skill, you should add the following code to your skill:
public override IEnumerable<Type> Dependencies => [typeof(IDataCreatorSkill), typeof(IEntitiesExplorerSkill)];
Note
If you not specify dependencies, the skill will not be able to use the AI functions of other skills unless they are directly assigned to the agent.
Note
For the skill provided by Neos, you should use the interface of the skill, because the implementation is not accessible.
Make the skill available to agents
To make the skill available to agents, you need to configure the skill in the service container.
To do this, you need to register the skill service in the ConfigureServices method of the Startup class of the business assembly.
Examples :
- Skill registered as scoped service :
services.AddScoped<IAISkill, MySkill>();
- Skill registered as singleton service :
services.AddSingleton<IAISkill, MySkill>();
You should use correct registration type according to the skill implementation.
Note
The cluster solution must be built to take into account the new skill.
Example
You can find an example of skill creation at Create a skill to search in documents