-
Notifications
You must be signed in to change notification settings - Fork 5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/staging' into selector-groupchat
- Loading branch information
Showing
25 changed files
with
344 additions
and
138 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
using Google.Protobuf; | ||
using Microsoft.AspNetCore.Builder; | ||
using Microsoft.Extensions.DependencyInjection; | ||
|
||
namespace Microsoft.AutoGen.Agents.Client; | ||
|
||
public static class App | ||
{ | ||
// need a variable to store the runtime instance | ||
public static WebApplication? RuntimeApp { get; set; } | ||
public static WebApplication? ClientApp { get; set; } | ||
public static async ValueTask<WebApplication> StartAsync(AgentTypes? agentTypes = null, bool local = false) | ||
{ | ||
// start the server runtime | ||
RuntimeApp ??= await Runtime.Host.StartAsync(local); | ||
var clientBuilder = WebApplication.CreateBuilder(); | ||
var appBuilder = clientBuilder.AddAgentWorker(); | ||
agentTypes ??= AgentTypes.GetAgentTypesFromAssembly() | ||
?? throw new InvalidOperationException("No agent types found in the assembly"); | ||
foreach (var type in agentTypes.Types) | ||
{ | ||
appBuilder.AddAgent(type.Key, type.Value); | ||
} | ||
ClientApp = clientBuilder.Build(); | ||
await ClientApp.StartAsync().ConfigureAwait(false); | ||
return ClientApp; | ||
} | ||
|
||
public static async ValueTask<WebApplication> PublishMessageAsync( | ||
string topic, | ||
IMessage message, | ||
AgentTypes? agentTypes = null, | ||
bool local = false) | ||
{ | ||
if (ClientApp == null) | ||
{ | ||
ClientApp = await App.StartAsync(agentTypes, local); | ||
} | ||
var client = ClientApp.Services.GetRequiredService<AgentClient>() ?? throw new InvalidOperationException("Client not started"); | ||
await client.PublishEventAsync(topic, message).ConfigureAwait(false); | ||
return ClientApp; | ||
} | ||
|
||
public static async ValueTask ShutdownAsync() | ||
{ | ||
if (ClientApp == null) | ||
{ | ||
throw new InvalidOperationException("Client not started"); | ||
} | ||
await RuntimeApp!.StopAsync(); | ||
await ClientApp.StopAsync(); | ||
} | ||
} |
Oops, something went wrong.