Skip to content

A programming framework for agentic AI

first tests

Jack Gerritsb19374e81df7
diff --git a/dotnet/src/Microsoft.AutoGen/Contracts/PythonEquiv/IAgentRuntime.cs b/dotnet/src/Microsoft.AutoGen/Contracts/PythonEquiv/IAgentRuntime.cs
index d39413d5f..09e3b83f5 100644
--- a/dotnet/src/Microsoft.AutoGen/Contracts/PythonEquiv/IAgentRuntime.cs
+++ b/dotnet/src/Microsoft.AutoGen/Contracts/PythonEquiv/IAgentRuntime.cs
@@ -23,7 +23,7 @@ public interface IAgentRuntime : ISaveState<IAgentRuntime>
/// <exception cref="CantHandleException">Thrown if the recipient cannot handle the message.</exception>
/// <exception cref="UndeliverableException">Thrown if the message cannot be delivered.</exception>
public ValueTask<object?> SendMessageAsync(object message, AgentId recepient, AgentId? sender = null, string? messageId = null, CancellationToken? cancellationToken = default);
-
+
/// <summary>
/// Publishes a message to all agents subscribed to the given topic.
/// No responses are expected from publishing.
@@ -45,7 +45,7 @@ public interface IAgentRuntime : ISaveState<IAgentRuntime>
/// <param name="lazy">If <c>true</c>, the agent is fetched lazily.</param>
/// <returns>A task representing the asynchronous operation, returning the agent's ID.</returns>
public ValueTask<AgentId> GetAgentAsync(AgentId agentId, bool lazy = true/*, CancellationToken? = default*/);
-
+
/// <summary>
/// Retrieves an agent by its type.
/// </summary>
@@ -54,7 +54,7 @@ public interface IAgentRuntime : ISaveState<IAgentRuntime>
/// <param name="lazy">If <c>true</c>, the agent is fetched lazily.</param>
/// <returns>A task representing the asynchronous operation, returning the agent's ID.</returns>
public ValueTask<AgentId> GetAgentAsync(AgentType agentType, string key = "default", bool lazy = true/*, CancellationToken? = default*/);
-
+
/// <summary>
/// Retrieves an agent by its string representation.
/// </summary>
@@ -64,7 +64,7 @@ public interface IAgentRuntime : ISaveState<IAgentRuntime>
/// <returns>A task representing the asynchronous operation, returning the agent's ID.</returns>
public ValueTask<AgentId> GetAgentAsync(string agent, string key = "default", bool lazy = true/*, CancellationToken? = default*/);
-
+
/// <summary>
/// Saves the state of an agent.
/// The result must be JSON serializable.
@@ -72,7 +72,7 @@ public interface IAgentRuntime : ISaveState<IAgentRuntime>
/// <param name="agentId">The ID of the agent whose state is being saved.</param>
/// <returns>A task representing the asynchronous operation, returning a dictionary of the saved state.</returns>
public ValueTask<StateDict> SaveAgentStateAsync(AgentId agentId/*, CancellationToken? cancellationToken = default*/);
-
+
/// <summary>
/// Loads the saved state into an agent.
/// </summary>
@@ -94,7 +94,7 @@ public interface IAgentRuntime : ISaveState<IAgentRuntime>
/// <param name="subscription">The subscription to add.</param>
/// <returns>A task representing the asynchronous operation.</returns>
public ValueTask AddSubscriptionAsync(ISubscriptionDefinition subscription/*, CancellationToken? cancellationToken = default*/);
-
+
/// <summary>
/// Removes a subscription from the runtime.
/// </summary>
@@ -111,7 +111,7 @@ public interface IAgentRuntime : ISaveState<IAgentRuntime>
/// <param name="type">The agent type to associate with the factory.</param>
/// <param name="factoryFunc">A function that asynchronously creates the agent instance.</param>
/// <returns>A task representing the asynchronous operation, returning the registered <see cref="AgentType"/>.</returns>
- public ValueTask<AgentType> RegisterAgentFactoryAsync<TAgent>(AgentType type, Func<ValueTask<TAgent>> factoryFunc) where TAgent : IHostableAgent;
+ public ValueTask<AgentType> RegisterAgentFactoryAsync<TAgent>(AgentType type, Func<AgentId, IAgentRuntime, ValueTask<TAgent>> factoryFunc) where TAgent : IHostableAgent;
// TODO:
//public ValueTask<TAgent> TryGetUnderlyingAgentInstanceAsync<TAgent>(AgentId agentId) where TAgent : IHostableAgent;
diff --git a/dotnet/src/Microsoft.AutoGen/Contracts/PythonEquiv/TopicId.cs b/dotnet/src/Microsoft.AutoGen/Contracts/PythonEquiv/TopicId.cs
index 13da25fb2..15c6e4f1d 100644
--- a/dotnet/src/Microsoft.AutoGen/Contracts/PythonEquiv/TopicId.cs
+++ b/dotnet/src/Microsoft.AutoGen/Contracts/PythonEquiv/TopicId.cs
@@ -10,7 +10,9 @@ public struct TopicId
public string Type { get; }
public string Source { get; }
- public TopicId(string type, string source)
+ public const string DefaultSource = "default";
+
+ public TopicId(string type, string source = DefaultSource)
{
Type = type;
Source = source;
diff --git a/dotnet/src/Microsoft.AutoGen/Contracts/PythonEquiv/AgentRuntimeExtensions.cs b/dotnet/src/Microsoft.AutoGen/Core/PythonEquiv/AgentRuntimeExtensions.cs
similarity index 58%
rename from dotnet/src/Microsoft.AutoGen/Contracts/PythonEquiv/AgentRuntimeExtensions.cs
rename to dotnet/src/Microsoft.AutoGen/Core/PythonEquiv/AgentRuntimeExtensions.cs
index 2fe9606b1..caee18a43 100644
--- a/dotnet/src/Microsoft.AutoGen/Contracts/PythonEquiv/AgentRuntimeExtensions.cs
+++ b/dotnet/src/Microsoft.AutoGen/Core/PythonEquiv/AgentRuntimeExtensions.cs
@@ -1,7 +1,9 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// AgentRuntimeExtensions.cs
+using Microsoft.AutoGen.Core.Python;
using Microsoft.Extensions.DependencyInjection;
+using System.Reflection;
namespace Microsoft.AutoGen.Contracts.Python;
@@ -39,9 +41,40 @@ public static class AgentRuntimeExtensions
/// <param name="serviceProvider">The service provider used for dependency injection.</param>
/// <param name="additionalArguments">Additional arguments to pass to the agent's constructor.</param>
/// <returns>A <see cref="ValueTask{AgentType}"/> representing the asynchronous operation of registering the agent.</returns>
- public static ValueTask<AgentType> RegisterAgentTypeAsync<TAgent>(this IAgentRuntime runtime, AgentType type, IServiceProvider serviceProvider, params object[] additionalArguments) where TAgent : IHostableAgent
+ public static ValueTask<AgentType> RegisterAgentTypeAsync<TAgent>(this IAgentRuntime runtime, AgentType type, IServiceProvider serviceProvider, params IEnumerable<object> additionalArguments) where TAgent : IHostableAgent
{
- Func<ValueTask<TAgent>> factory = () => ActivateAgentAsync<TAgent>(serviceProvider, additionalArguments);
+ Func<AgentId, IAgentRuntime, ValueTask<TAgent>> factory = (id, runtime) => ActivateAgentAsync<TAgent>(serviceProvider, [id, runtime, ..additionalArguments]);
return runtime.RegisterAgentFactoryAsync(type, factory);
}
+
+ private static ISubscriptionDefinition[] BindSubscriptionsForAgentType<T>(AgentType agentType, bool skipClassSubscriptions = false, bool skipDirectMessageSubscription = false)
+ {
+ // var topicAttributes = this.GetType().GetCustomAttributes<TopicSubscriptionAttribute>().Select(t => t.Topic);
+ var subscriptions = new List<ISubscriptionDefinition>();
+
+ if (!skipClassSubscriptions)
+ {
+ var classSubscriptions = typeof(T).GetCustomAttributes<TypeSubscriptionAttribute>().Select(t => t.Bind(agentType));
+ subscriptions.AddRange(classSubscriptions);
+
+ var prefixSubscriptions = typeof(T).GetCustomAttributes<TopicPrefixSubscriptionAttribute>().Select(t => t.Bind(agentType));
+ subscriptions.AddRange(prefixSubscriptions);
+ }
+
+ if (!skipDirectMessageSubscription)
+ {
+ subscriptions.Add(new TypePrefixSubscription(agentType.Name + ":", agentType));
+ }
+
+ return subscriptions.ToArray();
+ }
+
+ public static async ValueTask RegisterImplicitAgentSubscriptionsAsync<TAgent>(this IAgentRuntime runtime, AgentType type) where TAgent : IHostableAgent
+ {
+ var subscriptions = BindSubscriptionsForAgentType<TAgent>(type);
+ foreach (var subscription in subscriptions)
+ {
+ await runtime.AddSubscriptionAsync(subscription);
+ }
+ }
}
diff --git a/dotnet/src/Microsoft.AutoGen/Core/PythonEquiv/BaseAgent.cs b/dotnet/src/Microsoft.AutoGen/Core/PythonEquiv/BaseAgent.cs
index 4e66f9fe2..c3a3f8080 100644
--- a/dotnet/src/Microsoft.AutoGen/Core/PythonEquiv/BaseAgent.cs
+++ b/dotnet/src/Microsoft.AutoGen/Core/PythonEquiv/BaseAgent.cs
@@ -22,7 +22,7 @@ public abstract class BaseAgent : IAgent, IHostableAgent
/// Gets the unique identifier of the agent.
/// </summary>
public AgentId Id { get; private set; }
- protected internal ILogger<Agent> _logger;
+ protected internal ILogger<BaseAgent> _logger;
public Type[] HandledTypes {
get {
@@ -55,37 +55,15 @@ public abstract class BaseAgent : IAgent, IHostableAgent
AgentId id,
IAgentRuntime runtime,
string description,
- ILogger<Agent>? logger = null)
+ ILogger<BaseAgent>? logger = null)
{
Id = id;
- _logger = logger ?? LoggerFactory.Create(builder => { }).CreateLogger<Agent>();
+ _logger = logger ?? LoggerFactory.Create(builder => { }).CreateLogger<BaseAgent>();
Description = description;
Runtime = runtime;
_handlersByMessageType = new(GetType().GetHandlersLookupTable());
}
- public ISubscriptionDefinition[] BindSubscriptionsForAgentType(AgentType agentType, bool skipClassSubscriptions = false, bool skipDirectMessageSubscription = false)
- {
- // var topicAttributes = this.GetType().GetCustomAttributes<TopicSubscriptionAttribute>().Select(t => t.Topic);
- var subscriptions = new List<ISubscriptionDefinition>();
-
- if (!skipClassSubscriptions)
- {
- var classSubscriptions = this.GetType().GetCustomAttributes<TypeSubscriptionAttribute>().Select(t => t.Bind(agentType));
- subscriptions.AddRange(classSubscriptions);
-
- var prefixSubscriptions = this.GetType().GetCustomAttributes<TopicPrefixSubscriptionAttribute>().Select(t => t.Bind(agentType));
- subscriptions.AddRange(prefixSubscriptions);
- }
-
- if (!skipDirectMessageSubscription)
- {
- subscriptions.Add(new TypePrefixSubscription(agentType.Name + ":", agentType));
- }
-
- return subscriptions.ToArray();
- }
-
public ValueTask<object?> OnMessageAsync(object message, MessageContext messageContext)
{
// Determine type of message, then get handler method and invoke it
@@ -93,7 +71,7 @@ public abstract class BaseAgent : IAgent, IHostableAgent
if (_handlersByMessageType.TryGetValue(messageType, out var handlerMethod))
{
// Determine if this is a IHandle<T> or IHandle<T, U> method
- var genericArguments = handlerMethod.GetGenericArguments();
+ var genericArguments = handlerMethod.GetParameters();
if (genericArguments.Length == 1)
{
// This is a IHandle<T> method
@@ -121,15 +99,13 @@ public abstract class BaseAgent : IAgent, IHostableAgent
}
}
- public ValueTask<IDictionary<string, object>> SaveStateAsync()
+ public virtual ValueTask<IDictionary<string, object>> SaveStateAsync()
{
- // Raise not implemented exception
- throw new NotImplementedException();
+ return ValueTask.FromResult<IDictionary<string, object>>(new Dictionary<string, object>());
}
- public ValueTask LoadStateAsync(IDictionary<string, object> state)
+ public virtual ValueTask LoadStateAsync(IDictionary<string, object> state)
{
- // Raise not implemented exception
- throw new NotImplementedException();
+ return ValueTask.CompletedTask;
}
public ValueTask<object?> SendMessageAsync(object message, AgentId recepient, string? messageId = null, CancellationToken? cancellationToken = default)
diff --git a/dotnet/src/Microsoft.AutoGen/Core/PythonEquiv/IHandle.cs b/dotnet/src/Microsoft.AutoGen/Core/PythonEquiv/IHandle.cs
index c86e73dea..bd37618dd 100644
--- a/dotnet/src/Microsoft.AutoGen/Core/PythonEquiv/IHandle.cs
+++ b/dotnet/src/Microsoft.AutoGen/Core/PythonEquiv/IHandle.cs
@@ -2,6 +2,7 @@
// IHandle.cs
using Google.Protobuf;
+using Microsoft.AutoGen.Contracts.Python;
namespace Microsoft.AutoGen.Core.Python;
@@ -9,22 +10,22 @@ namespace Microsoft.AutoGen.Core.Python;
/// Defines a handler interface for processing items of type <typeparamref name="T"/>.
/// </summary>
/// <typeparam name="T">The type of item to be handled, which must implement <see cref="IMessage"/>.</typeparam>
-public interface IHandle<in T> where T : IMessage
+public interface IHandle<in T>
{
/// <summary>
/// Handles the specified item asynchronously.
/// </summary>
/// <param name="item">The item to be handled.</param>
/// <returns>A task that represents the asynchronous operation.</returns>
- Task Handle(T item, CancellationToken cancellationToken = default);
+ Task Handle(T item, MessageContext messageContext);
}
-public interface IHandle<in InT, OutT> where InT : IMessage where OutT : IMessage
+public interface IHandle<in InT, OutT>
{
/// <summary>
/// Handles the specified item asynchronously.
/// </summary>
/// <param name="item">The item to be handled.</param>
/// <returns>A task that represents the asynchronous operation.</returns>
- Task<OutT> Handle(InT item, CancellationToken cancellationToken = default);
+ Task<OutT> Handle(InT item, MessageContext messageContext);
}
diff --git a/dotnet/src/Microsoft.AutoGen/Core/PythonEquiv/InProcessRuntime.cs b/dotnet/src/Microsoft.AutoGen/Core/PythonEquiv/InProcessRuntime.cs
index 5d75f623f..cbc6187b4 100644
--- a/dotnet/src/Microsoft.AutoGen/Core/PythonEquiv/InProcessRuntime.cs
+++ b/dotnet/src/Microsoft.AutoGen/Core/PythonEquiv/InProcessRuntime.cs
@@ -3,15 +3,14 @@
using Microsoft.AutoGen.Contracts.Python;
-namespace Microsoft.AutoGen.Core;
+namespace Microsoft.AutoGen.Core.Python;
-internal sealed class InProcessRuntime : IAgentRuntime
+public sealed class InProcessRuntime : IAgentRuntime
{
Dictionary<AgentId, IHostableAgent> agentInstances = new();
Dictionary<string, ISubscriptionDefinition> subscriptions = new();
Dictionary<AgentType, Func<AgentId, IAgentRuntime, ValueTask<IHostableAgent>>> agentFactories = new();
-
private ValueTask<T> ExecuteTracedAsync<T>(Func<ValueTask<T>> func)
{
// TODO: Bind tracing
@@ -176,13 +175,15 @@ internal sealed class InProcessRuntime : IAgentRuntime
return state;
}
- public ValueTask<AgentType> RegisterAgentFactoryAsync<TAgent>(AgentType type, Func<ValueTask<TAgent>> factoryFunc) where TAgent : IHostableAgent
+ public ValueTask<AgentType> RegisterAgentFactoryAsync<TAgent>(AgentType type, Func<AgentId, IAgentRuntime, ValueTask<TAgent>> factoryFunc) where TAgent : IHostableAgent
{
if (this.agentFactories.ContainsKey(type))
{
throw new Exception($"Agent with type {type} already exists.");
}
+ this.agentFactories.Add(type, async (agentId, runtime) => await factoryFunc(agentId, runtime));
+
return ValueTask.FromResult(type);
}
diff --git a/dotnet/test/Microsoft.AutoGen.Core.Tests/PythonEquiv/AgentTests.cs b/dotnet/test/Microsoft.AutoGen.Core.Tests/PythonEquiv/AgentTests.cs
new file mode 100644
index 000000000..98cace67b
--- /dev/null
+++ b/dotnet/test/Microsoft.AutoGen.Core.Tests/PythonEquiv/AgentTests.cs
@@ -0,0 +1,212 @@
+// Copyright (c) Microsoft Corporation. All rights reserved.
+// AgentTests.cs
+using FluentAssertions;
+using Microsoft.AutoGen.Contracts.Python;
+using Microsoft.AutoGen.Core.Python;
+using Microsoft.Extensions.Logging;
+using Xunit;
+
+namespace Microsoft.AutoGen.Core.Tests.Python;
+
+//[Collection(ClusterFixtureCollection.Name)]
+public class AgentTests()
+{
+ [Fact]
+ public async Task Agent_ShouldNotReceiveMessages_WhenNotSubscribed()
+ {
+ var runtime = new Core.Python.InProcessRuntime();
+
+ Logger<BaseAgent> logger = new(new LoggerFactory());
+ await runtime.RegisterAgentFactoryAsync("MyAgent", (id, runtime) => ValueTask.FromResult(new TestAgent(id, runtime, logger)));
+ await runtime.RegisterImplicitAgentSubscriptionsAsync<TestAgent>("MyAgent");
+
+ var topicType = "TestTopic";
+
+ await runtime.PublishMessageAsync(new TextMessage { Source = topicType, Content = "test" }, new TopicId("TestTopic")).ConfigureAwait(true);
+
+ //await Task.Yield();
+ await Task.Delay(100);
+
+ TestAgent.ReceivedMessages.Any().Should().BeFalse("Agent should not receive messages when not subscribed.");
+ }
+
+ [Fact]
+ public async Task Agent_ShoulReceiveMessages_WhenSubscribed()
+ {
+ var runtime = new Core.Python.InProcessRuntime();
+
+ Logger<BaseAgent> logger = new(new LoggerFactory());
+ await runtime.RegisterAgentFactoryAsync("MyAgent", (id, runtime) => ValueTask.FromResult(new SubscribedAgent(id, runtime, logger)));
+ await runtime.RegisterImplicitAgentSubscriptionsAsync<SubscribedAgent>("MyAgent");
+
+ var topicType = "TestTopic";
+
+ await runtime.PublishMessageAsync(new TextMessage { Source = topicType, Content = "test" }, new TopicId("TestTopic")).ConfigureAwait(true);
+
+ //await Task.Yield();
+ await Task.Delay(100);
+
+ TestAgent.ReceivedMessages.Any().Should().BeTrue("Agent should receive messages when subscribed.");
+ }
+
+ // / <summary>
+ // / Verify that if the agent is not initialized via AgentWorker, it should throw the correct exception.
+ // / </summary>
+ // / <returns>void</returns>
+ // [Fact]
+ // public async Task Agent_ShouldThrowException_WhenNotInitialized()
+ // {
+ // using var fixture = new InMemoryAgentRuntimeFixture();
+ // var agent = ActivatorUtilities.CreateInstance<TestAgent>(fixture.AppHost.Services);
+ // await Assert.ThrowsAsync<UninitializedAgentWorker.AgentInitalizedIncorrectlyException>(
+ // async () =>
+ // {
+ // await agent.SubscribeAsync("TestEvent");
+ // }
+ // );
+ // }
+
+ // /// <summary>
+ // /// validate that the agent is initialized correctly with implicit subs
+ // /// </summary>
+ // /// <returns>void</returns>
+ // [Fact]
+ // public async Task Agent_ShouldInitializeCorrectly()
+ // {
+ // var fixture = new InMemoryAgentRuntimeFixture();
+ // var (runtime, agent) = fixture.Start();
+ // Assert.Equal(nameof(AgentRuntime), runtime.GetType().Name);
+ // var subscriptions = await agent.GetSubscriptionsAsync();
+ // Assert.Equal(2, subscriptions.Count);
+ // fixture.Stop();
+ // }
+ // /// <summary>
+ // /// Test SubscribeAsync method
+ // /// </summary>
+ // /// <returns>void</returns>
+ // [Fact]
+ // public async Task SubscribeAsync_UnsubscribeAsync_and_GetSubscriptionsTest()
+ // {
+ // var fixture = new InMemoryAgentRuntimeFixture();
+ // var (_, agent) = fixture.Start();
+ // await agent.SubscribeAsync("TestEvent");
+ // await Task.Delay(100);
+ // var subscriptions = await agent.GetSubscriptionsAsync().ConfigureAwait(true);
+ // var found = false;
+ // foreach (var subscription in subscriptions)
+ // {
+ // if (subscription.TypeSubscription.TopicType == "TestEvent")
+ // {
+ // found = true;
+ // }
+ // }
+ // Assert.True(found);
+ // await agent.UnsubscribeAsync("TestEvent").ConfigureAwait(true);
+ // await Task.Delay(500);
+ // subscriptions = await agent.GetSubscriptionsAsync().ConfigureAwait(true);
+ // found = false;
+ // foreach (var subscription in subscriptions)
+ // {
+ // if (subscription.TypeSubscription.TopicType == "TestEvent")
+ // {
+ // found = true;
+ // }
+ // }
+ // Assert.False(found);
+ // fixture.Stop();
+ // }
+
+ // /// <summary>
+ // /// Test StoreAsync and ReadAsync methods
+ // /// </summary>
+ // /// <returns>void</returns>
+ // [Fact]
+ // public async Task StoreAsync_and_ReadAsyncTest()
+ // {
+ // var fixture = new InMemoryAgentRuntimeFixture();
+ // var (_, agent) = fixture.Start();
+ // Dictionary<string, string> state = new()
+ // {
+ // { "testdata", "Active" }
+ // };
+ // await agent.StoreAsync(new AgentState
+ // {
+ // AgentId = agent.AgentId,
+ // TextData = JsonSerializer.Serialize(state)
+ // }).ConfigureAwait(true);
+ // var readState = await agent.ReadAsync<AgentState>(agent.AgentId).ConfigureAwait(true);
+ // var read = JsonSerializer.Deserialize<Dictionary<string, string>>(readState.TextData) ?? new Dictionary<string, string> { { "data", "No state data found" } };
+ // read.TryGetValue("testdata", out var value);
+ // Assert.Equal("Active", value);
+ // fixture.Stop();
+ // }
+
+ // /// <summary>
+ // /// Test PublishMessageAsync method and ReceiveMessage method
+ // /// </summary>
+ // /// <returns>void</returns>
+ // [Fact]
+ // public async Task PublishMessageAsync_and_ReceiveMessageTest()
+ // {
+ // var fixture = new InMemoryAgentRuntimeFixture();
+ // var (_, agent) = fixture.Start();
+ // var topicType = "TestTopic";
+ // await agent.SubscribeAsync(topicType).ConfigureAwait(true);
+ // var subscriptions = await agent.GetSubscriptionsAsync().ConfigureAwait(true);
+ // var found = false;
+ // foreach (var subscription in subscriptions)
+ // {
+ // if (subscription.TypeSubscription.TopicType == topicType)
+ // {
+ // found = true;
+ // }
+ // }
+ // Assert.True(found);
+ // await agent.PublishMessageAsync(new TextMessage()
+ // {
+ // Source = topicType,
+ // TextMessage_ = "buffer"
+ // }, topicType).ConfigureAwait(true);
+ // await Task.Delay(100);
+ // Assert.True(TestAgent.ReceivedMessages.ContainsKey(topicType));
+ // fixture.Stop();
+ // }
+
+ // [Fact]
+ // public async Task InvokeCorrectHandler()
+ // {
+ // var agent = new TestAgent(new AgentsMetadata(TypeRegistry.Empty, new Dictionary<string, Type>(), new Dictionary<Type, HashSet<string>>(), new Dictionary<Type, HashSet<string>>()), new Logger<Agent>(new LoggerFactory()));
+ // await agent.HandleObjectAsync("hello world");
+ // await agent.HandleObjectAsync(42);
+ // agent.ReceivedItems.Should().HaveCount(2);
+ // agent.ReceivedItems[0].Should().Be("hello world");
+ // agent.ReceivedItems[1].Should().Be(42);
+ // }
+
+ // [Fact]
+ // public async Task DelegateMessageToTestAgentAsync()
+ // {
+ // var runtime = new InMemoryAgentRuntimeFixture();
+ // var client = runtime.AppHost.Services.GetRequiredService<Client>();
+ // await client.PublishMessageAsync(new TextMessage()
+ // {
+ // Source = nameof(DelegateMessageToTestAgentAsync),
+ // TextMessage_ = "buffer"
+ // }, token: CancellationToken.None);
+
+ // // wait for 10 seconds
+ // var cts = new CancellationTokenSource(TimeSpan.FromSeconds(10));
+ // while (!TestAgent.ReceivedMessages.ContainsKey(nameof(DelegateMessageToTestAgentAsync)) && !cts.Token.IsCancellationRequested)
+ // {
+ // await Task.Delay(100);
+ // }
+
+ // TestAgent.ReceivedMessages[nameof(DelegateMessageToTestAgentAsync)].Should().NotBeNull();
+ // }
+
+ // [CollectionDefinition(Name)]
+ // public sealed class ClusterFixtureCollection : ICollectionFixture<InMemoryAgentRuntimeFixture>
+ // {
+ // public const string Name = nameof(ClusterFixtureCollection);
+ // }
+}
diff --git a/dotnet/test/Microsoft.AutoGen.Core.Tests/PythonEquiv/TestAgent.cs b/dotnet/test/Microsoft.AutoGen.Core.Tests/PythonEquiv/TestAgent.cs
new file mode 100644
index 000000000..ffbedd706
--- /dev/null
+++ b/dotnet/test/Microsoft.AutoGen.Core.Tests/PythonEquiv/TestAgent.cs
@@ -0,0 +1,61 @@
+// Copyright (c) Microsoft Corporation. All rights reserved.
+// TestAgent.cs
+
+using Microsoft.AutoGen.Contracts.Python;
+using Microsoft.AutoGen.Core.Python;
+using Microsoft.Extensions.Logging;
+
+namespace Microsoft.AutoGen.Core.Tests.Python;
+
+public class TextMessage
+{
+ public string Source { get; set; } = "";
+ public string Content { get; set; } = "";
+}
+
+/// <summary>
+/// The test agent is a simple agent that is used for testing purposes.
+/// </summary>
+public class TestAgent(AgentId id,
+ IAgentRuntime runtime,
+ Logger<BaseAgent>? logger = null) : BaseAgent(id, runtime, "Test Agent", logger),
+ Core.Python.IHandle<TextMessage>,
+ Core.Python.IHandle<string>,
+ Core.Python.IHandle<int>
+{
+ public Task Handle(TextMessage item, MessageContext messageContext)
+ {
+ ReceivedMessages[item.Source] = item.Content;
+ return Task.CompletedTask;
+ }
+
+ public Task Handle(string item, MessageContext messageContext)
+ {
+ ReceivedItems.Add(item);
+ return Task.CompletedTask;
+ }
+
+ public Task Handle(int item, MessageContext messageContext)
+ {
+ ReceivedItems.Add(item);
+ return Task.CompletedTask;
+ }
+
+ public List<object> ReceivedItems { get; private set; } = [];
+
+ /// <summary>
+ /// Key: source
+ /// Value: message
+ /// </summary>
+ public static Dictionary<string, object> ReceivedMessages { get; private set; } = new();
+}
+
+[TypeSubscription("TestTopic")]
+public class SubscribedAgent : TestAgent
+{
+ public SubscribedAgent(AgentId id,
+ IAgentRuntime runtime,
+ Logger<BaseAgent>? logger = null) : base(id, runtime, logger)
+ {
+ }
+}