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

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