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

rysweet-adopt .NET Microsoft.Extensions.AI abstractions #3790

Merged
merged 66 commits into from
Oct 23, 2024
Merged
Show file tree
Hide file tree
Changes from 51 commits
Commits
Show all changes
66 commits
Select commit Hold shift + click to select a range
80c7a9f
rename the old AIAgent to skaiagent
rysweet Oct 14, 2024
0df244c
stashing wip
rysweet Oct 15, 2024
f43b581
Merge branch 'main' into rysweet-dotnet-ai-ext-abstractions
rysweet Oct 16, 2024
dc51387
rebasing branch
rysweet Oct 16, 2024
de59416
rebasing
rysweet Oct 16, 2024
69afaab
fix paths and rename proj files
rysweet Oct 16, 2024
f30152c
fixing paths
rysweet Oct 16, 2024
f517ae1
fix hello
rysweet Oct 16, 2024
e3f386e
it all builds! - fixes devteam
rysweet Oct 16, 2024
8c99b50
run gen-proto
rysweet Oct 16, 2024
c184fb6
rebasing
rysweet Oct 14, 2024
d3af26d
trying to catch up to main
rysweet Oct 17, 2024
c00c53d
fixing up the build
rysweet Oct 17, 2024
361766f
adding Microsoft.Extensions.AI and removing net6
rysweet Oct 17, 2024
06d3164
not quite there yet but making progress.
rysweet Oct 17, 2024
075874c
improving the App host
rysweet Oct 18, 2024
135018c
incorporated fixes for App.cs to clean up shutdown
rysweet Oct 18, 2024
548cb1d
Merge branch 'main' into rysweet-dotnet-ai-ext-abstractions
rysweet Oct 18, 2024
7d668ff
add back the shutdown
rysweet Oct 18, 2024
15edb15
Merge branch 'main' into rysweet-dotnet-ai-ext-abstractions
rysweet Oct 18, 2024
109ccc4
starting to structure the HelloAIAgents
rysweet Oct 21, 2024
b3a89f6
it builds!
rysweet Oct 22, 2024
dba4df8
model types
rysweet Oct 22, 2024
71d1e16
fixing breakages
rysweet Oct 22, 2024
53cf398
update azure identity
rysweet Oct 22, 2024
0ac6bd3
System.InvalidOperationException: Unable to resolve service for type …
rysweet Oct 22, 2024
0e21fb5
update example configuration
rysweet Oct 22, 2024
e6e34bf
format
rysweet Oct 22, 2024
19b2b41
s
rysweet Oct 22, 2024
e9a2441
Merge branch 'main' into rysweet-dotnet-ai-ext-abstractions
rysweet Oct 22, 2024
f2e05e6
missing ref
rysweet Oct 22, 2024
96752b8
make the fiy config more obvious
rysweet Oct 22, 2024
03f2563
don't throw away builder
rysweet Oct 22, 2024
9a7c77b
no really
rysweet Oct 22, 2024
8c61da8
accept a list of agents...
rysweet Oct 22, 2024
7357f4c
stash
rysweet Oct 22, 2024
2609f34
send agenttypes
rysweet Oct 22, 2024
caedeba
Merge branch 'main' into rysweet-dotnet-ai-ext-abstractions
rysweet Oct 22, 2024
ee44e90
Merge branch 'main' into rysweet-dotnet-ai-ext-abstractions
rysweet Oct 22, 2024
6521902
was adding the agent twice. fixed
rysweet Oct 22, 2024
6717b17
shrink delay
rysweet Oct 22, 2024
50b457b
stashing an attempt to aspirify things. might roll this back
rysweet Oct 22, 2024
bef820b
Merge branch 'main' into rysweet-dotnet-ai-ext-abstractions
rysweet Oct 23, 2024
2624f2d
add basic aspire project and docs for HelloAgent because for now I ca…
rysweet Oct 23, 2024
0a6cb3d
markdown lint
rysweet Oct 23, 2024
464dce4
format
rysweet Oct 23, 2024
e00fb6f
lets get the dir correct
rysweet Oct 23, 2024
c5650d5
Merge branch 'main' into rysweet-dotnet-ai-ext-abstractions
rysweet Oct 23, 2024
a596582
couple of missing items
rysweet Oct 23, 2024
9f85ced
Merge branch 'main' into rysweet-dotnet-ai-ext-abstractions
rysweet Oct 23, 2024
ca5f12e
Merge branch 'main' into rysweet-dotnet-ai-ext-abstractions
rysweet Oct 23, 2024
839b7c0
update agent class name.
rysweet Oct 23, 2024
bae64ba
whoops - revert
rysweet Oct 23, 2024
49095d4
remove unnecessary composition.
rysweet Oct 23, 2024
a86404f
fix coment
rysweet Oct 23, 2024
a3a045c
removed vestigal func/members
rysweet Oct 23, 2024
2ea208e
remove unintended comment
rysweet Oct 23, 2024
530d288
typo
rysweet Oct 23, 2024
1458cad
Merge branch 'main' into rysweet-dotnet-ai-ext-abstractions
rysweet Oct 23, 2024
d15f79c
matching the prior fix....
rysweet Oct 23, 2024
87e5db2
Merge branch 'main' into rysweet-dotnet-ai-ext-abstractions
rysweet Oct 23, 2024
f82ada7
MEAI build version props
rysweet Oct 23, 2024
6dd32e9
missing configure await.
rysweet Oct 23, 2024
029bd67
update aspire and remove some deps that arent needed.
rysweet Oct 23, 2024
311c51d
remove commented out
rysweet Oct 23, 2024
81972dc
Merge branch 'main' into rysweet-dotnet-ai-ext-abstractions
rysweet Oct 23, 2024
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
224 changes: 125 additions & 99 deletions dotnet/AutoGen.sln

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dotnet/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<Import Project="./eng/MetaInfo.props" />
<Import Project="./eng/Sign.props" />
<PropertyGroup>
<PackageTargetFrameworks>netstandard2.0;net6.0;net8.0</PackageTargetFrameworks>
<PackageTargetFrameworks>netstandard2.0;net8.0</PackageTargetFrameworks>
<TestTargetFrameworks>net8.0</TestTargetFrameworks>
<LangVersion>preview</LangVersion>
<Nullable>enable</Nullable>
Expand Down
9 changes: 7 additions & 2 deletions dotnet/Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,12 @@
<PackageVersion Include="Microsoft.AspNetCore.App" Version="8.0.4" />
<PackageVersion Include="Microsoft.AspNetCore.OpenApi" Version="8.0.8" />
<PackageVersion Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.22.0" />
<PackageVersion Include="Microsoft.Bcl.AsyncInterfaces" Version="8.0.0" />
<PackageVersion Include="Microsoft.Bcl.AsyncInterfaces" Version="9.0.0-rc.2.24473.5" />
rysweet marked this conversation as resolved.
Show resolved Hide resolved
<PackageVersion Include="Microsoft.Extensions.AI" Version="9.0.0-preview.9.24507.7" />
<PackageVersion Include="Microsoft.Extensions.AI.Abstractions" Version="9.0.0-preview.9.24507.7" />
<PackageVersion Include="Microsoft.Extensions.AI.AzureAIInference" Version="9.0.0-preview.9.24507.7" />
<PackageVersion Include="Microsoft.Extensions.AI.Ollama" Version="9.0.0-preview.9.24507.7" />
<PackageVersion Include="Microsoft.Extensions.AI.OpenAI" Version="9.0.0-preview.9.24507.7" />
<PackageVersion Include="Microsoft.Extensions.Azure" Version="1.7.6" />
<PackageVersion Include="Microsoft.Extensions.Caching.Abstractions" Version="8.0.0" />
<PackageVersion Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="8.0.0" />
Expand Down Expand Up @@ -104,6 +109,6 @@
<PackageVersion Include="Moq" Version="4.20.72" />
<PackageVersion Include="Microsoft.PowerShell.SDK" Version="7.4.5" />
<PackageVersion Include="Microsoft.AspNetCore.TestHost" Version="8.0.10" />
<PackageVersion Include="System.Text.Json" Version="8.0.5" />
<PackageVersion Include="System.Text.Json" Version="9.0.0-rc.2.24473.5" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -1,19 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">

<Project Sdk="Microsoft.NET.Sdk">
<ItemGroup>
<ProjectReference Include="..\..\src\Microsoft.AutoGen\Agents\Microsoft.AutoGen.Agents.csproj" />
<ProjectReference Include="..\..\src\Microsoft.AutoGen\Runtime\Microsoft.AutoGen.Runtime.csproj" />
<ProjectReference Include="..\..\..\src\Microsoft.AutoGen\Runtime\Microsoft.AutoGen.Runtime.csproj" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Hosting" />
</ItemGroup>

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

</Project>
5 changes: 5 additions & 0 deletions dotnet/samples/Hello/Backend/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// Copyright (c) Microsoft. All rights reserved.
using Microsoft.Extensions.Hosting;

var app = await Microsoft.AutoGen.Runtime.Host.StartAsync(local: true);
await app.WaitForShutdownAsync();
12 changes: 12 additions & 0 deletions dotnet/samples/Hello/Backend/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Backend Example

This example demonstrates how to create a simple backend service for the agent runtime using ASP.NET Core.

To Run it, simply run the following command in the terminal:

```bash
dotnet run
```

Or you can run it using Visual Studio Code by pressing `F5`.

20 changes: 20 additions & 0 deletions dotnet/samples/Hello/Hello.AppHost/Hello.AppHost.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<IsAspireHost>true</IsAspireHost>
<UserSecretsId>ecb5cbe4-15d8-4120-8f18-d3ba4902915b</UserSecretsId>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Aspire.Hosting.AppHost"/>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Backend\Backend.csproj" />
<ProjectReference Include="..\HelloAgent\HelloAgent.csproj" />
</ItemGroup>

</Project>
6 changes: 6 additions & 0 deletions dotnet/samples/Hello/Hello.AppHost/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// Copyright (c) Microsoft. All rights reserved.

var builder = DistributedApplication.CreateBuilder(args);
builder.AddProject<Projects.Backend>("backend");
builder.AddProject<Projects.HelloAgent>("client");
builder.Build().Run();
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
}
}
34 changes: 34 additions & 0 deletions dotnet/samples/Hello/HelloAIAgents/HelloAIAgent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using Microsoft.AutoGen.Abstractions;
using Microsoft.AutoGen.Agents;
using Microsoft.Extensions.AI;
using Microsoft.Extensions.DependencyInjection;

namespace Hello;
[TopicSubscription("HelloAgents")]
public class HelloAIAgent(
rysweet marked this conversation as resolved.
Show resolved Hide resolved
IAgentContext context,
[FromKeyedServices("EventTypes")] EventTypes typeRegistry,
IChatClient client) : HelloAgent(
context,
typeRegistry),
ISayHello,
rysweet marked this conversation as resolved.
Show resolved Hide resolved
IHandle<NewMessageReceived>
{
// This Handle supercedes the one in the base class
public new async Task Handle(NewMessageReceived item)
{
var prompt = "Please write a limerick greeting someone with the name " + item.Message;
var response = await client.CompleteAsync(prompt);
var evt = new Output
{
Message = response.Message.Text
}.ToCloudEvent(this.AgentId.Key);
await PublishEvent(evt).ConfigureAwait(false);
var goodbye = new ConversationClosed
{
UserId = this.AgentId.Key,
UserMessage = "Goodbye"
}.ToCloudEvent(this.AgentId.Key);
await PublishEvent(goodbye).ConfigureAwait(false);
}
}
21 changes: 21 additions & 0 deletions dotnet/samples/Hello/HelloAIAgents/HelloAIAgents.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<Project Sdk="Microsoft.NET.Sdk">

<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\Runtime\Microsoft.AutoGen.Runtime.csproj" />
<ProjectReference Include="..\..\..\src\Microsoft.AutoGen\Extensions\AIModelClientHostingExtensions\AIModelClientHostingExtensions.csproj" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Hosting" />
</ItemGroup>

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

</Project>
80 changes: 80 additions & 0 deletions dotnet/samples/Hello/HelloAIAgents/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
using Hello;
using Microsoft.AutoGen.Abstractions;
using Microsoft.AutoGen.Agents;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;

