2024-09-17 09:01:49 -04:00
|
|
|
using DevTeam.Shared;
|
2024-09-18 11:57:51 -07:00
|
|
|
using Microsoft.AutoGen.Agents.Abstractions;
|
2024-09-24 09:26:30 -07:00
|
|
|
using Microsoft.AutoGen.Agents.Client;
|
2024-09-17 09:01:49 -04:00
|
|
|
using Microsoft.SemanticKernel;
|
|
|
|
using Microsoft.SemanticKernel.Memory;
|
|
|
|
|
|
|
|
namespace DevTeam.Agents;
|
|
|
|
|
|
|
|
[TopicSubscription("devteam")]
|
|
|
|
public class ProductManager(IAgentContext context, Kernel kernel, ISemanticTextMemory memory, [FromKeyedServices("EventTypes")] EventTypes typeRegistry, ILogger<ProductManager> logger)
|
|
|
|
: AiAgent<ProductManagerState>(context, memory, kernel, typeRegistry), IManageProducts,
|
|
|
|
IHandle<ReadmeChainClosed>,
|
|
|
|
IHandle<ReadmeRequested>
|
|
|
|
{
|
|
|
|
public async Task Handle(ReadmeChainClosed item)
|
|
|
|
{
|
|
|
|
// TODO: Get readme from state
|
|
|
|
var lastReadme = ""; // _state.State.History.Last().Message
|
2024-10-02 11:42:27 -07:00
|
|
|
var evt = new ReadmeCreated
|
|
|
|
{
|
2024-09-17 09:01:49 -04:00
|
|
|
Readme = lastReadme
|
|
|
|
}.ToCloudEvent(this.AgentId.Key);
|
|
|
|
await PublishEvent(evt);
|
|
|
|
}
|
|
|
|
|
|
|
|
public async Task Handle(ReadmeRequested item)
|
|
|
|
{
|
|
|
|
var readme = await CreateReadme(item.Ask);
|
|
|
|
var evt = new ReadmeGenerated
|
|
|
|
{
|
2024-09-18 11:57:51 -07:00
|
|
|
Readme = readme,
|
|
|
|
Org = item.Org,
|
|
|
|
Repo = item.Repo,
|
|
|
|
IssueNumber = item.IssueNumber
|
2024-09-17 09:01:49 -04:00
|
|
|
}.ToCloudEvent(this.AgentId.Key);
|
|
|
|
await PublishEvent(evt);
|
|
|
|
}
|
|
|
|
|
|
|
|
public async Task<string> CreateReadme(string ask)
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
var context = new KernelArguments { ["input"] = AppendChatHistory(ask) };
|
|
|
|
var instruction = "Consider the following architectural guidelines:!waf!";
|
|
|
|
var enhancedContext = await AddKnowledge(instruction, "waf", context);
|
|
|
|
return await CallFunction(PMSkills.Readme, enhancedContext);
|
|
|
|
}
|
|
|
|
catch (Exception ex)
|
|
|
|
{
|
|
|
|
logger.LogError(ex, "Error creating readme");
|
|
|
|
return "";
|
|
|
|
}
|
2024-10-02 11:42:27 -07:00
|
|
|
}
|
|
|
|
}
|
2024-09-17 09:01:49 -04:00
|
|
|
|
|
|
|
public interface IManageProducts
|
|
|
|
{
|
|
|
|
public Task<string> CreateReadme(string ask);
|
|
|
|
}
|