You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

Developer.cs 1.9 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. // Copyright (c) Microsoft Corporation. All rights reserved.
  2. // Developer.cs
  3. using DevTeam.Shared;
  4. using Microsoft.AutoGen.Agents;
  5. using Microsoft.AutoGen.Contracts;
  6. using Microsoft.AutoGen.Core;
  7. using Microsoft.SemanticKernel;
  8. using Microsoft.SemanticKernel.Memory;
  9. namespace DevTeam.Agents;
  10. [TopicSubscription("devteam")]
  11. public class Dev(IAgentWorker worker, Kernel kernel, ISemanticTextMemory memory, [FromKeyedServices("EventTypes")] EventTypes typeRegistry, ILogger<Dev> logger)
  12. : SKAiAgent<DeveloperState>(worker, memory, kernel, typeRegistry), IDevelopApps,
  13. IHandle<CodeGenerationRequested>,
  14. IHandle<CodeChainClosed>
  15. {
  16. public async Task Handle(CodeGenerationRequested item)
  17. {
  18. var code = await GenerateCode(item.Ask);
  19. var evt = new CodeGenerated
  20. {
  21. Org = item.Org,
  22. Repo = item.Repo,
  23. IssueNumber = item.IssueNumber,
  24. Code = code
  25. };
  26. await PublishMessageAsync(evt);
  27. }
  28. public async Task Handle(CodeChainClosed item)
  29. {
  30. //TODO: Get code from state
  31. var lastCode = ""; // _state.State.History.Last().Message
  32. var evt = new CodeCreated
  33. {
  34. Code = lastCode
  35. };
  36. await PublishMessageAsync(evt);
  37. }
  38. public async Task<string> GenerateCode(string ask)
  39. {
  40. try
  41. {
  42. var context = new KernelArguments { ["input"] = AppendChatHistory(ask) };
  43. var instruction = "Consider the following architectural guidelines:!waf!";
  44. var enhancedContext = await AddKnowledge(instruction, "waf", context);
  45. return await CallFunction(DeveloperSkills.Implement, enhancedContext);
  46. }
  47. catch (Exception ex)
  48. {
  49. logger.LogError(ex, "Error generating code");
  50. return "";
  51. }
  52. }
  53. }
  54. public interface IDevelopApps
  55. {
  56. public Task<string> GenerateCode(string ask);
  57. }