mirror of
https://github.com/microsoft/autogen.git
synced 2025-07-09 10:01:37 +00:00

* dotnet rework * add dotnet workload update to startup * fix build * interim fixup * this is the stuff that was missing * renaming the .net classes * more build fixup * port dev-team sample WIP * add proto messages and IHandle to agents * add github variables * remove OAgents gh-flow * remove OAgents library * add .vs to gitignore --------- Co-authored-by: Kosta Petan <kostapetan@gmail.com> Co-authored-by: Ryan Sweet <rysweet@microsoft.com>
57 lines
1.7 KiB
C#
57 lines
1.7 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 Dev(IAgentContext context, Kernel kernel, ISemanticTextMemory memory, [FromKeyedServices("EventTypes")] EventTypes typeRegistry, ILogger<Dev> logger)
|
|
: AiAgent<DeveloperState>(context, memory, kernel, typeRegistry), IDevelopApps,
|
|
IHandle<CodeGenerationRequested>,
|
|
IHandle<CodeChainClosed>
|
|
{
|
|
public async Task Handle(CodeGenerationRequested item)
|
|
{
|
|
var code = await GenerateCode(item.Ask);
|
|
var evt = new CodeGenerated
|
|
{
|
|
Code = code
|
|
}.ToCloudEvent(this.AgentId.Key);
|
|
await PublishEvent(evt);
|
|
}
|
|
|
|
public async Task Handle(CodeChainClosed item)
|
|
{
|
|
//TODO: Get code from state
|
|
var lastCode = ""; // _state.State.History.Last().Message
|
|
var evt = new CodeCreated
|
|
{
|
|
Code = lastCode
|
|
}.ToCloudEvent(this.AgentId.Key);
|
|
await PublishEvent(evt);
|
|
}
|
|
|
|
public async Task<string> GenerateCode(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(DeveloperSkills.Implement, enhancedContext);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
logger.LogError(ex, "Error generating code");
|
|
return "";
|
|
}
|
|
}
|
|
}
|
|
|
|
public interface IDevelopApps
|
|
{
|
|
public Task<string> GenerateCode(string ask);
|
|
}
|