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.

DeveloperLead.cs 2.2 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. using DevTeam.Shared;
  2. using Microsoft.AutoGen.Agents.Abstractions;
  3. using Microsoft.AutoGen.Agents.Client;
  4. using Microsoft.SemanticKernel;
  5. using Microsoft.SemanticKernel.Connectors.OpenAI;
  6. using Microsoft.SemanticKernel.Memory;
  7. namespace DevTeam.Agents;
  8. [TopicSubscription("devteam")]
  9. public class DeveloperLead(IAgentContext context, Kernel kernel, ISemanticTextMemory memory, [FromKeyedServices("EventTypes")] EventTypes typeRegistry, ILogger<DeveloperLead> logger)
  10. : AiAgent<DeveloperLeadState>(context, memory, kernel, typeRegistry), ILeadDevelopers,
  11. IHandle<DevPlanRequested>,
  12. IHandle<DevPlanChainClosed>
  13. {
  14. public async Task Handle(DevPlanRequested item)
  15. {
  16. var plan = await CreatePlan(item.Ask);
  17. var evt = new DevPlanGenerated
  18. {
  19. Org = item.Org,
  20. Repo = item.Repo,
  21. IssueNumber = item.IssueNumber,
  22. Plan = plan
  23. }.ToCloudEvent(this.AgentId.Key);
  24. await PublishEvent(evt);
  25. }
  26. public async Task Handle(DevPlanChainClosed item)
  27. {
  28. // TODO: Get plan from state
  29. var lastPlan = ""; // _state.State.History.Last().Message
  30. var evt = new DevPlanCreated
  31. {
  32. Plan = lastPlan
  33. }.ToCloudEvent(this.AgentId.Key);
  34. await PublishEvent(evt);
  35. }
  36. public async Task<string> CreatePlan(string ask)
  37. {
  38. try
  39. {
  40. var context = new KernelArguments { ["input"] = AppendChatHistory(ask) };
  41. var instruction = "Consider the following architectural guidelines:!waf!";
  42. var enhancedContext = await AddKnowledge(instruction, "waf", context);
  43. var settings = new OpenAIPromptExecutionSettings
  44. {
  45. ResponseFormat = "json_object",
  46. MaxTokens = 4096,
  47. Temperature = 0.8,
  48. TopP = 1
  49. };
  50. return await CallFunction(DevLeadSkills.Plan, enhancedContext, settings);
  51. }
  52. catch (Exception ex)
  53. {
  54. logger.LogError(ex, "Error creating development plan");
  55. return "";
  56. }
  57. }
  58. }
  59. public interface ILeadDevelopers
  60. {
  61. public Task<string> CreatePlan(string ask);
  62. }