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

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