// send a message to the agent
var builder = AgentsApp.CreateBuilder();
// put these in your environment or appsettings.json
builder.Configuration["HelloAIAgents:ModelType"] = "azureopenai";
builder.Configuration["HelloAIAgents:LlmModelName"] = "gpt-3.5-turbo";
Environment.SetEnvironmentVariable("AZURE_OPENAI_CONNECTION_STRING", "Endpoint=https://TODO.openai.azure.com/;Key=TODO;Deployment=TODO");
if (Environment.GetEnvironmentVariable("AZURE_OPENAI_CONNECTION_STRING") == null)
{
throw new InvalidOperationException("AZURE_OPENAI_CONNECTION_STRING not set, try something like AZURE_OPENAI_CONNECTION_STRING = \"Endpoint=https://TODO.openai.azure.com/;Key=TODO;Deployment=TODO\"");
}
builder.Configuration["ConectionStrings:HelloAIAgents"] = Environment.GetEnvironmentVariable("AZURE_OPENAI_CONNECTION_STRING");
builder.AddChatCompletionService("HelloAIAgents");
var agentTypes = new AgentTypes(new Dictionary<string, Type>
{
{ "HelloAIAgents", typeof(HelloAIAgent) }
});
var app = await AgentsApp.PublishMessageAsync("HelloAgents", new NewMessageReceived
{
Message = "World"
}, builder, agentTypes, local: true);

await app.WaitForShutdownAsync();

namespace Hello
{
[TopicSubscription("HelloAgents")]
public class HelloAgent(
IAgentContext context,
[FromKeyedServices("EventTypes")] EventTypes typeRegistry) : ConsoleAgent(
context,
typeRegistry),
ISayHello,
IHandle<NewMessageReceived>,
IHandle<ConversationClosed>
{
public async Task Handle(NewMessageReceived item)
{
var response = await SayHello(item.Message).ConfigureAwait(false);
var evt = new Output
{
Message = response
}.ToCloudEvent(this.AgentId.Key);
await PublishEvent(evt).ConfigureAwait(false);
var goodbye = new ConversationClosed
{
UserId = this.AgentId.Key,
UserMessage = "Goodbye"
}.ToCloudEvent(this.AgentId.Key);
await PublishEvent(goodbye).ConfigureAwait(false);
}
public async Task Handle(ConversationClosed item)
{
var goodbye = $"********************* {item.UserId} said {item.UserMessage} ************************";
var evt = new Output
{
Message = goodbye
}.ToCloudEvent(this.AgentId.Key);
await PublishEvent(evt).ConfigureAwait(false);
//sleep30 seconds
await Task.Delay(30000).ConfigureAwait(false);
await AgentsApp.ShutdownAsync().ConfigureAwait(false);

}
public async Task<string> SayHello(string ask)
{
var response = $"\n\n\n\n***************Hello {ask}**********************\n\n\n\n";
return response;
}
}
public interface ISayHello
{
public Task<string> SayHello(string ask);
}
}
21 changes: 21 additions & 0 deletions dotnet/samples/Hello/HelloAgent/HelloAgent.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<Project Sdk="Microsoft.NET.Sdk">

<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\Runtime\Microsoft.AutoGen.Runtime.csproj" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Hosting" />
<PackageReference Include="Aspire.Hosting.AppHost" />
</ItemGroup>

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
// Copyright (c) Microsoft. All rights reserved.

using Microsoft.AutoGen.Abstractions;
using Microsoft.AutoGen.Agents;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;

// send a message to the agent
var app = await App.PublishMessageAsync("HelloAgents", new NewMessageReceived
var app = await AgentsApp.PublishMessageAsync("HelloAgents", new NewMessageReceived
{
Message = "World"
}, local: true);
}, local: false);

await App.RuntimeApp!.WaitForShutdownAsync();
await app.WaitForShutdownAsync();

namespace Hello
Expand Down Expand Up @@ -47,7 +48,10 @@ public async Task Handle(ConversationClosed item)
Message = goodbye
}.ToCloudEvent(this.AgentId.Key);
await PublishEvent(evt).ConfigureAwait(false);
await App.ShutdownAsync();
//sleep30 seconds
rysweet marked this conversation as resolved.
Show resolved Hide resolved
await Task.Delay(10000).ConfigureAwait(false);
await AgentsApp.ShutdownAsync().ConfigureAwait(false);

}
public async Task<string> SayHello(string ask)
{
Expand Down
Loading
Loading