mirror of https://github.com/microsoft/autogen.git
[wip] [dotnet] adding IOAgents (#598)
* new agent events top level photo for base agents * new tip IOAgent * fix .net build break from proto
This commit is contained in:
parent
9009c2aa96
commit
d60536c9fe
|
@ -6,10 +6,19 @@ 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 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)
|
||||
{
|
||||
|
|
|
@ -11,7 +11,7 @@ namespace Microsoft.AutoGen.Agents.Worker.Client;
|
|||
|
||||
public abstract class AgentBase
|
||||
{
|
||||
public static readonly ActivitySource s_source = new("Starfleet.Agent");
|
||||
public static readonly ActivitySource s_source = new("AutoGen.Agent");
|
||||
private readonly object _lock = new();
|
||||
private readonly Dictionary<string, TaskCompletionSource<RpcResponse>> _pendingRequests = [];
|
||||
|
||||
|
|
|
@ -176,7 +176,7 @@ public sealed class AgentWorkerRuntime : IHostedService, IDisposable, IAgentWork
|
|||
|
||||
await WriteChannelAsync(new Message
|
||||
{
|
||||
RegisterAgentType = new RegisterAgentType
|
||||
RegisterAgentTypeRequest = new RegisterAgentTypeRequest
|
||||
{
|
||||
Type = type,
|
||||
//TopicTypes = { topicTypes },
|
||||
|
|
|
@ -0,0 +1,27 @@
|
|||
using Microsoft.AutoGen.Agents.Abstractions;
|
||||
|
||||
namespace Microsoft.AutoGen.Agents.Worker.Client;
|
||||
|
||||
public abstract class IOAgent<T> : AgentBase where T : class, new()
|
||||
{
|
||||
protected AgentState<T> _state;
|
||||
private readonly string _route = "console";
|
||||
|
||||
public IOAgent(IAgentContext context, EventTypes typeRegistry) : base(context, typeRegistry)
|
||||
{
|
||||
_state = new();
|
||||
}
|
||||
|
||||
public async Task Handle(Input item)
|
||||
{
|
||||
//var processed = await ProcessInput(item.Message);
|
||||
var evt = new InputProcessed
|
||||
{
|
||||
Route = _route
|
||||
}.ToCloudEvent(this.AgentId.Key);
|
||||
await PublishEvent(evt);
|
||||
}
|
||||
|
||||
public abstract Task<string> ProcessInput(string message);
|
||||
|
||||
}
|
|
@ -129,15 +129,15 @@ internal sealed class WorkerGateway : BackgroundService, IWorkerGateway
|
|||
case Message.MessageOneofCase.CloudEvent:
|
||||
await DispatchEventAsync(message.CloudEvent);
|
||||
break;
|
||||
case Message.MessageOneofCase.RegisterAgentType:
|
||||
await RegisterAgentTypeAsync(connection, message.RegisterAgentType);
|
||||
case Message.MessageOneofCase.RegisterAgentTypeRequest:
|
||||
await RegisterAgentTypeAsync(connection, message.RegisterAgentTypeRequest);
|
||||
break;
|
||||
default:
|
||||
throw new InvalidOperationException($"Unknown message type for message '{message}'.");
|
||||
};
|
||||
}
|
||||
|
||||
async ValueTask RegisterAgentTypeAsync(WorkerProcessConnection connection, RegisterAgentType msg)
|
||||
async ValueTask RegisterAgentTypeAsync(WorkerProcessConnection connection, RegisterAgentTypeRequest msg)
|
||||
{
|
||||
connection.AddSupportedType(msg.Type);
|
||||
_supportedAgentTypes.GetOrAdd(msg.Type, _ => []).Add(connection);
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
<ItemGroup>
|
||||
<Protobuf Include="..\..\..\protos\agent_worker.proto" GrpcServices="Client;Server" Link="Protos\agent_worker.proto" />
|
||||
<Protobuf Include="..\..\..\protos\cloudevent.proto" GrpcServices="Client;Server" Link="Protos\cloudevent.proto" />
|
||||
<Protobuf Include="..\..\..\protos\agent_events.proto" GrpcServices="Client;Server" Link="Protos\cloudevent.proto" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
|
|
@ -0,0 +1,20 @@
|
|||
syntax = "proto3";
|
||||
|
||||
package helloagents;
|
||||
|
||||
option csharp_namespace = "Microsoft.AutoGen.Agents.Worker.Client";
|
||||
|
||||
message Input {
|
||||
string message = 1;
|
||||
}
|
||||
|
||||
message InputProcessed {
|
||||
string route = 1;
|
||||
}
|
||||
message Output {
|
||||
string message = 1;
|
||||
}
|
||||
|
||||
message OutputProcessed {
|
||||
string route = 1;
|
||||
}
|
Loading…
Reference in New Issue