Skip to content

Commit

Permalink
feat: Restore Runtime.Grpc project and get it building
Browse files Browse the repository at this point in the history
  • Loading branch information
lokitoth committed Jan 30, 2025
1 parent 6f1f04f commit 07bdb55
Show file tree
Hide file tree
Showing 27 changed files with 393 additions and 197 deletions.
19 changes: 12 additions & 7 deletions dotnet/AutoGen.sln
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Hello", "Hello", "{F42F9C8E
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.AutoGen.Core.Grpc", "src\Microsoft.AutoGen\Core.Grpc\Microsoft.AutoGen.Core.Grpc.csproj", "{3D83C6DB-ACEA-48F3-959F-145CCD2EE135}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.AutoGen.Runtime.Grpc", "src\Microsoft.AutoGen\Runtime.Grpc\Microsoft.AutoGen.Runtime.Grpc.csproj", "{BEC2FDB8-5FC4-4B88-9D69-69759F63F4DC}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -296,16 +298,18 @@ Global
{70A8D4B5-D0A6-4098-A6F3-6ED274B65E7D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{70A8D4B5-D0A6-4098-A6F3-6ED274B65E7D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{70A8D4B5-D0A6-4098-A6F3-6ED274B65E7D}.Release|Any CPU.Build.0 = Release|Any CPU
{3D83C6DB-ACEA-48F3-959F-145CCD2EE135}.CoreOnly|Any CPU.ActiveCfg = Debug|Any CPU
{3D83C6DB-ACEA-48F3-959F-145CCD2EE135}.CoreOnly|Any CPU.Build.0 = Debug|Any CPU
{3D83C6DB-ACEA-48F3-959F-145CCD2EE135}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{3D83C6DB-ACEA-48F3-959F-145CCD2EE135}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3D83C6DB-ACEA-48F3-959F-145CCD2EE135}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3D83C6DB-ACEA-48F3-959F-145CCD2EE135}.Release|Any CPU.Build.0 = Release|Any CPU
{AAD593FE-A49B-425E-A9FE-A0022CD25E3D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{AAD593FE-A49B-425E-A9FE-A0022CD25E3D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{AAD593FE-A49B-425E-A9FE-A0022CD25E3D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{AAD593FE-A49B-425E-A9FE-A0022CD25E3D}.Release|Any CPU.Build.0 = Release|Any CPU
{3D83C6DB-ACEA-48F3-959F-145CCD2EE135}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{3D83C6DB-ACEA-48F3-959F-145CCD2EE135}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3D83C6DB-ACEA-48F3-959F-145CCD2EE135}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3D83C6DB-ACEA-48F3-959F-145CCD2EE135}.Release|Any CPU.Build.0 = Release|Any CPU
{BEC2FDB8-5FC4-4B88-9D69-69759F63F4DC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{BEC2FDB8-5FC4-4B88-9D69-69759F63F4DC}.Debug|Any CPU.Build.0 = Debug|Any CPU
{BEC2FDB8-5FC4-4B88-9D69-69759F63F4DC}.Release|Any CPU.ActiveCfg = Release|Any CPU
{BEC2FDB8-5FC4-4B88-9D69-69759F63F4DC}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -356,9 +360,10 @@ Global
{EAFFE339-26CB-4019-991D-BCCE8E7D33A1} = {F823671B-3ECA-4AE6-86DA-25E920D3FE64}
{58AD8E1D-83BD-4950-A324-1A20677D78D9} = {F823671B-3ECA-4AE6-86DA-25E920D3FE64}
{70A8D4B5-D0A6-4098-A6F3-6ED274B65E7D} = {CE0AA8D5-12B8-4628-9589-DAD8CB0DDCF6}
{3D83C6DB-ACEA-48F3-959F-145CCD2EE135} = {18BF8DD7-0585-48BF-8F97-AD333080CE06}
{AAD593FE-A49B-425E-A9FE-A0022CD25E3D} = {F42F9C8E-7BD9-4687-9B63-AFFA461AF5C1}
{F42F9C8E-7BD9-4687-9B63-AFFA461AF5C1} = {CE0AA8D5-12B8-4628-9589-DAD8CB0DDCF6}
{3D83C6DB-ACEA-48F3-959F-145CCD2EE135} = {18BF8DD7-0585-48BF-8F97-AD333080CE06}
{BEC2FDB8-5FC4-4B88-9D69-69759F63F4DC} = {18BF8DD7-0585-48BF-8F97-AD333080CE06}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {93384647-528D-46C8-922C-8DB36A382F0B}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// IAgentGrain.cs

using Microsoft.AutoGen.Protobuf;

namespace Microsoft.AutoGen.Runtime.Grpc.Abstractions;

internal interface IAgentGrain : IGrainWithStringKey
{
ValueTask<Contracts.AgentState> ReadStateAsync();
ValueTask<string> WriteStateAsync(Contracts.AgentState state, string eTag);
ValueTask<AgentState> ReadStateAsync();
ValueTask<string> WriteStateAsync(AgentState state, string eTag);
}
18 changes: 14 additions & 4 deletions dotnet/src/Microsoft.AutoGen/Runtime.Grpc/Abstractions/IGateway.cs
Original file line number Diff line number Diff line change
@@ -1,18 +1,28 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// IGateway.cs
using Microsoft.AutoGen.Contracts;
using Microsoft.AutoGen.Protobuf;

namespace Microsoft.AutoGen.Runtime.Grpc.Abstractions;

public interface IConnection
{
}

public interface IGateway : IGrainObserver
{
ValueTask<RpcResponse> InvokeRequestAsync(RpcRequest request);
ValueTask BroadcastEventAsync(CloudEvent evt);
ValueTask StoreAsync(Contracts.AgentState value);
ValueTask<Contracts.AgentState> ReadAsync(AgentId agentId);
ValueTask<RegisterAgentTypeResponse> RegisterAgentTypeAsync(RegisterAgentTypeRequest request);

ValueTask<RpcResponse> InvokeRequestAsync(RpcRequest request);

ValueTask StoreAsync(Protobuf.AgentState value);
ValueTask<Protobuf.AgentState> ReadAsync(Protobuf.AgentId agentId);

ValueTask<RegisterAgentTypeResponse> RegisterAgentTypeAsync(string requestId, RegisterAgentTypeRequest request);

ValueTask<AddSubscriptionResponse> SubscribeAsync(AddSubscriptionRequest request);
ValueTask<RemoveSubscriptionResponse> UnsubscribeAsync(RemoveSubscriptionRequest request);
ValueTask<List<Subscription>> GetSubscriptionsAsync(GetSubscriptionsRequest request);

Task SendMessageAsync(IConnection connection, CloudEvent cloudEvent);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,62 @@
// IGatewayRegistry.cs

using Microsoft.AutoGen.Contracts;
using Microsoft.AutoGen.Protobuf;

namespace Microsoft.AutoGen.Runtime.Grpc.Abstractions;

public interface IRegistry
{
//AgentsRegistryState State { get; set; }
/// <summary>
/// Registers a new agent type with the specified worker.
/// </summary>
/// <param name="request">The request containing agent type details.</param>
/// <param name="worker">The worker to register the agent type with.</param>
/// <returns>A task representing the asynchronous operation.</returns>
/// <remarks>removing CancellationToken from here as it is not compatible with Orleans Serialization</remarks>
ValueTask RegisterAgentTypeAsync(RegisterAgentTypeRequest request, IAgentRuntime worker);

/// <summary>
/// Unregisters an agent type from the specified worker.
/// </summary>
/// <param name="type">The type of the agent to unregister.</param>
/// <param name="worker">The worker to unregister the agent type from.</param>
/// <returns>A task representing the asynchronous operation.</returns>
/// <remarks>removing CancellationToken from here as it is not compatible with Orleans Serialization</remarks>
ValueTask UnregisterAgentTypeAsync(string type, IAgentRuntime worker);

/// <summary>
/// Gets a list of agents subscribed to and handling the specified topic and event type.
/// </summary>
/// <param name="topic">The topic to check subscriptions for.</param>
/// <param name="eventType">The event type to check subscriptions for.</param>
/// <returns>A task representing the asynchronous operation, with the list of agent IDs as the result.</returns>
ValueTask<List<string>> GetSubscribedAndHandlingAgentsAsync(string topic, string eventType);

/// <summary>
/// Subscribes an agent to a topic.
/// </summary>
/// <param name="request">The subscription request.</param>
/// <returns>A task representing the asynchronous operation.</returns>
/// <remarks>removing CancellationToken from here as it is not compatible with Orleans Serialization</remarks>
ValueTask SubscribeAsync(AddSubscriptionRequest request);

/// <summary>
/// Unsubscribes an agent from a topic.
/// </summary>
/// <param name="request">The unsubscription request.</param>
/// <returns>A task representing the asynchronous operation.</returns>
/// <remarks>removing CancellationToken from here as it is not compatible with Orleans Serialization</remarks>
ValueTask UnsubscribeAsync(RemoveSubscriptionRequest request); // TODO: This should have its own request type.

/// <summary>
/// Gets the subscriptions for a specified agent type.
/// </summary>
/// <returns>A task representing the asynchronous operation, with the subscriptions as the result.</returns>
ValueTask<List<Subscription>> GetSubscriptionsAsync(GetSubscriptionsRequest request);
}

/// <summary>
/// Interface for managing agent registration, placement, and subscriptions.
/// </summary>
Expand All @@ -15,7 +68,7 @@ public interface IGatewayRegistry : IRegistry
/// </summary>
/// <param name="agentId">The ID of the agent.</param>
/// <returns>A tuple containing the worker and a boolean indicating if it's a new placement.</returns>
ValueTask<(IGateway? Worker, bool NewPlacement)> GetOrPlaceAgent(AgentId agentId);
ValueTask<(IGateway? Worker, bool NewPlacement)> GetOrPlaceAgent(Protobuf.AgentId agentId);

/// <summary>
/// Removes a worker from the registry.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// IRegistryGrain.cs

using Microsoft.AutoGen.Protobuf;
using System.Collections.Concurrent;

namespace Microsoft.AutoGen.Runtime.Grpc.Abstractions;

/// <summary>
Expand All @@ -9,3 +12,15 @@ namespace Microsoft.AutoGen.Runtime.Grpc.Abstractions;
[Alias("Microsoft.AutoGen.Runtime.Grpc.Abstractions.IRegistryGrain")]
public interface IRegistryGrain : IGatewayRegistry, IGrainWithIntegerKey
{ }

public class AgentsRegistryState
{
public ConcurrentDictionary<string, HashSet<string>> AgentsToEventsMap { get; set; } = new ConcurrentDictionary<string, HashSet<string>>();
public ConcurrentDictionary<string, HashSet<string>> AgentsToTopicsMap { get; set; } = [];
public ConcurrentDictionary<string, HashSet<string>> TopicToAgentTypesMap { get; set; } = [];
public ConcurrentDictionary<string, HashSet<string>> EventsToAgentTypesMap { get; set; } = [];
public ConcurrentDictionary<string, HashSet<Subscription>> GuidSubscriptionsMap { get; set; } = [];
public ConcurrentDictionary<string, AgentId> AgentTypes { get; set; } = [];
public string Etag { get; set; } = Guid.NewGuid().ToString();
}

Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\Contracts\Microsoft.AutoGen.Contracts.csproj" />
<ProjectReference Include="..\Core.Grpc\Microsoft.AutoGen.Core.Grpc.csproj" />
<ProjectReference Include="..\Core\Microsoft.AutoGen.Core.csproj" />
</ItemGroup>
<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

using System.Diagnostics;
using Microsoft.AspNetCore.Builder;
using Microsoft.AutoGen.Core;
//using Microsoft.AutoGen.Core;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
using Microsoft.Extensions.Hosting;
Expand All @@ -18,10 +18,10 @@ public static WebApplicationBuilder AddAgentService(this WebApplicationBuilder b
builder.Services.TryAddSingleton(DistributedContextPropagator.Current);

builder.Services.AddGrpc();
builder.Services.AddKeyedSingleton("AgentsMetadata", (sp, key) =>
{
return ReflectionHelper.GetAgentsMetadata(AppDomain.CurrentDomain.GetAssemblies());
});
//builder.Services.AddKeyedSingleton("AgentsMetadata", (sp, key) =>
//{
// return ReflectionHelper.GetAgentsMetadata(AppDomain.CurrentDomain.GetAssemblies());
//});
builder.Services.AddSingleton<GrpcGateway>();
builder.Services.AddSingleton<IHostedService>(sp => (IHostedService)sp.GetRequiredService<GrpcGateway>());

Expand Down
Loading

0 comments on commit 07bdb55

Please sign in to comment.