|
6 | 6 | using Microsoft.Extensions.DependencyInjection; |
7 | 7 | using Microsoft.Extensions.Hosting; |
8 | 8 |
|
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; } |
18 | 11 | var app = await AgentsApp.PublishMessageAsync("HelloAgents", new NewMessageReceived |
19 | 12 | { |
20 | 13 | Message = "World" |
21 | | -}, local: true); |
22 | | -//var app = await AgentsApp.StartAsync(); |
| 14 | +}, local: local).ConfigureAwait(false); |
23 | 15 | await app.WaitForShutdownAsync(); |
24 | 16 |
|
25 | 17 | namespace Hello |
26 | 18 | { |
27 | | - [TopicSubscription("HelloAgents")] |
| 19 | + [TopicSubscription("agents")] |
28 | 20 | public class HelloAgent( |
29 | 21 | IAgentRuntime context, IHostApplicationLifetime hostApplicationLifetime, |
30 | 22 | [FromKeyedServices("EventTypes")] EventTypes typeRegistry) : AgentBase( |
@@ -53,7 +45,10 @@ public async Task Handle(ConversationClosed item) |
53 | 45 | var goodbye = $"********************* {item.UserId} said {item.UserMessage} ************************"; |
54 | 46 | var evt = new Output { Message = goodbye }; |
55 | 47 | 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 | + } |
57 | 52 | } |
58 | 53 |
|
59 | 54 | public async Task Handle(Shutdown item) |
|
0 commit comments