Skip to content

Commit

Permalink
merging dotnet from main
Browse files Browse the repository at this point in the history
  • Loading branch information
rysweet committed Nov 21, 2024
1 parent c591c9e commit f8b43de
Show file tree
Hide file tree
Showing 40 changed files with 261 additions and 134 deletions.
2 changes: 1 addition & 1 deletion dotnet/.tools/test-aot-compatibility.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ foreach ($line in $($publishOutput -split "`r`n"))
}
}

pushd $rootDirectory/test/AutoGen.AotCompatibility.Tests/bin/Release/$targetNetFramework/linux-x64
pushd $rootDirectory/artifacts/bin/AutoGen.AotCompatibility.Tests/release

Write-Host "Executing test App..."
./AutoGen.AotCompatibility.Tests
Expand Down
6 changes: 3 additions & 3 deletions dotnet/AutoGen.sln
Original file line number Diff line number Diff line change
Expand Up @@ -122,15 +122,15 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HelloAIAgents", "samples\He
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HelloAgent", "samples\Hello\HelloAgent\HelloAgent.csproj", "{8F7560CF-EEBB-4333-A69F-838CA40FD85D}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AIModelClientHostingExtensions", "src\Microsoft.AutoGen\Extensions\AIModelClientHostingExtensions\AIModelClientHostingExtensions.csproj", "{97550E87-48C6-4EBF-85E1-413ABAE9DBFD}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.AutoGen.Extensions.MEAI", "src\Microsoft.AutoGen\Extensions\MEAI\Microsoft.AutoGen.Extensions.MEAI.csproj", "{97550E87-48C6-4EBF-85E1-413ABAE9DBFD}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "sample", "sample", "{686480D7-8FEC-4ED3-9C5D-CEBE1057A7ED}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HelloAgentState", "samples\Hello\HelloAgentState\HelloAgentState.csproj", "{64EF61E7-00A6-4E5E-9808-62E10993A0E5}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.AutoGen.ServiceDefaults", "src\Microsoft.AutoGen\Extensions\ServiceDefaults\Microsoft.AutoGen.ServiceDefaults.csproj", "{65059914-5527-4A00-9308-9FAF23D5E85A}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.AutoGen.Extensions.Aspire", "src\Microsoft.AutoGen\Extensions\Aspire\Microsoft.AutoGen.Extensions.Aspire.csproj", "{65059914-5527-4A00-9308-9FAF23D5E85A}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.AutoGen.Agents.Tests", "test\Microsoft.AutoGen.Agents.Tests\Microsoft.AutoGen.Agents.Tests.csproj", "{394FDAF8-74F9-4977-94A5-3371737EB774}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.AutoGen.Agents.Tests", "test\Microsoft.AutoGen.Agents.Tests\Microsoft.AutoGen.Agents.Tests.csproj", "{394FDAF8-74F9-4977-94A5-3371737EB774}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down
7 changes: 6 additions & 1 deletion dotnet/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<Import Project="./eng/MetaInfo.props" />
<Import Project="./eng/Sign.props" />
<PropertyGroup>
<UseArtifactsOutput>true</UseArtifactsOutput>
<PackageTargetFrameworks>netstandard2.0;net8.0</PackageTargetFrameworks>
<TestTargetFrameworks>net8.0</TestTargetFrameworks>
<LangVersion>preview</LangVersion>
Expand All @@ -20,7 +21,6 @@
<EnableNetAnalyzers>true</EnableNetAnalyzers>
<EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild>
<IsTestProject>false</IsTestProject>

<DebugType>embedded</DebugType>
<DebugSymbols>true</DebugSymbols>
</PropertyGroup>
Expand All @@ -29,6 +29,11 @@
<RepoRoot>$(MSBuildThisFileDirectory)</RepoRoot>
</PropertyGroup>

<PropertyGroup Condition="'$(MSBuildProjectName.StartsWith(`AutoGen`))' == 'true'">
<VersionPrefix>$(VersionPrefixForAutoGen0_2)</VersionPrefix>
<IsAutoGen0_2>true</IsAutoGen0_2>
</PropertyGroup>

<PropertyGroup Condition="'$(IsTestProject)' == 'true'">
<NoWarn>$(NoWarn);CA1829</NoWarn>
</PropertyGroup>
Expand Down
2 changes: 1 addition & 1 deletion dotnet/Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,8 @@
<PackageVersion Include="Microsoft.DotNet.Interactive.PackageManagement" Version="1.0.0-beta.24229.4" />
<PackageVersion Include="Google.Cloud.AIPlatform.V1" Version="3.10.0" />
<PackageVersion Include="OpenAI" Version="2.1.0-beta.1" />
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="4.8.0" />
<PackageVersion Include="System.CodeDom" Version="9.0.0" />
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="4.11.0" />
<PackageVersion Include="Microsoft.SourceLink.GitHub" Version="8.0.0" />
<PackageVersion Include="ApprovalTests" Version="6.0.0" />
<PackageVersion Include="FluentAssertions" Version="6.12.2" />
Expand Down
8 changes: 3 additions & 5 deletions dotnet/README.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@
# AutoGen for .NET

Thre are two sets of packages here:
Autogen.\* the older packages derived from Autogen 0.2 for .NET - these will gradually be deprecated and ported into the new packages
AutoGen.\* the older packages derived from AutoGen 0.2 for .NET - these will gradually be deprecated and ported into the new packages
Microsoft.AutoGen.* the new packages for .NET that use the event-driven model - These APIs are not yet stable and are subject to change.

To get started with the new packages, please see the [samples](./samples/) and in particular the [Hello](./samples/Hello) sample.

The remaining content is for the older Autogen.* packages.
You can install both new and old packages from the following feeds:

