A programming framework for agentic AI
[.Net] Add AOT compatible check for AutoGen.Core (#2858)
Xiaoyun Zhang84c7c2430c59
diff --git a/.github/workflows/dotnet-build.yml b/.github/workflows/dotnet-build.ymlindex 2e679412f..f4074b061 100644--- a/.github/workflows/dotnet-build.yml+++ b/.github/workflows/dotnet-build.yml@@ -67,6 +67,31 @@ jobs:dotnet build --no-restore --configuration Release -bl /p:SignAssembly=true- name: Unit Testrun: dotnet test --no-build -bl --configuration Release+ aot-test: # this make sure the AutoGen.Core is aot compatible+ strategy:+ fail-fast: false # ensures the entire test matrix is run, even if one permutation fails+ matrix:+ os: [ ubuntu-latest ]+ version: [ net8.0 ]+ needs: build+ defaults:+ run:+ working-directory: dotnet++ runs-on: ${{ matrix.os }}+ steps:+ - uses: actions/checkout@v4+ with:+ fetch-depth: 0 # fetching all++ - name: Setup dotnet+ uses: actions/setup-dotnet@v4+ with:+ global-json-file: dotnet/global.json++ - name: publish AOT testApp, assert static analysis warning count, and run the app+ shell: pwsh+ run: ./.tools/test-aot-compatibility.ps1 ${{ matrix.version }}openai-test:name: Run openai testruns-on: ubuntu-latest@@ -75,7 +100,7 @@ jobs:run:working-directory: dotnetif: success() && (github.ref == 'refs/heads/main')- needs: build+ needs: aot-teststeps:- uses: actions/checkout@v4with:diff --git a/dotnet/.tools/test-aot-compatibility.ps1 b/dotnet/.tools/test-aot-compatibility.ps1new file mode 100644index 000000000..071edcd95--- /dev/null+++ b/dotnet/.tools/test-aot-compatibility.ps1@@ -0,0 +1,41 @@+param([string]$targetNetFramework)++$rootDirectory = Split-Path $PSScriptRoot -Parent+$publishOutput = dotnet publish $rootDirectory/test/AutoGen.AotCompatibility.Tests -nodeReuse:false /p:UseSharedCompilation=false /p:ExposeExperimentalFeatures=true++$actualWarningCount = 0++foreach ($line in $($publishOutput -split "`r`n"))+{+ if ($line -like "*analysis warning IL*")+ {+ Write-Host $line++ $actualWarningCount += 1+ }+}++pushd $rootDirectory/test/AutoGen.AotCompatibility.Tests/bin/Release/$targetNetFramework/linux-x64++Write-Host "Executing test App..."+./AutoGen.AotCompatibility.Tests+Write-Host "Finished executing test App"++if ($LastExitCode -ne 0)+{+ Write-Host "There was an error while executing AotCompatibility Test App. LastExitCode is:", $LastExitCode+}++popd++Write-Host "Actual warning count is:", $actualWarningCount+$expectedWarningCount = 0++$testPassed = 0+if ($actualWarningCount -ne $expectedWarningCount)+{+ $testPassed = 1+ Write-Host "Actual warning count:", actualWarningCount, "is not as expected. Expected warning count is:", $expectedWarningCount+}++Exit $testPassed\ No newline at end of filediff --git a/dotnet/AutoGen.sln b/dotnet/AutoGen.slnindex de2549cae..2bc106c0a 100644--- a/dotnet/AutoGen.sln+++ b/dotnet/AutoGen.sln@@ -43,15 +43,17 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AutoGen.Ollama", "src\AutoGEndProjectProject("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AutoGen.Ollama.Tests", "test\AutoGen.Ollama.Tests\AutoGen.Ollama.Tests.csproj", "{03E31CAA-3728-48D3-B936-9F11CF6C18FE}"EndProject-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AutoGen.Ollama.Sample", "sample\AutoGen.Ollama.Sample\AutoGen.Ollama.Sample.csproj", "{93AA4D0D-6EE4-44D5-AD77-7F73A3934544}"+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AutoGen.Ollama.Sample", "sample\AutoGen.Ollama.Sample\AutoGen.Ollama.Sample.csproj", "{93AA4D0D-6EE4-44D5-AD77-7F73A3934544}"EndProject-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AutoGen.SemanticKernel.Sample", "sample\AutoGen.SemanticKernel.Sample\AutoGen.SemanticKernel.Sample.csproj", "{52958A60-3FF7-4243-9058-34A6E4F55C31}"+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AutoGen.SemanticKernel.Sample", "sample\AutoGen.SemanticKernel.Sample\AutoGen.SemanticKernel.Sample.csproj", "{52958A60-3FF7-4243-9058-34A6E4F55C31}"EndProject-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AutoGen.Anthropic", "src\AutoGen.Anthropic\AutoGen.Anthropic.csproj", "{6A95E113-B824-4524-8F13-CD0C3E1C8804}"+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AutoGen.Anthropic", "src\AutoGen.Anthropic\AutoGen.Anthropic.csproj", "{6A95E113-B824-4524-8F13-CD0C3E1C8804}"EndProject-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AutoGen.Anthropic.Tests", "test\AutoGen.Anthropic.Tests\AutoGen.Anthropic.Tests.csproj", "{815E937E-86D6-4476-9EC6-B7FBCBBB5DB6}"+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AutoGen.Anthropic.Tests", "test\AutoGen.Anthropic.Tests\AutoGen.Anthropic.Tests.csproj", "{815E937E-86D6-4476-9EC6-B7FBCBBB5DB6}"EndProject-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AutoGen.Anthropic.Samples", "sample\AutoGen.Anthropic.Samples\AutoGen.Anthropic.Samples.csproj", "{834B4E85-64E5-4382-8465-548F332E5298}"+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AutoGen.Anthropic.Samples", "sample\AutoGen.Anthropic.Samples\AutoGen.Anthropic.Samples.csproj", "{834B4E85-64E5-4382-8465-548F332E5298}"+EndProject+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AutoGen.AotCompatibility.Tests", "test\AutoGen.AotCompatibility.Tests\AutoGen.AotCompatibility.Tests.csproj", "{6B82F26D-5040-4453-B21B-C8D1F913CE4C}"EndProjectGlobalGlobalSection(SolutionConfigurationPlatforms) = preSolution@@ -147,6 +149,10 @@ Global{834B4E85-64E5-4382-8465-548F332E5298}.Debug|Any CPU.Build.0 = Debug|Any CPU{834B4E85-64E5-4382-8465-548F332E5298}.Release|Any CPU.ActiveCfg = Release|Any CPU{834B4E85-64E5-4382-8465-548F332E5298}.Release|Any CPU.Build.0 = Release|Any CPU+ {6B82F26D-5040-4453-B21B-C8D1F913CE4C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU+ {6B82F26D-5040-4453-B21B-C8D1F913CE4C}.Debug|Any CPU.Build.0 = Debug|Any CPU+ {6B82F26D-5040-4453-B21B-C8D1F913CE4C}.Release|Any CPU.ActiveCfg = Release|Any CPU+ {6B82F26D-5040-4453-B21B-C8D1F913CE4C}.Release|Any CPU.Build.0 = Release|Any CPUEndGlobalSectionGlobalSection(SolutionProperties) = preSolutionHideSolutionNode = FALSE@@ -167,13 +173,14 @@ Global{1DFABC4A-8458-4875-8DCB-59F3802DAC65} = {F823671B-3ECA-4AE6-86DA-25E920D3FE64}{D36A85F9-C172-487D-8192-6BFE5D05B4A7} = {F823671B-3ECA-4AE6-86DA-25E920D3FE64}{B61388CA-DC73-4B7F-A7B2-7B9A86C9229E} = {F823671B-3ECA-4AE6-86DA-25E920D3FE64}- {6A95E113-B824-4524-8F13-CD0C3E1C8804} = {18BF8DD7-0585-48BF-8F97-AD333080CE06}- {815E937E-86D6-4476-9EC6-B7FBCBBB5DB6} = {F823671B-3ECA-4AE6-86DA-25E920D3FE64}- {834B4E85-64E5-4382-8465-548F332E5298} = {FBFEAD1F-29EB-4D99-A672-0CD8473E10B9}{9F9E6DED-3D92-4970-909A-70FC11F1A665} = {18BF8DD7-0585-48BF-8F97-AD333080CE06}{03E31CAA-3728-48D3-B936-9F11CF6C18FE} = {F823671B-3ECA-4AE6-86DA-25E920D3FE64}{93AA4D0D-6EE4-44D5-AD77-7F73A3934544} = {FBFEAD1F-29EB-4D99-A672-0CD8473E10B9}{52958A60-3FF7-4243-9058-34A6E4F55C31} = {FBFEAD1F-29EB-4D99-A672-0CD8473E10B9}+ {6A95E113-B824-4524-8F13-CD0C3E1C8804} = {18BF8DD7-0585-48BF-8F97-AD333080CE06}+ {815E937E-86D6-4476-9EC6-B7FBCBBB5DB6} = {F823671B-3ECA-4AE6-86DA-25E920D3FE64}+ {834B4E85-64E5-4382-8465-548F332E5298} = {FBFEAD1F-29EB-4D99-A672-0CD8473E10B9}+ {6B82F26D-5040-4453-B21B-C8D1F913CE4C} = {F823671B-3ECA-4AE6-86DA-25E920D3FE64}EndGlobalSectionGlobalSection(ExtensibilityGlobals) = postSolutionSolutionGuid = {93384647-528D-46C8-922C-8DB36A382F0B}diff --git a/dotnet/eng/Version.props b/dotnet/eng/Version.propsindex ae2130154..a43da436b 100644--- a/dotnet/eng/Version.props+++ b/dotnet/eng/Version.props@@ -12,6 +12,6 @@<MicrosoftNETTestSdkVersion>17.7.0</MicrosoftNETTestSdkVersion><MicrosoftDotnetInteractive>1.0.0-beta.24229.4</MicrosoftDotnetInteractive><MicrosoftSourceLinkGitHubVersion>8.0.0</MicrosoftSourceLinkGitHubVersion>- <JsonSchemaVersion>4.0.0</JsonSchemaVersion>+ <JsonSchemaVersion>4.3.0.2</JsonSchemaVersion></PropertyGroup></Project>\ No newline at end of filediff --git a/dotnet/src/AutoGen.Anthropic/Converters/ContentBaseConverter.cs b/dotnet/src/AutoGen.Anthropic/Converters/ContentBaseConverter.csindex 281274048..4cb8fdbb3 100644--- a/dotnet/src/AutoGen.Anthropic/Converters/ContentBaseConverter.cs+++ b/dotnet/src/AutoGen.Anthropic/Converters/ContentBaseConverter.cs@@ -1,13 +1,13 @@-// Copyright (c) Microsoft Corporation. All rights reserved.+// Copyright (c) Microsoft Corporation. All rights reserved.// ContentConverter.csusing AutoGen.Anthropic.DTO;-namespace AutoGen.Anthropic.Converters;using System;using System.Text.Json;using System.Text.Json.Serialization;+namespace AutoGen.Anthropic.Converters;public sealed class ContentBaseConverter : JsonConverter<ContentBase>{diff --git a/dotnet/src/AutoGen.Core/AutoGen.Core.csproj b/dotnet/src/AutoGen.Core/AutoGen.Core.csprojindex ebbec3f0a..60aeb3ae3 100644--- a/dotnet/src/AutoGen.Core/AutoGen.Core.csproj+++ b/dotnet/src/AutoGen.Core/AutoGen.Core.csproj@@ -17,6 +17,7 @@<ItemGroup><PackageReference Include="JsonSchema.Net.Generation" Version="$(JsonSchemaVersion)" /><PackageReference Include="System.Memory.Data" Version="8.0.0" />+ <PackageReference Include="Microsoft.Bcl.AsyncInterfaces" Version="8.0.0" /></ItemGroup></Project>diff --git a/dotnet/src/AutoGen.Core/Extension/MessageExtension.cs b/dotnet/src/AutoGen.Core/Extension/MessageExtension.csindex 3dbba9668..d948c0517 100644--- a/dotnet/src/AutoGen.Core/Extension/MessageExtension.cs+++ b/dotnet/src/AutoGen.Core/Extension/MessageExtension.cs@@ -25,7 +25,7 @@ public static class MessageExtensionToolCallResultMessage toolCallResultMessage => toolCallResultMessage.FormatMessage(),AggregateMessage<ToolCallMessage, ToolCallResultMessage> aggregateMessage => aggregateMessage.FormatMessage(),_ => message.ToString(),- };+ } ?? string.Empty;}public static string FormatMessage(this TextMessage message)diff --git a/dotnet/src/AutoGen.Core/GroupChat/GroupChat.cs b/dotnet/src/AutoGen.Core/GroupChat/GroupChat.csindex cd17a21f8..5e82931ab 100644--- a/dotnet/src/AutoGen.Core/GroupChat/GroupChat.cs+++ b/dotnet/src/AutoGen.Core/GroupChat/GroupChat.cs@@ -95,7 +95,7 @@ public class GroupChat : IGroupChatif (agentNames.Count() == 1){- return this.agents.FirstOrDefault(x => x.Name == agentNames.First());+ return this.agents.First(x => x.Name == agentNames.First());}}diff --git a/dotnet/src/AutoGen.Mistral/AutoGen.Mistral.csproj b/dotnet/src/AutoGen.Mistral/AutoGen.Mistral.csprojindex f1bb8e0af..25cc05fec 100644--- a/dotnet/src/AutoGen.Mistral/AutoGen.Mistral.csproj+++ b/dotnet/src/AutoGen.Mistral/AutoGen.Mistral.csproj@@ -15,10 +15,6 @@</Description></PropertyGroup>- <ItemGroup>- <PackageReference Include="System.Memory.Data" Version="8.0.0" />- </ItemGroup>-<ItemGroup><ProjectReference Include="..\AutoGen.Core\AutoGen.Core.csproj" /></ItemGroup>diff --git a/dotnet/src/AutoGen.OpenAI/Middleware/OpenAIChatRequestMessageConnector.cs b/dotnet/src/AutoGen.OpenAI/Middleware/OpenAIChatRequestMessageConnector.csindex 8f1825e2f..246e50cc6 100644--- a/dotnet/src/AutoGen.OpenAI/Middleware/OpenAIChatRequestMessageConnector.cs+++ b/dotnet/src/AutoGen.OpenAI/Middleware/OpenAIChatRequestMessageConnector.cs@@ -314,9 +314,9 @@ public class OpenAIChatRequestMessageConnector : IMiddleware, IStreamingMiddlewaprivate ChatMessageImageContentItem CreateChatMessageImageContentItemFromImageMessage(ImageMessage message){- return message.Data is null+ return message.Data is null && message.Url is not null? new ChatMessageImageContentItem(new Uri(message.Url))- : new ChatMessageImageContentItem(message.Data, message.Data.MediaType);+ : new ChatMessageImageContentItem(message.Data, message.Data?.MediaType);}private IEnumerable<ChatRequestMessage> ProcessToolCallMessage(IAgent agent, ToolCallMessage message)diff --git a/dotnet/src/AutoGen/AutoGen.csproj b/dotnet/src/AutoGen/AutoGen.csprojindex 7e14ad4e7..c54b7c84a 100644--- a/dotnet/src/AutoGen/AutoGen.csproj+++ b/dotnet/src/AutoGen/AutoGen.csproj@@ -15,7 +15,6 @@</PropertyGroup><ItemGroup>- <PackageReference Include="JsonSchema.Net.Generation" Version="$(JsonSchemaVersion)" /><ProjectReference Include="..\AutoGen.LMStudio\AutoGen.LMStudio.csproj" /><ProjectReference Include="..\AutoGen.Mistral\AutoGen.Mistral.csproj" /><ProjectReference Include="..\AutoGen.SemanticKernel\AutoGen.SemanticKernel.csproj" />diff --git a/dotnet/test/AutoGen.AotCompatibility.Tests/AutoGen.AotCompatibility.Tests.csproj b/dotnet/test/AutoGen.AotCompatibility.Tests/AutoGen.AotCompatibility.Tests.csprojnew file mode 100644index 000000000..aec9660bb--- /dev/null+++ b/dotnet/test/AutoGen.AotCompatibility.Tests/AutoGen.AotCompatibility.Tests.csproj@@ -0,0 +1,24 @@+<Project Sdk="Microsoft.NET.Sdk">++ <PropertyGroup>+ <OutputType>Exe</OutputType>+ <TargetFramework>net8.0</TargetFramework>+ <ImplicitUsings>enable</ImplicitUsings>+ <Nullable>enable</Nullable>+ <PublishAot>true</PublishAot>+ <InvariantGlobalization>true</InvariantGlobalization>+ <GenerateDocumentationFile>True</GenerateDocumentationFile>+ <SelfContained>true</SelfContained>+ <IsAotCompatible>true</IsAotCompatible>+ </PropertyGroup>++ <ItemGroup>+ </ItemGroup>++ <ItemGroup>+ <TrimmerRootAssembly Include="AutoGen.Core" />+ <TrimmerRootAssembly Update="@(TrimmerRootAssembly)" Path="$(RepoRoot)\src\%(Identity)\%(Identity).csproj" />+ <ProjectReference Include="@(TrimmerRootAssembly->'%(Path)')" />+ </ItemGroup>++</Project>diff --git a/dotnet/test/AutoGen.AotCompatibility.Tests/Program.cs b/dotnet/test/AutoGen.AotCompatibility.Tests/Program.csnew file mode 100644index 000000000..ad2b881ef--- /dev/null+++ b/dotnet/test/AutoGen.AotCompatibility.Tests/Program.cs@@ -0,0 +1,4 @@+// Copyright (c) Microsoft Corporation. All rights reserved.+// Program.cs++Console.WriteLine("Hello, World!");