Skip to content

Allow tagging coalesce methods, behaviors and DataSources with a tag to generate methods to be used by Semantic Kernel #550

Open
@meghanmae

Description

@meghanmae

It would be helpful to allow tagging Datasources, methods and behaviors (although we may want to punt the implementation of writing... Maybe just support reading for this issue's scope of work?) with a tag that takes in a description to then allow Coalesce to generate methods that can be leveraged by Semantic Kernal's function calling.

Ideally, Coalesce would add some additional logic to respect any security attributes defined for the model or the method being tagged that would perform identity checks on a user before calling the core logic of the tagged method.

Coalesce should also register the files it generates as 'plugins' in the app's configuration. We may need to discuss how this would work if a user wanted to do a mixture of using coalesce to register sementic kernel functions as well as register their own (e.g. skip the coalesce generation bit).

services.AddScoped(sp =>
{
    var kernelBuilder = Kernel.CreateBuilder()
        .AddAzureOpenAIChatCompletion("<deployed AI model name>", "<OpenAI API Key>");

    // Build the Kernel
    var kernel = kernelBuilder.Build();

    // Register any plugins if necessary
    kernel.Plugins.AddFromType<PeopleKernelPlugin>("PeopleKernelPlugin", sp);

    return kernel;
});

Proposed structure? I'm not 100% confident in how this should look, but a general idea to get started with:

// Tagging a DataSource to expose “Get People” to Semantic Kernel
[KernelFunction("Returns a list of people in the system, optionally filtered by status.")]
public class PersonDataSource : StandardDataSource<Person, AppDbContext>
{
    // Inherit all standard methods? The other option is to tag each overriden method rather than the whole class. 
}
// Some generated file
[KernelFunction("person_data_source")] // Function calling generally preforms better when named with snakecase - we may want to investigate latest guidelines around this though. 
[Description("Gets a list of people")]
// Some other attributes that may be helpful to generate are things like
// [return: Description("<description of what this method returns>")]
// a  [Description("")] attribute on each method parameter
public IQueryable<Person> GetPeople(){ /* Method logic */ } // The naming of these methods are just ball park - but there should just be methods semantic kernel can call that get generated off of the tagged datasource's standard methods. These methods should have simple method parameters if they take any additional filters.
public IQueryable<Person> SearchPeople(){/* Method logic */}

The main goal of this request is to allow me to re-use existing methods for sementic kernel function calling so I don't need to go write dedicated methods that possibly re-implement or write shared service classes that detail core business logic already defined in my model methods, behaviors and datasources.

We may want to sync on this further before implementation begins - I think there are details that may need to be ironed out further.

  • Structure-wise, is the above close enough? Maybe we should try and solidify this further. The descriptions are essentially prompts for AI and the quality of a prompt impacts AI's ability and performance significantly.
  • Is there any desire to add any kind of front end support for this that coalesce auto-generates (e.g. we will need a service on the backend that triggers the function calling... Does a user implement this, does Coalesce implement this? If Coalesce implements this do we want to add some additional support for sending back context of the current page the user made the call from?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions