Skip to content

Commit 7b708fb

Browse files
committed
Merge branch 'main' into final_answer_prompt
2 parents c1bcef5 + 1c09de8 commit 7b708fb

File tree

27 files changed

+624
-74
lines changed

27 files changed

+624
-74
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ var app = await App.PublishMessageAsync("HelloAgents", new NewMessageReceived
181181
await App.RuntimeApp!.WaitForShutdownAsync();
182182
await app.WaitForShutdownAsync();
183183

184-
[TopicSubscription("HelloAgents")]
184+
[TopicSubscription("agents")]
185185
public class HelloAgent(
186186
IAgentContext context,
187187
[FromKeyedServices("EventTypes")] EventTypes typeRegistry) : ConsoleAgent(

dotnet/Directory.Packages.props

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
</PropertyGroup>
1515
<ItemGroup>
1616
<PackageVersion Include="Aspire.Hosting" Version="9.0.0" />
17+
<PackageVersion Include="Aspire.Hosting.Python" Version="9.0.0" />
1718
<PackageVersion Include="AspNetCore.Authentication.ApiKey" Version="8.0.1" />
1819
<PackageVersion Include="Aspire.Azure.AI.OpenAI" Version="8.0.1-preview.8.24267.1" />
1920
<PackageVersion Include="Aspire.Hosting.AppHost" Version="9.0.0" />

dotnet/samples/Hello/Hello.AppHost/Hello.AppHost.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
<ItemGroup>
1515
<PackageReference Include="Aspire.Hosting.AppHost" />
1616
<PackageReference Include="Aspire.Hosting" />
17+
<PackageReference Include="Aspire.Hosting.Python" />
1718
</ItemGroup>
1819

1920
<ItemGroup>

dotnet/samples/Hello/Hello.AppHost/Program.cs

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,23 @@
55

66
var builder = DistributedApplication.CreateBuilder(args);
77
var backend = builder.AddProject<Projects.Backend>("backend").WithExternalHttpEndpoints();
8-
builder.AddProject<Projects.HelloAgent>("client")
8+
var client = builder.AddProject<Projects.HelloAgent>("HelloAgentsDotNET")
99
.WithReference(backend)
10-
.WithEnvironment("AGENT_HOST", $"{backend.GetEndpoint("https").Property(EndpointProperty.Url)}")
10+
.WithEnvironment("AGENT_HOST", backend.GetEndpoint("https"))
11+
.WithEnvironment("STAY_ALIVE_ON_GOODBYE", "true")
1112
.WaitFor(backend);
12-
13+
#pragma warning disable ASPIREHOSTINGPYTHON001 // Type is for evaluation purposes only and is subject to change or removal in future updates. Suppress this diagnostic to proceed.
14+
// xlang is over http for now - in prod use TLS between containers
15+
builder.AddPythonApp("HelloAgentsPython", "../../../../python/packages/autogen-core/samples/xlang/hello_python_agent", "hello_python_agent.py", "../../../../../.venv")
16+
.WithReference(backend)
17+
.WithEnvironment("AGENT_HOST", backend.GetEndpoint("http"))
18+
.WithEnvironment("STAY_ALIVE_ON_GOODBYE", "true")
19+
.WithEnvironment("GRPC_DNS_RESOLVER", "native")
20+
.WithOtlpExporter()
21+
.WaitFor(client);
22+
#pragma warning restore ASPIREHOSTINGPYTHON001 // Type is for evaluation purposes only and is subject to change or removal in future updates. Suppress this diagnostic to proceed.
1323
using var app = builder.Build();
14-
1524
await app.StartAsync();
1625
var url = backend.GetEndpoint("http").Url;
1726
Console.WriteLine("Backend URL: " + url);
18-
1927
await app.WaitForShutdownAsync();

dotnet/samples/Hello/HelloAIAgents/HelloAIAgent.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
using Microsoft.Extensions.AI;
77

88
namespace Hello;
9-
[TopicSubscription("HelloAgents")]
9+
[TopicSubscription("agents")]
1010
public class HelloAIAgent(
1111
IAgentRuntime context,
1212
[FromKeyedServices("EventTypes")] EventTypes typeRegistry,

dotnet/samples/Hello/HelloAIAgents/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030

3131
namespace Hello
3232
{
33-
[TopicSubscription("HelloAgents")]
33+
[TopicSubscription("agents")]
3434
public class HelloAgent(
3535
IAgentRuntime context,
3636
[FromKeyedServices("EventTypes")] EventTypes typeRegistry,

dotnet/samples/Hello/HelloAgent/Program.cs

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,17 @@
66
using Microsoft.Extensions.DependencyInjection;
77
using Microsoft.Extensions.Hosting;
88

9-
// step 1: create in-memory agent runtime
10-
11-
// step 2: register HelloAgent to that agent runtime
12-
13-
// step 3: start the agent runtime
14-
15-
// step 4: send a message to the agent
16-
17-
// step 5: wait for the agent runtime to shutdown
9+
var local = true;
10+
if (Environment.GetEnvironmentVariable("AGENT_HOST") != null) { local = false; }
1811
var app = await AgentsApp.PublishMessageAsync("HelloAgents", new NewMessageReceived
1912
{
2013
Message = "World"
21-
}, local: true);
22-
//var app = await AgentsApp.StartAsync();
14+
}, local: local).ConfigureAwait(false);
2315
await app.WaitForShutdownAsync();
2416

2517
namespace Hello
2618
{
27-
[TopicSubscription("HelloAgents")]
19+
[TopicSubscription("agents")]
2820
public class HelloAgent(
2921
IAgentRuntime context, IHostApplicationLifetime hostApplicationLifetime,
3022
[FromKeyedServices("EventTypes")] EventTypes typeRegistry) : AgentBase(
@@ -53,7 +45,10 @@ public async Task Handle(ConversationClosed item)
5345
var goodbye = $"********************* {item.UserId} said {item.UserMessage} ************************";
5446
var evt = new Output { Message = goodbye };
5547
await PublishMessageAsync(evt).ConfigureAwait(true);
56-
await PublishMessageAsync(new Shutdown()).ConfigureAwait(false);
48+
if (Environment.GetEnvironmentVariable("STAY_ALIVE_ON_GOODBYE") != "true")
49+
{
50+
await PublishMessageAsync(new Shutdown()).ConfigureAwait(false);
51+
}
5752
}
5853

5954
public async Task Handle(Shutdown item)

dotnet/samples/Hello/HelloAgentState/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
namespace Hello
1717
{
18-
[TopicSubscription("HelloAgents")]
18+
[TopicSubscription("agents")]
1919
public class HelloAgent(
2020
IAgentRuntime context,
2121
IHostApplicationLifetime hostApplicationLifetime,
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
syntax = "proto3";
2+
3+
package HelloAgents;
4+
5+
option csharp_namespace = "Microsoft.AutoGen.Abstractions";
6+
message TextMessage {
7+
string textMessage = 1;
8+
string source = 2;
9+
}
10+
message Input {
11+
string message = 1;
12+
}
13+
message InputProcessed {
14+
string route = 1;
15+
}
16+
message Output {
17+
string message = 1;
18+
}
19+
message OutputWritten {
20+
string route = 1;
21+
}
22+
message IOError {
23+
string message = 1;
24+
}
25+
message NewMessageReceived {
26+
string message = 1;
27+
}
28+
message ResponseGenerated {
29+
string response = 1;
30+
}
31+
message GoodBye {
32+
string message = 1;
33+
}
34+
message MessageStored {
35+
string message = 1;
36+
}
37+
message ConversationClosed {
38+
string user_id = 1;
39+
string user_message = 2;
40+
}
41+
message Shutdown {
42+
string message = 1;
43+
}

dotnet/src/Microsoft.AutoGen/Abstractions/MessageExtensions.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,16 @@ namespace Microsoft.AutoGen.Abstractions;
88

99
public static class MessageExtensions
1010
{
11+
private const string PROTO_DATA_CONTENT_TYPE = "application/x-protobuf";
1112
public static CloudEvent ToCloudEvent<T>(this T message, string source) where T : IMessage
1213
{
1314
return new CloudEvent
1415
{
1516
ProtoData = Any.Pack(message),
1617
Type = message.Descriptor.FullName,
1718
Source = source,
18-
Id = Guid.NewGuid().ToString()
19-
19+
Id = Guid.NewGuid().ToString(),
20+
Attributes = { { "datacontenttype", new CloudEvent.Types.CloudEventAttributeValue { CeString = PROTO_DATA_CONTENT_TYPE } } }
2021
};
2122
}
2223
public static T FromCloudEvent<T>(this CloudEvent cloudEvent) where T : IMessage, new()

0 commit comments

Comments
 (0)