mirror of
https://github.com/microsoft/autogen.git
synced 2025-09-02 21:07:18 +00:00

* interim stash * interim stash * interim checkpoint * broken stash * whoops * merge sln files * fix a bunch of refactoring errors * moving more to core vs samples * interim * fixup the devteam sample * fix ci * fixup soln file * trying to fix ci * trying to fix ci * adding back * still trying * recreate * next step * adding it back * trying to fix * Rename Autogen -> AutoGen (#567) * Add transparency faqs (#566) * remove Autogen * add AutoGen back --------- Co-authored-by: Eric Zhu <ekzhu@users.noreply.github.com> --------- Co-authored-by: Xiaoyun Zhang <xiaoyuz@microsoft.com> Co-authored-by: Eric Zhu <ekzhu@users.noreply.github.com>
54 lines
1.6 KiB
C#
54 lines
1.6 KiB
C#
using Microsoft.AutoGen.Agents.Abstractions;
|
|
using Microsoft.AutoGen.Agents.Worker.Client;
|
|
using Microsoft.SemanticKernel;
|
|
using Microsoft.SemanticKernel.Memory;
|
|
|
|
namespace HelloAgents.Agents;
|
|
|
|
[TopicSubscription("HelloAgents")]
|
|
public class HelloAgent(IAgentContext context, Kernel kernel, ISemanticTextMemory memory, [FromKeyedServices("EventTypes")] EventTypes typeRegistry, ILogger<HelloAgent> logger)
|
|
: AiAgent<HelloAgentState>(context, memory, kernel, typeRegistry), ISayHello,
|
|
IHandle<NewMessageReceived>,
|
|
IHandle<ConversationClosed>
|
|
{
|
|
public async Task Handle(NewMessageReceived item)
|
|
{
|
|
var response = await SayHello(item.Message);
|
|
var evt = new ResponseGenerated
|
|
{
|
|
Response = response
|
|
}.ToCloudEvent(this.AgentId.Key);
|
|
await PublishEvent(evt);
|
|
}
|
|
|
|
public async Task Handle(ConversationClosed item)
|
|
{
|
|
//TODO: Get msg from state
|
|
var goodbye = ""; // _state.State.History.Last().Message
|
|
var evt = new GoodBye
|
|
{
|
|
Message = goodbye
|
|
}.ToCloudEvent(this.AgentId.Key);
|
|
await PublishEvent(evt);
|
|
}
|
|
|
|
public async Task<string> SayHello(string ask)
|
|
{
|
|
try
|
|
{
|
|
var context = new KernelArguments { ["input"] = AppendChatHistory(ask) };
|
|
return await CallFunction(HelloSkills.Greeting, context);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
logger.LogError(ex, "Error generating code");
|
|
return "";
|
|
}
|
|
}
|
|
}
|
|
|
|
public interface ISayHello
|
|
{
|
|
public Task<string> SayHello(string ask);
|
|
}
|