mirror of
https://github.com/microsoft/autogen.git
synced 2025-07-19 06:53:17 +00:00
55 lines
1.8 KiB
C#
55 lines
1.8 KiB
C#
![]() |
using DevTeam.Shared;
|
||
|
using Microsoft.AI.Agents.Abstractions;
|
||
|
using Microsoft.AI.Agents.Worker.Client;
|
||
|
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
|
||
|
var evt= new ReadmeCreated {
|
||
|
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
|
||
|
{
|
||
|
Readme = readme
|
||
|
}.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 "";
|
||
|
}
|
||
|
}}
|
||
|
|
||
|
public interface IManageProducts
|
||
|
{
|
||
|
public Task<string> CreateReadme(string ask);
|
||
|
}
|