Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve e2e integration tests and isolate tests from other things; includes patch to Serializer #5497

Merged
merged 41 commits into from
Feb 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
eaf0cbd
bringing back grpc to helloagent
rysweet Feb 10, 2025
834dde4
interim commit
rysweet Feb 11, 2025
1cd9b45
cleanup InMemoryTest
rysweet Feb 11, 2025
c52a4ce
simplification
rysweet Feb 11, 2025
b41a6d7
stash
rysweet Feb 11, 2025
3b967ed
Merge branch 'main' into rysweet-ensure-helloagent-in-test-uses-grpc
rysweet Feb 11, 2025
ea1a2fc
Merge branch 'main' into rysweet-ensure-helloagent-in-test-uses-grpc
rysweet Feb 12, 2025
62bb27e
interim
rysweet Feb 12, 2025
20bfd1b
add dead letter queue.
rysweet Feb 12, 2025
90889f2
interim
rysweet Feb 12, 2025
00f0027
doh. already had one.
rysweet Feb 12, 2025
6d548cb
test
rysweet Feb 12, 2025
99a5b90
you have to run AddAgent<>
rysweet Feb 12, 2025
963501b
handle if registration happens before open channel and vice versa
rysweet Feb 12, 2025
a00f7fb
always add agent type
rysweet Feb 12, 2025
279cf22
important line for running delivery went missing.
rysweet Feb 12, 2025
2259185
ensure that we have a connection or write to dead letter until we do.
rysweet Feb 12, 2025
ab375f7
we can't throw on unrecognized message type
rysweet Feb 12, 2025
b25c4c1
improving the tests and avoiding a crash if no serialization
rysweet Feb 12, 2025
cd3e8b5
simplify
rysweet Feb 12, 2025
1190d0e
backing off some of my changes to rebase
rysweet Feb 13, 2025
d1fd051
fixing up sln file afer rebase
rysweet Feb 13, 2025
cb2e89c
Merge branch 'main' into rysweet-ensure-helloagent-in-test-uses-grpc
rysweet Feb 13, 2025
1d7d4aa
format
rysweet Feb 13, 2025
02210ed
rename the tests to read better
rysweet Feb 13, 2025
d717745
rename again
rysweet Feb 13, 2025
f52e436
add in dlq to try and deal with races
rysweet Feb 13, 2025
6a90016
use the protos from the agents package
rysweet Feb 13, 2025
7150217
send message with TopicId.Key
rysweet Feb 13, 2025
5a41f42
serializer needed tryadd
rysweet Feb 13, 2025
e104780
change topic of output message
rysweet Feb 13, 2025
877c388
add debug log entry
rysweet Feb 13, 2025
9c890a5
update test message
rysweet Feb 13, 2025
eb2670f
move the xlang python test agent into the dotnet integration tests dir.
rysweet Feb 13, 2025
edfda21
improe debugging experience
rysweet Feb 13, 2025
b763194
format
rysweet Feb 13, 2025
d2daeda
Merge branch 'main' into rysweet-ensure-helloagent-in-test-uses-grpc
rysweet Feb 13, 2025
1ae2596
give back mains uv.lock
rysweet Feb 14, 2025
7259d55
add blank line
rysweet Feb 14, 2025
35ead9c
Merge branch 'main' into rysweet-ensure-helloagent-in-test-uses-grpc
rysweet Feb 14, 2025
a61c134
reduce environment usage
rysweet Feb 14, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 23 additions & 2 deletions dotnet/AutoGen.sln
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,13 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.AutoGen.AgentChat
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.AutoGen.AgentChat.Tests", "test\Microsoft.AutoGen.AgentChat.Tests\Microsoft.AutoGen.AgentChat.Tests.csproj", "{217A4F86-8ADD-4998-90BA-880092A019F5}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HelloAgent.AppHost", "test\Microsoft.AutoGen.Integration.Tests.AppHosts\HelloAgent.AppHost\HelloAgent.AppHost.csproj", "{0C371D65-7EF9-44EA-8128-A105DA82A80E}"
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Microsoft.AutoGen.Integration.Tests.AppHosts", "Microsoft.AutoGen.Integration.Tests.AppHosts", "{D1C2B0BB-1276-4146-A699-D1983AE8ED04}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HelloAgentTests", "test\Microsoft.AutoGen.Integration.Tests.AppHosts\HelloAgentTests\HelloAgentTests.csproj", "{CD10E29A-725E-4BEF-9CFF-6C0E0A652926}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "InMemoryTests.AppHost", "test\Microsoft.AutoGen.Integration.Tests.AppHosts\InMemoryTests.AppHost\InMemoryTests.AppHost.csproj", "{1E4E1ED4-7701-4A05-A861-64461C3B1EE3}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "XlangTests.AppHost", "test\Microsoft.AutoGen.Integration.Tests.AppHosts\XLangTests.AppHost\XlangTests.AppHost.csproj", "{62CDFB27-3B02-4D4B-B789-8AAD5E20688A}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down Expand Up @@ -372,6 +378,18 @@ Global
{0C371D65-7EF9-44EA-8128-A105DA82A80E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0C371D65-7EF9-44EA-8128-A105DA82A80E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0C371D65-7EF9-44EA-8128-A105DA82A80E}.Release|Any CPU.Build.0 = Release|Any CPU
{CD10E29A-725E-4BEF-9CFF-6C0E0A652926}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{CD10E29A-725E-4BEF-9CFF-6C0E0A652926}.Debug|Any CPU.Build.0 = Debug|Any CPU
{CD10E29A-725E-4BEF-9CFF-6C0E0A652926}.Release|Any CPU.ActiveCfg = Release|Any CPU
{CD10E29A-725E-4BEF-9CFF-6C0E0A652926}.Release|Any CPU.Build.0 = Release|Any CPU
{1E4E1ED4-7701-4A05-A861-64461C3B1EE3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{1E4E1ED4-7701-4A05-A861-64461C3B1EE3}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1E4E1ED4-7701-4A05-A861-64461C3B1EE3}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1E4E1ED4-7701-4A05-A861-64461C3B1EE3}.Release|Any CPU.Build.0 = Release|Any CPU
{62CDFB27-3B02-4D4B-B789-8AAD5E20688A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{62CDFB27-3B02-4D4B-B789-8AAD5E20688A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{62CDFB27-3B02-4D4B-B789-8AAD5E20688A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{62CDFB27-3B02-4D4B-B789-8AAD5E20688A}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -436,7 +454,10 @@ Global
{EF954ED3-87D5-40F1-8557-E7179F43EA0E} = {18BF8DD7-0585-48BF-8F97-AD333080CE06}
{7F828599-56E8-4597-8F68-EE26FD631417} = {18BF8DD7-0585-48BF-8F97-AD333080CE06}
{217A4F86-8ADD-4998-90BA-880092A019F5} = {F823671B-3ECA-4AE6-86DA-25E920D3FE64}
{0C371D65-7EF9-44EA-8128-A105DA82A80E} = {F42F9C8E-7BD9-4687-9B63-AFFA461AF5C1}
{D1C2B0BB-1276-4146-A699-D1983AE8ED04} = {F823671B-3ECA-4AE6-86DA-25E920D3FE64}
{CD10E29A-725E-4BEF-9CFF-6C0E0A652926} = {D1C2B0BB-1276-4146-A699-D1983AE8ED04}
{1E4E1ED4-7701-4A05-A861-64461C3B1EE3} = {D1C2B0BB-1276-4146-A699-D1983AE8ED04}
{62CDFB27-3B02-4D4B-B789-8AAD5E20688A} = {D1C2B0BB-1276-4146-A699-D1983AE8ED04}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {93384647-528D-46C8-922C-8DB36A382F0B}
Expand Down
1 change: 1 addition & 0 deletions dotnet/samples/Hello/HelloAgent/HelloAgent.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
<ProjectReference Include="..\..\..\src\Microsoft.AutoGen\Contracts\Microsoft.AutoGen.Contracts.csproj" />
<ProjectReference Include="..\..\..\src\Microsoft.AutoGen\Core.Grpc\Microsoft.AutoGen.Core.Grpc.csproj" />
<ProjectReference Include="..\..\..\src\Microsoft.AutoGen\Core\Microsoft.AutoGen.Core.csproj" />
<ProjectReference Include="..\..\..\src\Microsoft.AutoGen\Core.Grpc\Microsoft.AutoGen.Core.Grpc.csproj" />
</ItemGroup>

<ItemGroup>
Expand Down
24 changes: 16 additions & 8 deletions dotnet/samples/Hello/HelloAgent/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,22 @@
using Microsoft.AutoGen.Agents;
using Microsoft.AutoGen.Contracts;
using Microsoft.AutoGen.Core;
using Microsoft.AutoGen.Core.Grpc;
using Samples;

// Set up app builder for in-process runtime, allow message delivery to self, and add the Hello agent
AgentsAppBuilder appBuilder = new AgentsAppBuilder()
.UseInProcessRuntime(deliverToSelf: true)
.AddAgent<HelloAgent>("HelloAgent");
var appBuilder = new AgentsAppBuilder(); // Create app builder
// if we are using distributed, we need the AGENT_HOST var defined and then we will use the grpc runtime
if (Environment.GetEnvironmentVariable("AGENT_HOST") is string agentHost)
{
appBuilder.AddGrpcAgentWorker(agentHost)
.AddAgent<HelloAgent>("HelloAgent");
}
else
{
// Set up app builder for in-process runtime, allow message delivery to self, and add the Hello agent
appBuilder.UseInProcessRuntime(deliverToSelf: true).AddAgent<HelloAgent>("HelloAgent");
}
var app = await appBuilder.BuildAsync(); // Build the app
// Create a custom message type from proto and define message
NewMessageReceived message = new NewMessageReceived { Message = "Hello World!" };
await app.PublishMessageAsync(message, new TopicId("HelloTopic")); // Publish custom message (handler has been set in HelloAgent)
await app.WaitForShutdownAsync(); // Wait for shutdown from agent
var message = new NewMessageReceived { Message = "Hello World!" };
await app.PublishMessageAsync(message, new TopicId("HelloTopic")).ConfigureAwait(false); // Publish custom message (handler has been set in HelloAgent)
await app.WaitForShutdownAsync().ConfigureAwait(false); // Wait for shutdown from agent
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// IHandleConsole.cs
using Google.Protobuf;
using Microsoft.AutoGen.Contracts;

namespace Microsoft.AutoGen.Agents;
Expand All @@ -14,13 +13,12 @@
/// <summary>
/// Prototype for Publish Message Async method
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="message"></param>
/// <param name="topic"></param>
/// <param name="messageId"></param>
/// <param name="token"></param>
/// <param name="cancellationToken"></param>
/// <returns>ValueTask</returns>
ValueTask PublishMessageAsync<T>(T message, TopicId topic, string? messageId, CancellationToken token = default) where T : IMessage;
ValueTask PublishMessageAsync(object message, TopicId topic, string? messageId = null, CancellationToken cancellationToken = default);

/// <summary>
/// Receives events of type Output and writes them to the console
Expand All @@ -39,7 +37,7 @@
{
Route = "console"
};
await PublishMessageAsync(evt, new TopicId("OutputWritten"), null, token: CancellationToken.None).ConfigureAwait(false);
await PublishMessageAsync(evt, new TopicId("OutputWritten"), null, cancellationToken: CancellationToken.None).ConfigureAwait(false);

Check warning on line 40 in dotnet/src/Microsoft.AutoGen/Agents/IOAgent/ConsoleAgent/IHandleConsole.cs

View check run for this annotation

Codecov / codecov/patch

dotnet/src/Microsoft.AutoGen/Agents/IOAgent/ConsoleAgent/IHandleConsole.cs#L40

Added line #L40 was not covered by tests
}

/// <summary>
Expand All @@ -60,6 +58,6 @@
{
Route = "console"
};
await PublishMessageAsync(evt, new TopicId("InputProcessed"), null, token: CancellationToken.None).ConfigureAwait(false);
await PublishMessageAsync(evt, new TopicId("InputProcessed"), null, cancellationToken: CancellationToken.None).ConfigureAwait(false);

Check warning on line 61 in dotnet/src/Microsoft.AutoGen/Agents/IOAgent/ConsoleAgent/IHandleConsole.cs

View check run for this annotation

Codecov / codecov/patch

dotnet/src/Microsoft.AutoGen/Agents/IOAgent/ConsoleAgent/IHandleConsole.cs#L61

Added line #L61 was not covered by tests
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// IHandleFileIO.cs

using Google.Protobuf;
using Microsoft.AutoGen.Contracts;
using Microsoft.Extensions.Logging;

Expand All @@ -25,13 +23,12 @@
/// <summary>
/// Prototype for Publish Message Async method
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="message"></param>
/// <param name="topic"></param>
/// <param name="messageId"></param>
/// <param name="token"></param>
/// <param name="cancellationToken"></param>
/// <returns>ValueTask</returns>
ValueTask PublishMessageAsync<T>(T message, TopicId topic, string? messageId, CancellationToken token = default) where T : IMessage;
ValueTask PublishMessageAsync(object message, TopicId topic, string? messageId = null, CancellationToken cancellationToken = default);
async ValueTask IHandle<Input>.HandleAsync(Input item, MessageContext messageContext)
{

Expand All @@ -45,7 +42,7 @@
{
Message = errorMessage
};
await PublishMessageAsync(err, new TopicId("IOError"), null, token: CancellationToken.None).ConfigureAwait(false);
await PublishMessageAsync(err, new TopicId("IOError"), null, cancellationToken: CancellationToken.None).ConfigureAwait(false);

Check warning on line 45 in dotnet/src/Microsoft.AutoGen/Agents/IOAgent/FileAgent/IHandleFileIO.cs

View check run for this annotation

Codecov / codecov/patch

dotnet/src/Microsoft.AutoGen/Agents/IOAgent/FileAgent/IHandleFileIO.cs#L45

Added line #L45 was not covered by tests
return;
}
string content;
Expand All @@ -58,7 +55,7 @@
{
Route = Route
};
await PublishMessageAsync(evt, new TopicId("InputProcessed"), null, token: CancellationToken.None).ConfigureAwait(false);
await PublishMessageAsync(evt, new TopicId("InputProcessed"), null, cancellationToken: CancellationToken.None).ConfigureAwait(false);

Check warning on line 58 in dotnet/src/Microsoft.AutoGen/Agents/IOAgent/FileAgent/IHandleFileIO.cs

View check run for this annotation

Codecov / codecov/patch

dotnet/src/Microsoft.AutoGen/Agents/IOAgent/FileAgent/IHandleFileIO.cs#L58

Added line #L58 was not covered by tests
}
async ValueTask IHandle<Output>.HandleAsync(Output item, MessageContext messageContext)
{
Expand All @@ -70,6 +67,6 @@
{
Route = Route
};
await PublishMessageAsync(evt, new TopicId("OutputWritten"), null, token: CancellationToken.None).ConfigureAwait(false);
await PublishMessageAsync(evt, new TopicId("OutputWritten"), null, cancellationToken: CancellationToken.None).ConfigureAwait(false);

Check warning on line 70 in dotnet/src/Microsoft.AutoGen/Agents/IOAgent/FileAgent/IHandleFileIO.cs

View check run for this annotation

Codecov / codecov/patch

dotnet/src/Microsoft.AutoGen/Agents/IOAgent/FileAgent/IHandleFileIO.cs#L70

Added line #L70 was not covered by tests
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,7 @@ public bool Exists(Type type)

public void RegisterSerializer(Type type, IProtobufMessageSerializer serializer)
{
if (_serializers.ContainsKey(TypeNameResolver.ResolveTypeName(type)))
{
throw new InvalidOperationException($"Serializer already registered for {type.FullName}");
}
_serializers.TryAdd(TypeNameResolver.ResolveTypeName(type), serializer);
_serializers[TypeNameResolver.ResolveTypeName(type)] = serializer;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,40 @@
using Microsoft.AutoGen.Protobuf;

namespace Microsoft.AutoGen.RuntimeGateway.Grpc.Abstractions;

/// <summary>
/// Stores agent subscription information such as topic and prefix mappings,
/// and maintains an ETag for concurrency checks.
/// </summary>
public class AgentsRegistryState
{
/// <summary>
/// Maps each agent ID to the set of topics they subscribe to.
/// </summary>
public ConcurrentDictionary<string, HashSet<string>> AgentsToTopicsMap { get; set; } = [];

/// <summary>
/// Maps each agent ID to the set of topic prefixes they subscribe to.
/// </summary>
public ConcurrentDictionary<string, HashSet<string>> AgentsToTopicsPrefixMap { get; set; } = [];

/// <summary>
/// Maps each topic name to the set of agent types subscribed to it.
/// </summary>
public ConcurrentDictionary<string, HashSet<string>> TopicToAgentTypesMap { get; set; } = [];

/// <summary>
/// Maps each topic prefix to the set of agent types subscribed to it.
/// </summary>
public ConcurrentDictionary<string, HashSet<string>> TopicPrefixToAgentTypesMap { get; set; } = [];

/// <summary>
/// Stores subscriptions by GUID
/// </summary>
public ConcurrentDictionary<string, HashSet<Subscription>> GuidSubscriptionsMap { get; set; } = [];

/// <summary>
/// The concurrency ETag for identifying the registry's version or state.
/// </summary>
public string Etag { get; set; } = Guid.NewGuid().ToString();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// IMessageRegistryGrain.cs

using Microsoft.AutoGen.Contracts;

namespace Microsoft.AutoGen.RuntimeGateway.Grpc.Abstractions;

public interface IMessageRegistryGrain : IGrainWithIntegerKey
{
/// <summary>
/// Writes a message to the dead-letter queue for the given topic.
/// </summary>
Task WriteMessageAsync(string topic, CloudEvent message);

/// <summary>
/// Removes all messages for the given topic from the dead-letter queue.
/// </summary>
/// <param name="topic">The topic to remove messages for.</param>
/// <returns>A task representing the asynchronous operation, with the list of removed messages as the result.</returns>
Task<List<CloudEvent>> RemoveMessagesAsync(string topic);
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// MessageRegistryState.cs

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

namespace Microsoft.AutoGen.RuntimeGateway.Grpc.Abstractions;

/// <summary>
/// Holds a dead-letter queue by topic type.
/// </summary>
public class MessageRegistryState
{
/// <summary>
/// Dictionary mapping topic types to a list of CloudEvents that failed delivery.
/// </summary>
public ConcurrentDictionary<string, List<CloudEvent>> DeadLetterQueue { get; set; } = new();

Check warning on line 17 in dotnet/src/Microsoft.AutoGen/RuntimeGateway.Grpc/Abstractions/MessageRegistryState.cs

View check run for this annotation

Codecov / codecov/patch

dotnet/src/Microsoft.AutoGen/RuntimeGateway.Grpc/Abstractions/MessageRegistryState.cs#L17

Added line #L17 was not covered by tests
}
Loading
Loading