Skip to content

A programming framework for agentic AI

[wip] [dotnet] adding IOAgents (#598)

Ryan Sweetd60536c9feaa
diff --git a/dotnet/samples/HelloAgents/HelloAgents.Agents/Agents/HelloAgent/HelloAgent.cs b/dotnet/samples/HelloAgents/HelloAgents.Agents/Agents/HelloAgent/HelloAgent.cs
index b2caff040..534bfe07e 100644
--- a/dotnet/samples/HelloAgents/HelloAgents.Agents/Agents/HelloAgent/HelloAgent.cs
+++ b/dotnet/samples/HelloAgents/HelloAgents.Agents/Agents/HelloAgent/HelloAgent.cs
@@ -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)
{
diff --git a/dotnet/src/Microsoft.AutoGen.Agents.Worker.Client/AgentBase.cs b/dotnet/src/Microsoft.AutoGen.Agents.Worker.Client/AgentBase.cs
index 661c10b87..35c1c229a 100644
--- a/dotnet/src/Microsoft.AutoGen.Agents.Worker.Client/AgentBase.cs
+++ b/dotnet/src/Microsoft.AutoGen.Agents.Worker.Client/AgentBase.cs
@@ -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 = [];
diff --git a/dotnet/src/Microsoft.AutoGen.Agents.Worker.Client/AgentWorkerRuntime.cs b/dotnet/src/Microsoft.AutoGen.Agents.Worker.Client/AgentWorkerRuntime.cs
index 2e2f243b3..19b6ed550 100644
--- a/dotnet/src/Microsoft.AutoGen.Agents.Worker.Client/AgentWorkerRuntime.cs
+++ b/dotnet/src/Microsoft.AutoGen.Agents.Worker.Client/AgentWorkerRuntime.cs
@@ -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 },
diff --git a/dotnet/src/Microsoft.AutoGen.Agents.Worker.Client/AiAgent.cs b/dotnet/src/Microsoft.AutoGen.Agents.Worker.Client/Agents/AIAgent/AiAgent.cs
similarity index 100%
rename from dotnet/src/Microsoft.AutoGen.Agents.Worker.Client/AiAgent.cs
rename to dotnet/src/Microsoft.AutoGen.Agents.Worker.Client/Agents/AIAgent/AiAgent.cs
diff --git a/dotnet/src/Microsoft.AutoGen.Agents.Worker.Client/Agents/IOAgent/IOAgent.cs b/dotnet/src/Microsoft.AutoGen.Agents.Worker.Client/Agents/IOAgent/IOAgent.cs
new file mode 100644
index 000000000..710c495ed
--- /dev/null
+++ b/dotnet/src/Microsoft.AutoGen.Agents.Worker.Client/Agents/IOAgent/IOAgent.cs
@@ -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);
+
+}
\ No newline at end of file
diff --git a/dotnet/src/Microsoft.AutoGen.Agents.Worker.Server/WorkerGateway.cs b/dotnet/src/Microsoft.AutoGen.Agents.Worker.Server/WorkerGateway.cs
index bfdbf46c0..fc4cf1a75 100644
--- a/dotnet/src/Microsoft.AutoGen.Agents.Worker.Server/WorkerGateway.cs
+++ b/dotnet/src/Microsoft.AutoGen.Agents.Worker.Server/WorkerGateway.cs
@@ -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);
diff --git a/dotnet/src/Microsoft.AutoGen.Agents/Microsoft.AutoGen.Agents.csproj b/dotnet/src/Microsoft.AutoGen.Agents/Microsoft.AutoGen.Agents.csproj
index 231d501bf..35bfcbf9f 100644
--- a/dotnet/src/Microsoft.AutoGen.Agents/Microsoft.AutoGen.Agents.csproj
+++ b/dotnet/src/Microsoft.AutoGen.Agents/Microsoft.AutoGen.Agents.csproj
@@ -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>
diff --git a/protos/agent_events.proto b/protos/agent_events.proto
new file mode 100644
index 000000000..c0984f4dd
--- /dev/null
+++ b/protos/agent_events.proto
@@ -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;
+}