[![dotnet-ci](https://github.com/microsoft/autogen/actions/workflows/dotnet-build.yml/badge.svg)](https://github.com/microsoft/autogen/actions/workflows/dotnet-build.yml)
[![NuGet version](https://badge.fury.io/nu/AutoGen.Core.svg)](https://badge.fury.io/nu/AutoGen.Core)

> [!NOTE]
> Nightly build is available at:
>
> - ![Static Badge](https://img.shields.io/badge/public-blue?style=flat) ![Static Badge](https://img.shields.io/badge/nightly-yellow?style=flat) ![Static Badge](https://img.shields.io/badge/github-grey?style=flat): <https://nuget.pkg.github.com/microsoft/index.json>
> - ![Static Badge](https://img.shields.io/badge/public-blue?style=flat) ![Static Badge](https://img.shields.io/badge/nightly-yellow?style=flat) ![Static Badge](https://img.shields.io/badge/myget-grey?style=flat): <https://www.myget.org/F/agentchat/api/v3/index.json>
> - ![Static Badge](https://img.shields.io/badge/internal-blue?style=flat) ![Static Badge](https://img.shields.io/badge/nightly-yellow?style=flat) ![Static Badge](https://img.shields.io/badge/azure_devops-grey?style=flat) : <https://devdiv.pkgs.visualstudio.com/DevDiv/_packaging/AutoGen/nuget/v3/index.json>
> - [![Static Badge](https://img.shields.io/badge/azure_devops-grey?style=flat)](https://dev.azure.com/AGPublish/AGPublic/_artifacts/feed/AutoGen-Nightly) : <https://pkgs.dev.azure.com/AGPublish/AGPublic/_packaging/AutoGen-Nightly/nuget/v3/index.json>
Firstly, following the [installation guide](./website/articles/Installation.md) to install AutoGen packages.

Expand Down
3 changes: 2 additions & 1 deletion dotnet/eng/MetaInfo.props
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<VersionPrefix>0.2.2</VersionPrefix>
<VersionPrefix>0.4.0</VersionPrefix>
<VersionPrefixForAutoGen0_2>0.2.2</VersionPrefixForAutoGen0_2>
<Authors>AutoGen</Authors>
<PackageProjectUrl>https://microsoft.github.io/autogen-for-net/</PackageProjectUrl>
<RepositoryUrl>https://github.com/microsoft/autogen</RepositoryUrl>
Expand Down
2 changes: 1 addition & 1 deletion dotnet/nuget/nuget-package.props
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<Company>Microsoft</Company>
<Product>AutoGen</Product>
<Description>A programming framework for agentic AI</Description>
<PackageTags>AI, Artificial Intelligence, SDK</PackageTags>
<PackageTags>AI, Artificial Intelligence, Agents, Multiagent, SDK</PackageTags>
<PackageId>$(AssemblyName)</PackageId>

<!-- Required license, copyright, and repo information. Packages can override. -->
Expand Down
2 changes: 1 addition & 1 deletion dotnet/samples/Hello/Backend/Backend.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
</ItemGroup>
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
Expand Down
15 changes: 0 additions & 15 deletions dotnet/samples/Hello/Backend/appsettings.Development.json

This file was deleted.

7 changes: 7 additions & 0 deletions dotnet/samples/Hello/Backend/appsettings.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
{
"Logging": {
"LogLevel": {
"Default": "Warning",
"Microsoft": "Warning",
"Microsoft.Orleans": "Warning"
}
},
"AllowedHosts": "*",
"Kestrel": {
"EndpointDefaults": {
Expand Down
2 changes: 1 addition & 1 deletion dotnet/samples/Hello/HelloAIAgents/HelloAIAgents.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@
<ItemGroup>
<ProjectReference Include="..\..\..\src\Microsoft.AutoGen\Abstractions\Microsoft.AutoGen.Abstractions.csproj" />
<ProjectReference Include="..\..\..\src\Microsoft.AutoGen\Agents\Microsoft.AutoGen.Agents.csproj" />
<ProjectReference Include="..\..\..\src\Microsoft.AutoGen\Extensions\AIModelClientHostingExtensions\AIModelClientHostingExtensions.csproj" />
<ProjectReference Include="..\..\..\src\Microsoft.AutoGen\Extensions\MEAI\Microsoft.AutoGen.Extensions.MEAI.csproj" />
</ItemGroup>
</Project>
2 changes: 1 addition & 1 deletion dotnet/samples/Hello/HelloAgent/HelloAgent.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

<ItemGroup>
<ProjectReference Include="../../../src/Microsoft.AutoGen/Agents/Microsoft.AutoGen.Agents.csproj" />
<ProjectReference Include="../../../src/Microsoft.AutoGen/Extensions/ServiceDefaults/Microsoft.AutoGen.ServiceDefaults.csproj" />
<ProjectReference Include="..\..\..\src\Microsoft.AutoGen\Extensions\Aspire\Microsoft.AutoGen.Extensions.Aspire.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

<ProjectReference Include="../../../src/Microsoft.AutoGen/Agents/Microsoft.AutoGen.Agents.csproj" />

<ProjectReference Include="../../../src/Microsoft.AutoGen/Extensions/ServiceDefaults/Microsoft.AutoGen.ServiceDefaults.csproj" />
<ProjectReference Include="..\..\..\src\Microsoft.AutoGen\Extensions\Aspire\Microsoft.AutoGen.Extensions.Aspire.csproj" />
<ProjectReference Include="..\DevTeam.Shared\DevTeam.Shared.csproj" />
<ProjectReference Include="..\..\..\src\Microsoft.AutoGen\Extensions\SemanticKernel\Microsoft.AutoGen.Extensions.SemanticKernel.csproj" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
</ItemGroup>

<ItemGroup>
<ProjectReference Include="../../../src/Microsoft.AutoGen/Extensions/ServiceDefaults/Microsoft.AutoGen.ServiceDefaults.csproj" />
<ProjectReference Include="..\..\..\src\Microsoft.AutoGen\Extensions\Aspire\Microsoft.AutoGen.Extensions.Aspire.csproj" />
<ProjectReference Include="..\DevTeam.Shared\DevTeam.Shared.csproj" />
<ProjectReference Include="..\..\..\src\Microsoft.AutoGen\Extensions\SemanticKernel\Microsoft.AutoGen.Extensions.SemanticKernel.csproj" />
</ItemGroup>
Expand Down
4 changes: 2 additions & 2 deletions dotnet/samples/dev-team/DevTeam.Backend/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,9 @@
}); ;

app.UseSwagger();
app.UseSwaggerUI(c =>
/* app.UseSwaggerUI(c =>
{
c.SwaggerEndpoint("/swagger/v1/swagger.json", "My API V1");
});
}); */

app.Run();
64 changes: 45 additions & 19 deletions dotnet/src/AutoGen.Core/Message/ImageMessage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,39 +2,65 @@
// ImageMessage.cs

using System;
using System.Text.RegularExpressions;

namespace AutoGen.Core;

public class ImageMessage : IMessage
{
public ImageMessage(Role role, string url, string? from = null, string? mimeType = null)
: this(role, new Uri(url), from, mimeType)
{
}
private static readonly Regex s_DataUriRegex = new Regex(@"^data:(?<mediatype>[^;]+);base64,(?<data>.*)$", RegexOptions.Compiled);

public ImageMessage(Role role, Uri uri, string? from = null, string? mimeType = null)
/// <summary>
/// Create an ImageMessage from a url.
/// The url can be a regular url or a data uri.
/// If the url is a data uri, the scheme must be "data" and the format must be data:[<mediatype>][;base64],<data>
/// </summary>
public ImageMessage(Role role, string url, string? from = null, string? mimeType = null)
{
this.Role = role;
this.From = from;
this.Url = uri.ToString();

// try infer mimeType from uri extension if not provided
if (mimeType is null)
// url might be a data uri or a regular url
if (url.StartsWith("data:", StringComparison.OrdinalIgnoreCase))
{
// the url must be in the format of data:[<mediatype>][;base64],<data>
var match = s_DataUriRegex.Match(url);

if (!match.Success)
{
throw new ArgumentException("Invalid DataUri format, expected data:[<mediatype>][;base64],<data>", nameof(url));
}

this.Data = new BinaryData(Convert.FromBase64String(match.Groups["data"].Value), match.Groups["mediatype"].Value);

this.MimeType = match.Groups["mediatype"].Value;
}
else
{
mimeType = uri switch
this.Url = url;
// try infer mimeType from uri extension if not provided
if (mimeType is null)
{
_ when uri.AbsoluteUri.EndsWith(".png", StringComparison.OrdinalIgnoreCase) => "image/png",
_ when uri.AbsoluteUri.EndsWith(".jpg", StringComparison.OrdinalIgnoreCase) => "image/jpeg",
_ when uri.AbsoluteUri.EndsWith(".jpeg", StringComparison.OrdinalIgnoreCase) => "image/jpeg",
_ when uri.AbsoluteUri.EndsWith(".gif", StringComparison.OrdinalIgnoreCase) => "image/gif",
_ when uri.AbsoluteUri.EndsWith(".bmp", StringComparison.OrdinalIgnoreCase) => "image/bmp",
_ when uri.AbsoluteUri.EndsWith(".webp", StringComparison.OrdinalIgnoreCase) => "image/webp",
_ when uri.AbsoluteUri.EndsWith(".svg", StringComparison.OrdinalIgnoreCase) => "image/svg+xml",
_ => throw new ArgumentException("MimeType is required for ImageMessage", nameof(mimeType))
};
mimeType = url switch
{
_ when url.EndsWith(".png", StringComparison.OrdinalIgnoreCase) => "image/png",
_ when url.EndsWith(".jpg", StringComparison.OrdinalIgnoreCase) => "image/jpeg",
_ when url.EndsWith(".jpeg", StringComparison.OrdinalIgnoreCase) => "image/jpeg",
_ when url.EndsWith(".gif", StringComparison.OrdinalIgnoreCase) => "image/gif",
_ when url.EndsWith(".bmp", StringComparison.OrdinalIgnoreCase) => "image/bmp",
_ when url.EndsWith(".webp", StringComparison.OrdinalIgnoreCase) => "image/webp",
_ when url.EndsWith(".svg", StringComparison.OrdinalIgnoreCase) => "image/svg+xml",
_ => throw new ArgumentException("MimeType is required for ImageMessage", nameof(mimeType))
};
}

this.MimeType = mimeType;
}
}

this.MimeType = mimeType;
public ImageMessage(Role role, Uri uri, string? from = null, string? mimeType = null)
: this(role, uri.ToString(), from, mimeType)
{
}

public ImageMessage(Role role, BinaryData data, string? from = null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,19 @@ private IEnumerable<ChatMessageContent> ProcessMessageForOthers(TextMessage mess
private IEnumerable<ChatMessageContent> ProcessMessageForOthers(ImageMessage message)
{
var collectionItems = new ChatMessageContentItemCollection();
collectionItems.Add(new ImageContent(new Uri(message.Url ?? message.BuildDataUri())));
if (message.Url is not null)
{
collectionItems.Add(new ImageContent(new Uri(message.Url)));
}
else if (message.BuildDataUri() is string dataUri)
{
collectionItems.Add(new ImageContent(dataUri));
}
else
{
throw new InvalidOperationException("ImageMessage must have Url or DataUri");
}

return [new ChatMessageContent(AuthorRole.User, collectionItems)];
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<PackageId>AutoGen.Core</PackageId>
<PackageProjectUrl>https://github.com/microsoft/agnext</PackageProjectUrl>
<Authors>Microsoft</Authors>
<Description>AutoGenn Core Library</Description>
</PropertyGroup>

<Import Project="$(RepoRoot)/nuget/nuget-package.props" />

<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" />
Expand Down
3 changes: 2 additions & 1 deletion dotnet/src/Microsoft.AutoGen/Agents/App.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public static class AgentsApp
{
// need a variable to store the runtime instance
public static WebApplication? Host { get; private set; }

[MemberNotNull(nameof(Host))]
public static async ValueTask<WebApplication> StartAsync(WebApplicationBuilder? builder = null, AgentTypes? agentTypes = null, bool local = false)
{
Expand Down Expand Up @@ -58,7 +59,7 @@ public static async ValueTask ShutdownAsync()
await Host.StopAsync();
}

private static AgentApplicationBuilder AddAgents(this AgentApplicationBuilder builder, AgentTypes? agentTypes)
private static IHostApplicationBuilder AddAgents(this IHostApplicationBuilder builder, AgentTypes? agentTypes)
{
agentTypes ??= AgentTypes.GetAgentTypesFromAssembly()
?? throw new InvalidOperationException("No agent types found in the assembly");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<PackageId>Microsoft.AutoGen.Agents</PackageId>
<PackageProjectUrl>https://github.com/microsoft/autogen</PackageProjectUrl>
<Authors>Microsoft</Authors>
<Description>Micrososft AutoGen Agents SDK</Description>
<Tags>ai-agents;event-driven-agents</Tags>
</PropertyGroup>

<Import Project="$(RepoRoot)/nuget/nuget-package.props" />


<ItemGroup>
<ProjectReference Include="..\Abstractions\Microsoft.AutoGen.Abstractions.csproj" />
<ProjectReference Include="..\Extensions\ServiceDefaults\Microsoft.AutoGen.ServiceDefaults.csproj" />
<ProjectReference Include="..\Extensions\Aspire\Microsoft.AutoGen.Extensions.Aspire.csproj" />
</ItemGroup>

<ItemGroup>
Expand Down
Loading

0 comments on commit f8b43de

Please sign in to comment.