diff --git a/README.md b/README.md
index a472e10a1b..7150942717 100644
--- a/README.md
+++ b/README.md
@@ -195,13 +195,13 @@ public class HelloAgent(
{
Message = response
}.ToCloudEvent(this.AgentId.Key);
- await PublishEvent(evt).ConfigureAwait(false);
+ await PublishEventAsync(evt).ConfigureAwait(false);
var goodbye = new ConversationClosed
{
UserId = this.AgentId.Key,
UserMessage = "Goodbye"
}.ToCloudEvent(this.AgentId.Key);
- await PublishEvent(goodbye).ConfigureAwait(false);
+ await PublishEventAsync(goodbye).ConfigureAwait(false);
}
public async Task Handle(ConversationClosed item)
{
@@ -210,7 +210,7 @@ public class HelloAgent(
{
Message = goodbye
}.ToCloudEvent(this.AgentId.Key);
- await PublishEvent(evt).ConfigureAwait(false);
+ await PublishEventAsync(evt).ConfigureAwait(false);
await Task.Delay(60000);
await App.ShutdownAsync();
}
diff --git a/docs/design/03 - worker-protocol.md b/docs/design/03 - Agent Worker Protocol.md
similarity index 100%
rename from docs/design/03 - worker-protocol.md
rename to docs/design/03 - Agent Worker Protocol.md
diff --git a/docs/design/05 - Services.md b/docs/design/05 - Services.md
new file mode 100644
index 0000000000..9aeacdb626
--- /dev/null
+++ b/docs/design/05 - Services.md
@@ -0,0 +1,26 @@
+# AutoGen Services
+
+## Overview
+
+Each AutoGen agent system has one or more Agent Workers and a set of services for managing/supporting the agents. The services and workers can all be hosted in the same process or in a distributed system. When in the same process communication and event delivery is in-memory. When distributed, workers communicate with the service over gRPC. In all cases, events are packaged as CloudEvents. There are multiple options for the backend services:
+
+- In-Memory: the Agent Workers and Services are all hosted in the same process and communicate over in-memory channels. Available for python and .NET.
+- Python only: Agent workers communicate with a python hosted service that implements an in-memory message bus and agent registry.
+- Micrososft Orleans: a distributed actor system that can host the services and workers, enables distributed state with persistent storage, can leverage multiple event bus types, and cross-language agent communication.
+- *Roadmap: support for other languages distributed systems such as dapr or Akka.*
+
+The Services in the system include:
+
+- Worker: Hosts the Agents and is a client to the Gateway
+- Gateway:
+-- RPC gateway for the other services APIs
+-- Provides an RPC bridge between the workers and the Event Bus
+-- Message Session state (track message queues/delivery)
+- Registry: keeps track of the {agents:agent types}:{Subscription/Topics} in the system and which events they can handle
+-- *Roadmap: add lookup api in gateway*
+- AgentState: persistent state for agents
+- Routing: delivers events to agents based on their subscriptions+topics
+-- *Roadmap: add subscription management APIs*
+- *Roadmap: Management APIs for the Agent System*
+- *Roadmap: Scheduling: manages placement of agents*
+- *Roadmap: Discovery: allows discovery of agents and services*
diff --git a/dotnet/AutoGen.sln b/dotnet/AutoGen.sln
index 8557f17840..accf92218a 100644
--- a/dotnet/AutoGen.sln
+++ b/dotnet/AutoGen.sln
@@ -84,10 +84,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.AutoGen.Abstracti
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.AutoGen.Extensions.SemanticKernel", "src\Microsoft.AutoGen\Extensions\SemanticKernel\Microsoft.AutoGen.Extensions.SemanticKernel.csproj", "{952827D4-8D4C-4327-AE4D-E8D25811EF35}"
EndProject
-Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.AutoGen.Runtime", "src\Microsoft.AutoGen\Runtime\Microsoft.AutoGen.Runtime.csproj", "{A905E29A-7110-497F-ADC5-2CE2A148FEA0}"
-EndProject
-Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.AutoGen.ServiceDefaults", "src\Microsoft.AutoGen\ServiceDefaults\Microsoft.AutoGen.ServiceDefaults.csproj", "{D7E9D90B-5595-4E72-A90A-6DE20D9AB7AE}"
-EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "AgentChat", "AgentChat", "{668726B9-77BC-45CF-B576-0F0773BF1615}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AutoGen.Anthropic.Samples", "samples\AutoGen.Anthropic.Samples\AutoGen.Anthropic.Samples.csproj", "{84020C4A-933A-4693-9889-1B99304A7D76}"
@@ -128,12 +124,14 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HelloAgent", "samples\Hello
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AIModelClientHostingExtensions", "src\Microsoft.AutoGen\Extensions\AIModelClientHostingExtensions\AIModelClientHostingExtensions.csproj", "{97550E87-48C6-4EBF-85E1-413ABAE9DBFD}"
EndProject
-Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.AutoGen.Agents.Tests", "Microsoft.AutoGen.Agents.Tests\Microsoft.AutoGen.Agents.Tests.csproj", "{CF4C92BD-28AE-4B8F-B173-601004AEC9BF}"
-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}"
+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}"
+EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@@ -264,14 +262,6 @@ Global
{952827D4-8D4C-4327-AE4D-E8D25811EF35}.Debug|Any CPU.Build.0 = Debug|Any CPU
{952827D4-8D4C-4327-AE4D-E8D25811EF35}.Release|Any CPU.ActiveCfg = Release|Any CPU
{952827D4-8D4C-4327-AE4D-E8D25811EF35}.Release|Any CPU.Build.0 = Release|Any CPU
- {A905E29A-7110-497F-ADC5-2CE2A148FEA0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
- {A905E29A-7110-497F-ADC5-2CE2A148FEA0}.Debug|Any CPU.Build.0 = Debug|Any CPU
- {A905E29A-7110-497F-ADC5-2CE2A148FEA0}.Release|Any CPU.ActiveCfg = Release|Any CPU
- {A905E29A-7110-497F-ADC5-2CE2A148FEA0}.Release|Any CPU.Build.0 = Release|Any CPU
- {D7E9D90B-5595-4E72-A90A-6DE20D9AB7AE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
- {D7E9D90B-5595-4E72-A90A-6DE20D9AB7AE}.Debug|Any CPU.Build.0 = Debug|Any CPU
- {D7E9D90B-5595-4E72-A90A-6DE20D9AB7AE}.Release|Any CPU.ActiveCfg = Release|Any CPU
- {D7E9D90B-5595-4E72-A90A-6DE20D9AB7AE}.Release|Any CPU.Build.0 = Release|Any CPU
{84020C4A-933A-4693-9889-1B99304A7D76}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{84020C4A-933A-4693-9889-1B99304A7D76}.Debug|Any CPU.Build.0 = Debug|Any CPU
{84020C4A-933A-4693-9889-1B99304A7D76}.Release|Any CPU.ActiveCfg = Release|Any CPU
@@ -340,14 +330,18 @@ Global
{97550E87-48C6-4EBF-85E1-413ABAE9DBFD}.Debug|Any CPU.Build.0 = Debug|Any CPU
{97550E87-48C6-4EBF-85E1-413ABAE9DBFD}.Release|Any CPU.ActiveCfg = Release|Any CPU
{97550E87-48C6-4EBF-85E1-413ABAE9DBFD}.Release|Any CPU.Build.0 = Release|Any CPU
- {CF4C92BD-28AE-4B8F-B173-601004AEC9BF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
- {CF4C92BD-28AE-4B8F-B173-601004AEC9BF}.Debug|Any CPU.Build.0 = Debug|Any CPU
- {CF4C92BD-28AE-4B8F-B173-601004AEC9BF}.Release|Any CPU.ActiveCfg = Release|Any CPU
- {CF4C92BD-28AE-4B8F-B173-601004AEC9BF}.Release|Any CPU.Build.0 = Release|Any CPU
{64EF61E7-00A6-4E5E-9808-62E10993A0E5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{64EF61E7-00A6-4E5E-9808-62E10993A0E5}.Debug|Any CPU.Build.0 = Debug|Any CPU
{64EF61E7-00A6-4E5E-9808-62E10993A0E5}.Release|Any CPU.ActiveCfg = Release|Any CPU
{64EF61E7-00A6-4E5E-9808-62E10993A0E5}.Release|Any CPU.Build.0 = Release|Any CPU
+ {65059914-5527-4A00-9308-9FAF23D5E85A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {65059914-5527-4A00-9308-9FAF23D5E85A}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {65059914-5527-4A00-9308-9FAF23D5E85A}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {65059914-5527-4A00-9308-9FAF23D5E85A}.Release|Any CPU.Build.0 = Release|Any CPU
+ {394FDAF8-74F9-4977-94A5-3371737EB774}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {394FDAF8-74F9-4977-94A5-3371737EB774}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {394FDAF8-74F9-4977-94A5-3371737EB774}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {394FDAF8-74F9-4977-94A5-3371737EB774}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@@ -385,8 +379,6 @@ Global
{FD87BD33-4616-460B-AC85-A412BA08BB78} = {18BF8DD7-0585-48BF-8F97-AD333080CE06}
{E0C991D9-0DB8-471C-ADC9-5FB16E2A0106} = {18BF8DD7-0585-48BF-8F97-AD333080CE06}
{952827D4-8D4C-4327-AE4D-E8D25811EF35} = {18BF8DD7-0585-48BF-8F97-AD333080CE06}
- {A905E29A-7110-497F-ADC5-2CE2A148FEA0} = {18BF8DD7-0585-48BF-8F97-AD333080CE06}
- {D7E9D90B-5595-4E72-A90A-6DE20D9AB7AE} = {18BF8DD7-0585-48BF-8F97-AD333080CE06}
{668726B9-77BC-45CF-B576-0F0773BF1615} = {686480D7-8FEC-4ED3-9C5D-CEBE1057A7ED}
{84020C4A-933A-4693-9889-1B99304A7D76} = {668726B9-77BC-45CF-B576-0F0773BF1615}
{5777515F-4053-42F9-AF2B-95D8D0F5384A} = {668726B9-77BC-45CF-B576-0F0773BF1615}
@@ -407,8 +399,9 @@ Global
{A20B9894-F352-4338-872A-F215A241D43D} = {7EB336C2-7C0A-4BC8-80C6-A3173AB8DC45}
{8F7560CF-EEBB-4333-A69F-838CA40FD85D} = {7EB336C2-7C0A-4BC8-80C6-A3173AB8DC45}
{97550E87-48C6-4EBF-85E1-413ABAE9DBFD} = {18BF8DD7-0585-48BF-8F97-AD333080CE06}
- {CF4C92BD-28AE-4B8F-B173-601004AEC9BF} = {F823671B-3ECA-4AE6-86DA-25E920D3FE64}
{64EF61E7-00A6-4E5E-9808-62E10993A0E5} = {7EB336C2-7C0A-4BC8-80C6-A3173AB8DC45}
+ {65059914-5527-4A00-9308-9FAF23D5E85A} = {18BF8DD7-0585-48BF-8F97-AD333080CE06}
+ {394FDAF8-74F9-4977-94A5-3371737EB774} = {F823671B-3ECA-4AE6-86DA-25E920D3FE64}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {93384647-528D-46C8-922C-8DB36A382F0B}
diff --git a/dotnet/Directory.Packages.props b/dotnet/Directory.Packages.props
index a414a5f59d..c1b26f2f9b 100644
--- a/dotnet/Directory.Packages.props
+++ b/dotnet/Directory.Packages.props
@@ -63,11 +63,17 @@
+
+ runtime; build; native; contentfiles; analyzers; buildtransitive
+ all
+
+
+
diff --git a/dotnet/samples/Hello/Backend/Backend.csproj b/dotnet/samples/Hello/Backend/Backend.csproj
index 2f5a02ee51..d502d7260d 100644
--- a/dotnet/samples/Hello/Backend/Backend.csproj
+++ b/dotnet/samples/Hello/Backend/Backend.csproj
@@ -1,4 +1,7 @@
-
+
+
+
+
Exe
net8.0
@@ -6,10 +9,6 @@
enable
-
-
-
-
diff --git a/dotnet/samples/Hello/Backend/Program.cs b/dotnet/samples/Hello/Backend/Program.cs
index 7abdb205a8..b913d39d64 100644
--- a/dotnet/samples/Hello/Backend/Program.cs
+++ b/dotnet/samples/Hello/Backend/Program.cs
@@ -1,5 +1,7 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Program.cs
-var app = await Microsoft.AutoGen.Runtime.Host.StartAsync(local: true);
+using Microsoft.Extensions.Hosting;
+
+var app = await Microsoft.AutoGen.Agents.Host.StartAsync(local: false, useGrpc: true);
await app.WaitForShutdownAsync();
diff --git a/dotnet/samples/Hello/Backend/appsettings.json b/dotnet/samples/Hello/Backend/appsettings.json
new file mode 100644
index 0000000000..3bb8d88255
--- /dev/null
+++ b/dotnet/samples/Hello/Backend/appsettings.json
@@ -0,0 +1,9 @@
+{
+ "Logging": {
+ "LogLevel": {
+ "Default": "Warning",
+ "Microsoft": "Warning",
+ "Microsoft.Orleans": "Warning"
+ }
+ }
+ }
\ No newline at end of file
diff --git a/dotnet/samples/Hello/HelloAIAgents/HelloAIAgent.cs b/dotnet/samples/Hello/HelloAIAgents/HelloAIAgent.cs
index fd3c517f33..d2ba81e659 100644
--- a/dotnet/samples/Hello/HelloAIAgents/HelloAIAgent.cs
+++ b/dotnet/samples/Hello/HelloAIAgents/HelloAIAgent.cs
@@ -8,11 +8,13 @@ using Microsoft.Extensions.AI;
namespace Hello;
[TopicSubscription("HelloAgents")]
public class HelloAIAgent(
- IAgentContext context,
+ IAgentRuntime context,
[FromKeyedServices("EventTypes")] EventTypes typeRegistry,
+ IHostApplicationLifetime hostApplicationLifetime,
IChatClient client) : HelloAgent(
context,
- typeRegistry),
+ typeRegistry,
+ hostApplicationLifetime),
IHandle
{
// This Handle supercedes the one in the base class
diff --git a/dotnet/samples/Hello/HelloAIAgents/HelloAIAgents.csproj b/dotnet/samples/Hello/HelloAIAgents/HelloAIAgents.csproj
index 86bccb13b3..f17ab0c9f0 100644
--- a/dotnet/samples/Hello/HelloAIAgents/HelloAIAgents.csproj
+++ b/dotnet/samples/Hello/HelloAIAgents/HelloAIAgents.csproj
@@ -13,7 +13,6 @@
-
diff --git a/dotnet/samples/Hello/HelloAIAgents/Program.cs b/dotnet/samples/Hello/HelloAIAgents/Program.cs
index 8285e0800f..9612a0a079 100644
--- a/dotnet/samples/Hello/HelloAIAgents/Program.cs
+++ b/dotnet/samples/Hello/HelloAIAgents/Program.cs
@@ -32,8 +32,9 @@ namespace Hello
{
[TopicSubscription("HelloAgents")]
public class HelloAgent(
- IAgentContext context,
- [FromKeyedServices("EventTypes")] EventTypes typeRegistry) : ConsoleAgent(
+ IAgentRuntime context,
+ [FromKeyedServices("EventTypes")] EventTypes typeRegistry,
+ IHostApplicationLifetime hostApplicationLifetime) : ConsoleAgent(
context,
typeRegistry),
ISayHello,
@@ -65,7 +66,7 @@ namespace Hello
await PublishMessageAsync(evt).ConfigureAwait(false);
//sleep30 seconds
await Task.Delay(30000).ConfigureAwait(false);
- await AgentsApp.ShutdownAsync().ConfigureAwait(false);
+ hostApplicationLifetime.StopApplication();
}
public async Task SayHello(string ask)
diff --git a/dotnet/samples/Hello/HelloAIAgents/appsettings.json b/dotnet/samples/Hello/HelloAIAgents/appsettings.json
new file mode 100644
index 0000000000..3bb8d88255
--- /dev/null
+++ b/dotnet/samples/Hello/HelloAIAgents/appsettings.json
@@ -0,0 +1,9 @@
+{
+ "Logging": {
+ "LogLevel": {
+ "Default": "Warning",
+ "Microsoft": "Warning",
+ "Microsoft.Orleans": "Warning"
+ }
+ }
+ }
\ No newline at end of file
diff --git a/dotnet/samples/Hello/HelloAgent/HelloAgent.csproj b/dotnet/samples/Hello/HelloAgent/HelloAgent.csproj
index 8799eb7275..f2f3e473fe 100644
--- a/dotnet/samples/Hello/HelloAgent/HelloAgent.csproj
+++ b/dotnet/samples/Hello/HelloAgent/HelloAgent.csproj
@@ -1,4 +1,4 @@
-
+
Exe
net8.0
@@ -14,6 +14,5 @@
-
diff --git a/dotnet/samples/Hello/HelloAgent/Program.cs b/dotnet/samples/Hello/HelloAgent/Program.cs
index 4e96c7f99b..506d915023 100644
--- a/dotnet/samples/Hello/HelloAgent/Program.cs
+++ b/dotnet/samples/Hello/HelloAgent/Program.cs
@@ -3,6 +3,8 @@
using Microsoft.AutoGen.Abstractions;
using Microsoft.AutoGen.Agents;
+using Microsoft.Extensions.DependencyInjection;
+using Microsoft.Extensions.Hosting;
// step 1: create in-memory agent runtime
@@ -16,7 +18,7 @@ using Microsoft.AutoGen.Agents;
var app = await AgentsApp.PublishMessageAsync("HelloAgents", new NewMessageReceived
{
Message = "World"
-}, local: false);
+}, local: true);
await app.WaitForShutdownAsync();
@@ -24,9 +26,8 @@ namespace Hello
{
[TopicSubscription("HelloAgents")]
public class HelloAgent(
- IAgentContext context,
- [FromKeyedServices("EventTypes")] EventTypes typeRegistry,
- IHostApplicationLifetime hostApplicationLifetime) : AgentBase(
+ IAgentRuntime context, IHostApplicationLifetime hostApplicationLifetime,
+ [FromKeyedServices("EventTypes")] EventTypes typeRegistry) : AgentBase(
context,
typeRegistry),
ISayHello,
diff --git a/dotnet/samples/Hello/HelloAgent/README.md b/dotnet/samples/Hello/HelloAgent/README.md
index 2de64ebaa0..f95e25d6ec 100644
--- a/dotnet/samples/Hello/HelloAgent/README.md
+++ b/dotnet/samples/Hello/HelloAgent/README.md
@@ -25,11 +25,11 @@ Flow Diagram:
```mermaid
%%{init: {'theme':'forest'}}%%
graph LR;
- A[Main] --> |"PublishEvent(NewMessage('World'))"| B{"Handle(NewMessageReceived item)"}
- B --> |"PublishEvent(Output('***Hello, World***'))"| C[ConsoleAgent]
+ A[Main] --> |"PublishEventAsync(NewMessage('World'))"| B{"Handle(NewMessageReceived item)"}
+ B --> |"PublishEventAsync(Output('***Hello, World***'))"| C[ConsoleAgent]
C --> D{"WriteConsole()"}
- B --> |"PublishEvent(ConversationClosed('Goodbye'))"| E{"Handle(ConversationClosed item)"}
- B --> |"PublishEvent(Output('***Goodbye***'))"| C
+ B --> |"PublishEventAsync(ConversationClosed('Goodbye'))"| E{"Handle(ConversationClosed item)"}
+ B --> |"PublishEventAsync(Output('***Goodbye***'))"| C
E --> F{"Shutdown()"}
```
@@ -58,13 +58,13 @@ public class HelloAgent(
{
Message = response
}.ToCloudEvent(this.AgentId.Key);
- await PublishEvent(evt).ConfigureAwait(false);
+ await PublishEventAsync(evt).ConfigureAwait(false);
var goodbye = new ConversationClosed
{
UserId = this.AgentId.Key,
UserMessage = "Goodbye"
}.ToCloudEvent(this.AgentId.Key);
- await PublishEvent(goodbye).ConfigureAwait(false);
+ await PublishEventAsync(goodbye).ConfigureAwait(false);
}
```
@@ -109,7 +109,6 @@ message ReadmeRequested {
}
```
-
```xml
diff --git a/dotnet/samples/Hello/HelloAgent/appsettings.json b/dotnet/samples/Hello/HelloAgent/appsettings.json
new file mode 100644
index 0000000000..3bb8d88255
--- /dev/null
+++ b/dotnet/samples/Hello/HelloAgent/appsettings.json
@@ -0,0 +1,9 @@
+{
+ "Logging": {
+ "LogLevel": {
+ "Default": "Warning",
+ "Microsoft": "Warning",
+ "Microsoft.Orleans": "Warning"
+ }
+ }
+ }
\ No newline at end of file
diff --git a/dotnet/samples/Hello/HelloAgentState/HelloAgentState.csproj b/dotnet/samples/Hello/HelloAgentState/HelloAgentState.csproj
index 8799eb7275..797fe957bb 100644
--- a/dotnet/samples/Hello/HelloAgentState/HelloAgentState.csproj
+++ b/dotnet/samples/Hello/HelloAgentState/HelloAgentState.csproj
@@ -14,6 +14,5 @@
-
diff --git a/dotnet/samples/Hello/HelloAgentState/Program.cs b/dotnet/samples/Hello/HelloAgentState/Program.cs
index d021126850..7c15c4c54d 100644
--- a/dotnet/samples/Hello/HelloAgentState/Program.cs
+++ b/dotnet/samples/Hello/HelloAgentState/Program.cs
@@ -1,6 +1,7 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Program.cs
+using System.Text.Json;
using Microsoft.AutoGen.Abstractions;
using Microsoft.AutoGen.Agents;
@@ -8,7 +9,7 @@ using Microsoft.AutoGen.Agents;
var app = await AgentsApp.PublishMessageAsync("HelloAgents", new NewMessageReceived
{
Message = "World"
-}, local: false);
+}, local: true);
await app.WaitForShutdownAsync();
@@ -16,13 +17,15 @@ namespace Hello
{
[TopicSubscription("HelloAgents")]
public class HelloAgent(
- IAgentContext context,
- [FromKeyedServices("EventTypes")] EventTypes typeRegistry) : ConsoleAgent(
+ IAgentRuntime context,
+ IHostApplicationLifetime hostApplicationLifetime,
+ [FromKeyedServices("EventTypes")] EventTypes typeRegistry) : AgentBase(
context,
typeRegistry),
- ISayHello,
+ IHandleConsole,
IHandle,
- IHandle
+ IHandle,
+ IHandle
{
private AgentState? State { get; set; }
public async Task Handle(NewMessageReceived item)
@@ -32,11 +35,15 @@ namespace Hello
{
Message = response
};
- var entry = "We said hello to " + item.Message;
- await Store(new AgentState
+ Dictionary state = new()
+ {
+ { "data", "We said hello to " + item.Message },
+ { "workflow", "Active" }
+ };
+ await StoreAsync(new AgentState
{
AgentId = this.AgentId,
- TextData = entry
+ TextData = JsonSerializer.Serialize(state)
}).ConfigureAwait(false);
await PublishMessageAsync(evt).ConfigureAwait(false);
var goodbye = new ConversationClosed
@@ -45,21 +52,40 @@ namespace Hello
UserMessage = "Goodbye"
};
await PublishMessageAsync(goodbye).ConfigureAwait(false);
+ // send the shutdown message
+ await PublishMessageAsync(new Shutdown { Message = this.AgentId.Key }).ConfigureAwait(false);
+
}
public async Task Handle(ConversationClosed item)
{
- State = await Read(this.AgentId).ConfigureAwait(false);
- var read = State?.TextData ?? "No state data found";
- var goodbye = $"{read}\n********************* {item.UserId} said {item.UserMessage} ************************";
+ State = await ReadAsync(this.AgentId).ConfigureAwait(false);
+ var state = JsonSerializer.Deserialize>(State.TextData) ?? new Dictionary { { "data", "No state data found" } };
+ var goodbye = $"\nState: {state}\n********************* {item.UserId} said {item.UserMessage} ************************";
var evt = new Output
{
Message = goodbye
};
- await PublishMessageAsync(evt).ConfigureAwait(false);
- //sleep
- await Task.Delay(10000).ConfigureAwait(false);
- await AgentsApp.ShutdownAsync().ConfigureAwait(false);
-
+ await PublishMessageAsync(evt).ConfigureAwait(true);
+ state["workflow"] = "Complete";
+ await StoreAsync(new AgentState
+ {
+ AgentId = this.AgentId,
+ TextData = JsonSerializer.Serialize(state)
+ }).ConfigureAwait(false);
+ }
+ public async Task Handle(Shutdown item)
+ {
+ string? workflow = null;
+ // make sure the workflow is finished
+ while (workflow != "Complete")
+ {
+ State = await ReadAsync(this.AgentId).ConfigureAwait(true);
+ var state = JsonSerializer.Deserialize>(State?.TextData ?? "{}") ?? new Dictionary();
+ workflow = state["workflow"];
+ await Task.Delay(1000).ConfigureAwait(true);
+ }
+ // now we can shut down...
+ hostApplicationLifetime.StopApplication();
}
public async Task SayHello(string ask)
{
@@ -67,8 +93,4 @@ namespace Hello
return response;
}
}
- public interface ISayHello
- {
- public Task SayHello(string ask);
- }
}
diff --git a/dotnet/samples/Hello/HelloAgentState/README.md b/dotnet/samples/Hello/HelloAgentState/README.md
index 0079005d24..8bc8e34545 100644
--- a/dotnet/samples/Hello/HelloAgentState/README.md
+++ b/dotnet/samples/Hello/HelloAgentState/README.md
@@ -25,11 +25,11 @@ Flow Diagram:
```mermaid
%%{init: {'theme':'forest'}}%%
graph LR;
- A[Main] --> |"PublishEvent(NewMessage('World'))"| B{"Handle(NewMessageReceived item)"}
- B --> |"PublishEvent(Output('***Hello, World***'))"| C[ConsoleAgent]
+ A[Main] --> |"PublishEventAsync(NewMessage('World'))"| B{"Handle(NewMessageReceived item)"}
+ B --> |"PublishEventAsync(Output('***Hello, World***'))"| C[ConsoleAgent]
C --> D{"WriteConsole()"}
- B --> |"PublishEvent(ConversationClosed('Goodbye'))"| E{"Handle(ConversationClosed item)"}
- B --> |"PublishEvent(Output('***Goodbye***'))"| C
+ B --> |"PublishEventAsync(ConversationClosed('Goodbye'))"| E{"Handle(ConversationClosed item)"}
+ B --> |"PublishEventAsync(Output('***Goodbye***'))"| C
E --> F{"Shutdown()"}
```
@@ -58,13 +58,13 @@ public class HelloAgent(
{
Message = response
}.ToCloudEvent(this.AgentId.Key);
- await PublishEvent(evt).ConfigureAwait(false);
+ await PublishEventAsync(evt).ConfigureAwait(false);
var goodbye = new ConversationClosed
{
UserId = this.AgentId.Key,
UserMessage = "Goodbye"
}.ToCloudEvent(this.AgentId.Key);
- await PublishEvent(goodbye).ConfigureAwait(false);
+ await PublishEventAsync(goodbye).ConfigureAwait(false);
}
```
diff --git a/dotnet/samples/Hello/HelloAgentState/appsettings.json b/dotnet/samples/Hello/HelloAgentState/appsettings.json
new file mode 100644
index 0000000000..3bb8d88255
--- /dev/null
+++ b/dotnet/samples/Hello/HelloAgentState/appsettings.json
@@ -0,0 +1,9 @@
+{
+ "Logging": {
+ "LogLevel": {
+ "Default": "Warning",
+ "Microsoft": "Warning",
+ "Microsoft.Orleans": "Warning"
+ }
+ }
+ }
\ No newline at end of file
diff --git a/dotnet/samples/dev-team/DevTeam.AgentHost/DevTeam.AgentHost.csproj b/dotnet/samples/dev-team/DevTeam.AgentHost/DevTeam.AgentHost.csproj
index 69705e4667..d8d7ebf8e4 100644
--- a/dotnet/samples/dev-team/DevTeam.AgentHost/DevTeam.AgentHost.csproj
+++ b/dotnet/samples/dev-team/DevTeam.AgentHost/DevTeam.AgentHost.csproj
@@ -9,8 +9,8 @@
-
-
+
+
diff --git a/dotnet/samples/dev-team/DevTeam.AgentHost/Program.cs b/dotnet/samples/dev-team/DevTeam.AgentHost/Program.cs
index 4864f39421..6480e72a0b 100644
--- a/dotnet/samples/dev-team/DevTeam.AgentHost/Program.cs
+++ b/dotnet/samples/dev-team/DevTeam.AgentHost/Program.cs
@@ -1,7 +1,7 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Program.cs
-using Microsoft.AutoGen.Runtime;
+using Microsoft.AutoGen.Agents;
var builder = WebApplication.CreateBuilder(args);
builder.AddServiceDefaults();
diff --git a/dotnet/samples/dev-team/DevTeam.Agents/DevTeam.Agents.csproj b/dotnet/samples/dev-team/DevTeam.Agents/DevTeam.Agents.csproj
index 03176d2cfd..8dfd6912e5 100644
--- a/dotnet/samples/dev-team/DevTeam.Agents/DevTeam.Agents.csproj
+++ b/dotnet/samples/dev-team/DevTeam.Agents/DevTeam.Agents.csproj
@@ -9,8 +9,8 @@
-
-
+
+
diff --git a/dotnet/samples/dev-team/DevTeam.Agents/Developer/Developer.cs b/dotnet/samples/dev-team/DevTeam.Agents/Developer/Developer.cs
index 5b66822482..325b9fbe0b 100644
--- a/dotnet/samples/dev-team/DevTeam.Agents/Developer/Developer.cs
+++ b/dotnet/samples/dev-team/DevTeam.Agents/Developer/Developer.cs
@@ -10,7 +10,7 @@ using Microsoft.SemanticKernel.Memory;
namespace DevTeam.Agents;
[TopicSubscription("devteam")]
-public class Dev(IAgentContext context, Kernel kernel, ISemanticTextMemory memory, [FromKeyedServices("EventTypes")] EventTypes typeRegistry, ILogger logger)
+public class Dev(IAgentRuntime context, Kernel kernel, ISemanticTextMemory memory, [FromKeyedServices("EventTypes")] EventTypes typeRegistry, ILogger logger)
: SKAiAgent(context, memory, kernel, typeRegistry), IDevelopApps,
IHandle,
IHandle
diff --git a/dotnet/samples/dev-team/DevTeam.Agents/DeveloperLead/DeveloperLead.cs b/dotnet/samples/dev-team/DevTeam.Agents/DeveloperLead/DeveloperLead.cs
index 71301dd3d3..e03701c968 100644
--- a/dotnet/samples/dev-team/DevTeam.Agents/DeveloperLead/DeveloperLead.cs
+++ b/dotnet/samples/dev-team/DevTeam.Agents/DeveloperLead/DeveloperLead.cs
@@ -11,7 +11,7 @@ using Microsoft.SemanticKernel.Memory;
namespace DevTeam.Agents;
[TopicSubscription("devteam")]
-public class DeveloperLead(IAgentContext context, Kernel kernel, ISemanticTextMemory memory, [FromKeyedServices("EventTypes")] EventTypes typeRegistry, ILogger logger)
+public class DeveloperLead(IAgentRuntime context, Kernel kernel, ISemanticTextMemory memory, [FromKeyedServices("EventTypes")] EventTypes typeRegistry, ILogger logger)
: SKAiAgent(context, memory, kernel, typeRegistry), ILeadDevelopers,
IHandle,
IHandle
diff --git a/dotnet/samples/dev-team/DevTeam.Agents/ProductManager/ProductManager.cs b/dotnet/samples/dev-team/DevTeam.Agents/ProductManager/ProductManager.cs
index a97b333567..cc393e6518 100644
--- a/dotnet/samples/dev-team/DevTeam.Agents/ProductManager/ProductManager.cs
+++ b/dotnet/samples/dev-team/DevTeam.Agents/ProductManager/ProductManager.cs
@@ -10,7 +10,7 @@ using Microsoft.SemanticKernel.Memory;
namespace DevTeam.Agents;
[TopicSubscription("devteam")]
-public class ProductManager(IAgentContext context, Kernel kernel, ISemanticTextMemory memory, [FromKeyedServices("EventTypes")] EventTypes typeRegistry, ILogger logger)
+public class ProductManager(IAgentRuntime context, Kernel kernel, ISemanticTextMemory memory, [FromKeyedServices("EventTypes")] EventTypes typeRegistry, ILogger logger)
: SKAiAgent(context, memory, kernel, typeRegistry), IManageProducts,
IHandle,
IHandle
diff --git a/dotnet/samples/dev-team/DevTeam.Backend/Agents/AzureGenie.cs b/dotnet/samples/dev-team/DevTeam.Backend/Agents/AzureGenie.cs
index 7dac8163a7..d3997a8f8e 100644
--- a/dotnet/samples/dev-team/DevTeam.Backend/Agents/AzureGenie.cs
+++ b/dotnet/samples/dev-team/DevTeam.Backend/Agents/AzureGenie.cs
@@ -9,7 +9,7 @@ using Microsoft.SemanticKernel;
using Microsoft.SemanticKernel.Memory;
namespace Microsoft.AI.DevTeam;
-public class AzureGenie(IAgentContext context, Kernel kernel, ISemanticTextMemory memory, [FromKeyedServices("EventTypes")] EventTypes typeRegistry, IManageAzure azureService)
+public class AzureGenie(IAgentRuntime context, Kernel kernel, ISemanticTextMemory memory, [FromKeyedServices("EventTypes")] EventTypes typeRegistry, IManageAzure azureService)
: SKAiAgent