diff --git a/Elsa.SemanticKernel/Activities/SemanticKernel.cs b/Elsa.SemanticKernel/Activities/SemanticKernel.cs index 3883ffe90..f3beac43e 100644 --- a/Elsa.SemanticKernel/Activities/SemanticKernel.cs +++ b/Elsa.SemanticKernel/Activities/SemanticKernel.cs @@ -33,6 +33,12 @@ namespace Elsa.SemanticKernel; [PublicAPI] public class SemanticKernelSkill : CodeActivity { + //constructor - called by the workflow engine + public SemanticKernelSkill(string? source = default, int? line = default) : base(source, line) + { + + } + [Input( Description = "System Prompt", UIHint = InputUIHints.MultiLine, @@ -89,34 +95,8 @@ public class SemanticKernelSkill : CodeActivity } else { - var kernelSettings = KernelSettings.LoadSettings(); - var kernelConfig = new KernelConfig(); - - using ILoggerFactory loggerFactory = LoggerFactory.Create(builder => - { - builder - .SetMinimumLevel(kernelSettings.LogLevel ?? LogLevel.Warning); - }); - /* var memoryStore = new QdrantMemoryStore(new QdrantVectorDbClient("http://qdrant", 1536, port: 6333)); - var embedingGeneration = new AzureTextEmbeddingGeneration(kernelSettings.EmbeddingDeploymentOrModelId, kernelSettings.Endpoint, kernelSettings.ApiKey); - var semanticTextMemory = new SemanticTextMemory(memoryStore, embedingGeneration); - */ - var kernel = new KernelBuilder() - .WithLogger(loggerFactory.CreateLogger()) - .WithAzureChatCompletionService(kernelSettings.DeploymentOrModelId, kernelSettings.Endpoint, kernelSettings.ApiKey, true, kernelSettings.ServiceId, true) - //.WithMemory(semanticTextMemory) - .WithConfiguration(kernelConfig) - .Configure(c => c.SetDefaultHttpRetryConfig(new HttpRetryConfig - { - MaxRetryCount = maxRetries, - UseExponentialBackoff = true, - // MinRetryDelay = TimeSpan.FromSeconds(2), - // MaxRetryDelay = TimeSpan.FromSeconds(8), - MaxTotalRetryTime = TimeSpan.FromSeconds(300), - // RetryableStatusCodes = new[] { HttpStatusCode.TooManyRequests, HttpStatusCode.RequestTimeout }, - // RetryableExceptions = new[] { typeof(HttpRequestException) } - })) - .Build(); + // get the kernel + var kernel = KernelBuilder(); /* var interestingMemories = kernel.Memory.SearchAsync("ImportedMemories", prompt, 2); var wafContext = "Consider the following contextual snippets:"; @@ -173,12 +153,53 @@ public class SemanticKernelSkill : CodeActivity //context.Set("wafContext", wafContext); - SKContext answer = await kernel.RunAsync(contextVars, function).ConfigureAwait(false); + SKContext answer = await kernel.RunAsync(contextVars, functionName).ConfigureAwait(false); string result = answer.Result; - + workflowContext.SetResult(result); } } + + /// + /// Gets a semantic kernel instance + /// + /// Microsoft.SemanticKernel.IKernel + private IKernel KernelBuilder() + { + var kernelSettings = KernelSettings.LoadSettings(); + var kernelConfig = new KernelConfig(); + + using ILoggerFactory loggerFactory = LoggerFactory.Create(builder => + { + builder.SetMinimumLevel(kernelSettings.LogLevel ?? LogLevel.Warning); + }); + + /* + var memoryStore = new QdrantMemoryStore(new QdrantVectorDbClient("http://qdrant", 1536, port: 6333)); + var embedingGeneration = new AzureTextEmbeddingGeneration(kernelSettings.EmbeddingDeploymentOrModelId, kernelSettings.Endpoint, kernelSettings.ApiKey); + var semanticTextMemory = new SemanticTextMemory(memoryStore, embedingGeneration); + */ + + var kernel = new KernelBuilder() + .WithLogger(loggerFactory.CreateLogger()) + .WithAzureChatCompletionService(kernelSettings.DeploymentOrModelId, kernelSettings.Endpoint, kernelSettings.ApiKey, true, kernelSettings.ServiceId, true) + //.WithMemory(semanticTextMemory) + .WithConfiguration(kernelConfig) + .Configure(c => c.SetDefaultHttpRetryConfig(new HttpRetryConfig + { + MaxRetryCount = maxRetries, + UseExponentialBackoff = true, + // MinRetryDelay = TimeSpan.FromSeconds(2), + // MaxRetryDelay = TimeSpan.FromSeconds(8), + MaxTotalRetryTime = TimeSpan.FromSeconds(300), + // RetryableStatusCodes = new[] { HttpStatusCode.TooManyRequests, HttpStatusCode.RequestTimeout }, + // RetryableExceptions = new[] { typeof(HttpRequestException) } + })) + .Build(); + + return kernel; + } + /// /// Gets a list of the skills in the assembly /// diff --git a/README.md b/README.md index 9104fdfbb..4e01b8e0e 100644 --- a/README.md +++ b/README.md @@ -1,13 +1,20 @@ + # sk-dev-team + # Build a Virtual AI Dev Team using Semantic Kernel Skills + ## Status -This is a nascent project - we will use the README to describe the project's intent - as we build it out we will document what exists and eventually move roadmap/intent to the discussion. + +This is a nascent project - we will use the README to describe the project's intent - as we build it out we will document what exists and eventually move roadmap/intent to the discussion. ## Trying it out + ## Via Workflows + The project supports running Semantic Kernel Skills as workflows using [Elsa Workflows](https://v3.elsaworkflows.io). You can build the workflows as .NET code or in the visual designer. To run the designer: -``` + +```bash > cd WorkflowsApp > cp .env_example .env # Edit the .env file to choose your AI model, add your API Endpoint, and secrets. @@ -17,13 +24,16 @@ To run the designer: # Open browser to the URI in the console output ``` -Once you have the app runing locally, you can login (admin/password - see the [Elsa Workflows](https://v3.elsaworkflows.io) for info about securing). Then you can click "new workflow" to begin building your workflow with semantic kernel skills. +Once you have the app runing locally, you can login (admin/password - see the [Elsa Workflows](https://v3.elsaworkflows.io) for info about securing). Then you can click "new workflow" to begin building your workflow with semantic kernel skills. ## Via CLI + The easiest way to run the project is in Codespaces. Codespaces will start a qdrant instance for you. + 1. Create a new codespace from the *code* button on the main branch. 2. Once the code space setup is finished, from the terminal: -``` + +```bash > cd cli cli> cp ../WorkflowsApp/.env_example . # Edit the .env file to choose your AI model, add your API Endpoint, and secrets. @@ -31,54 +41,60 @@ cli> bash .env cli> dotnet build cli> dotnet run --file util/ToDoListSamplePrompt.txt do it ``` -You will find the output in the *output/* directory. + +You will find the output in the *output/* directory. # Goal -From a natural language specification, set out to integrate a team of AI copilot skills into your team’s dev process, either for discrete tasks on an existing repo (unit tests, pipeline expansions, PRs for specific intents), developing a new feature, or even building an application from scratch. Starting from an existing repo and a broad statement of intent, work with multiple AI copilot dev skills, each of which has a different emphasis - from architecture, to task breakdown, to plans for individual tasks, to code output, code review, efficiency, documentation, build, writing tests, setting up pipelines, deployment, integration tests, and then validation. -The system will present a view that facilitates chain-of-thought coordination across multiple trees of reasoning with the dev team skills. + +From a natural language specification, set out to integrate a team of AI copilot skills into your team’s dev process, either for discrete tasks on an existing repo (unit tests, pipeline expansions, PRs for specific intents), developing a new feature, or even building an application from scratch. Starting from an existing repo and a broad statement of intent, work with multiple AI copilot dev skills, each of which has a different emphasis - from architecture, to task breakdown, to plans for individual tasks, to code output, code review, efficiency, documentation, build, writing tests, setting up pipelines, deployment, integration tests, and then validation. +The system will present a view that facilitates chain-of-thought coordination across multiple trees of reasoning with the dev team skills. + ## Proposed UX + * Possible UI: Start with an existing repo (GH or ADO), either populated or empty, and API Keys / config for access – once configured / loaded split view between three columns: -** Settings/History/Tasks (allows browsing into each of the chats with a copilot dev team role) | [Central Window Chat interface with Copilot DevTeam] | Repo browsing/editing -** Alternate interface will be via VS Code plugin/other IDE plugins, following the plugin idiom for each IDE -** Settings include teams channel for conversations, repo config and api keys, model config and api keys, and any desired prompt template additions + * Settings/History/Tasks (allows browsing into each of the chats with a copilot dev team role) | [Central Window Chat interface with Copilot DevTeam] | Repo browsing/editing + * Alternate interface will be via VS Code plugin/other IDE plugins, following the plugin idiom for each IDE + * Settings include teams channel for conversations, repo config and api keys, model config and api keys, and any desired prompt template additions * CLI: start simple with a CLI that can be passed a file as prompt input and takes optional arguments as to which skills to invoke -* User begins with specifying a repository and then statement of what they want to accomplish, natural language, as simple or as detailed as needed. -** SK DevTeam skill will use dialog to refine the intent as needed, returns a plan, proposes necessary steps -** User approves the plan or gives feedback, requests iteration -** Plan is parceled out to the appropriate further skills -** Eg, for a new app: -*** Architecture is passed to DevLead skill gives plan/task breakdown. -*** DevLead breaks down tasks into smaller tasks, each of these is fed to a skill to decide if it is a single code module or multiple -*** Each module is further fed to a dev lead to break down again or specify a prompt for a coder -*** Each code module prompt is fed to a coder -*** Each module output from a coder is fed to a code reviewer (with context, specific goals) -*** Each reviewer proposes changes, which result in a new prompt for the original coder -*** Changes are accepted by the coder -*** Each module fed to a builder -*** If it doesn’t build sent back to review -*** (etc) +* User begins with specifying a repository and then statement of what they want to accomplish, natural language, as simple or as detailed as needed. + * SK DevTeam skill will use dialog to refine the intent as needed, returns a plan, proposes necessary steps + * User approves the plan or gives feedback, requests iteration + * Plan is parceled out to the appropriate further skills + * Eg, for a new app: + * Architecture is passed to DevLead skill gives plan/task breakdown. + * DevLead breaks down tasks into smaller tasks, each of these is fed to a skill to decide if it is a single code module or multiple + * Each module is further fed to a dev lead to break down again or specify a prompt for a coder + * Each code module prompt is fed to a coder + * Each module output from a coder is fed to a code reviewer (with context, specific goals) + * Each reviewer proposes changes, which result in a new prompt for the original coder + * Changes are accepted by the coder + * Each module fed to a builder + * If it doesn’t build sent back to review + * (etc) + ## Proposed Architecture + * SK Kernel Service – ASP.NET Core Service with REST API * SK Skills: -** PM Skill – generates pot, word docs, describing app, -** Designer Skill – mockups? -** Architect Skill – proposes overall arch -** DevLead Skill – proposes task breakdown -** CoderSkill – builds code modules for each task -** ReviewerSkill – improves code modules -** TestSkill – writes tests -** Etc -* Web app: prompt front end and wizard style editor of app + * PM Skill – generates pot, word docs, describing app, + * Designer Skill – mockups? + * Architect Skill – proposes overall arch + * DevLead Skill – proposes task breakdown + * CoderSkill – builds code modules for each task + * ReviewerSkill – improves code modules + * TestSkill – writes tests + * Etc +* Web app: prompt front end and wizard style editor of app * Build service sandboxes – using branches and actions/pipelines 1st draft; Alternate – ephemeral build containers * Logging service streaming back to azure logs analytics, app insights, and teams channel * Deployment service – actions/pipelines driven -* Azure Dev Skill – lean into azure integrations – crawl the azure estate to inventory a tenant’s existing resources to memory and help inform new code. Eg: you have a large azure sql estate? Ok, most likely you want to wire your new app to one of those dbs, etc…. +* Azure Dev Skill – lean into azure integrations – crawl the azure estate to inventory a tenant’s existing resources to memory and help inform new code. Eg: you have a large azure sql estate? Ok, most likely you want to wire your new app to one of those dbs, etc…. # Contributing This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us -the rights to use your contribution. For details, visit https://cla.opensource.microsoft.com. +the rights to use your contribution. For details, visit . When you submit a pull request, a CLA bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., status check, comment). Simply follow the instructions @@ -98,9 +114,9 @@ see the [LICENSE](LICENSE) file, and grant you a license to any code in the repo Microsoft, Windows, Microsoft Azure and/or other Microsoft products and services referenced in the documentation may be either trademarks or registered trademarks of Microsoft in the United States and/or other countries. The licenses for this project do not grant you rights to use any Microsoft names, logos, or trademarks. -Microsoft's general trademark guidelines can be found at http://go.microsoft.com/fwlink/?LinkID=254653. +Microsoft's general trademark guidelines can be found at . -Privacy information can be found at https://privacy.microsoft.com/en-us/ +Privacy information can be found at Microsoft and any contributors reserve all other rights, whether under their respective copyrights, patents, or trademarks, whether by implication, estoppel or otherwise.