File tree 4 files changed +46
-23
lines changed
dotnet/samples/Hello-distributed/Backend
4 files changed +46
-23
lines changed Original file line number Diff line number Diff line change @@ -12,40 +12,25 @@ public class HelloAgent(
12
12
[ FromKeyedServices ( "EventTypes" ) ] EventTypes typeRegistry ) : AgentBase (
13
13
context ,
14
14
typeRegistry ) ,
15
- ISayHello ,
16
15
IHandleConsole ,
17
- IHandle < AppNewMessageReceived > ,
18
- IHandle < AppConversationClosed >
16
+ IHandle < NewGreetingRequested >
19
17
{
20
- public async Task Handle ( AppNewMessageReceived item )
18
+ public async Task Handle ( NewGreetingRequested item )
21
19
{
22
20
var response = await SayHello ( item . Message ) . ConfigureAwait ( false ) ;
23
21
var evt = new Output { Message = response } ;
24
22
await PublishMessageAsync ( evt ) . ConfigureAwait ( false ) ;
25
- var goodbye = new AppConversationClosed
23
+ var goodbye = new NewGreetingGenerated
26
24
{
27
25
UserId = AgentId . Key ,
28
26
UserMessage = "Goodbye"
29
27
} ;
30
28
await PublishMessageAsync ( goodbye ) . ConfigureAwait ( false ) ;
31
29
}
32
- public async Task Handle ( AppConversationClosed item )
33
- {
34
- var goodbye = $ "********************* { item . UserId } said { item . UserMessage } ************************";
35
- var evt = new AppOutput
36
- {
37
- Message = goodbye
38
- } ;
39
- await PublishMessageAsync ( evt ) . ConfigureAwait ( false ) ;
40
- }
41
30
42
31
public async Task < string > SayHello ( string ask )
43
32
{
44
33
var response = $ "\n \n \n \n ***************Hello { ask } **********************\n \n \n \n ";
45
34
return response ;
46
35
}
47
36
}
48
- public interface ISayHello
49
- {
50
- public Task < string > SayHello ( string ask ) ;
51
- }
Original file line number Diff line number Diff line change
1
+ // Copyright (c) Microsoft Corporation. All rights reserved.
2
+ // OutputAgent.cs
3
+
4
+ using Microsoft . AutoGen . Abstractions ;
5
+ using Microsoft . AutoGen . Agents ;
6
+
7
+ namespace Backend . Agents ;
8
+
9
+ [ TopicSubscription ( "HelloAgents" ) ]
10
+ public class OutputAgent (
11
+ IAgentRuntime context ,
12
+ [ FromKeyedServices ( "EventTypes" ) ] EventTypes typeRegistry ) : AgentBase (
13
+ context ,
14
+ typeRegistry ) ,
15
+ IHandleConsole ,
16
+ IHandle < NewGreetingGenerated >
17
+ {
18
+ public async Task Handle ( NewGreetingGenerated item )
19
+ {
20
+ // TODO: store to memory
21
+
22
+ }
23
+ }
Original file line number Diff line number Diff line change 1
1
// Copyright (c) Microsoft Corporation. All rights reserved.
2
2
// Program.cs
3
3
4
+ using Backend ;
4
5
using Backend . Agents ;
6
+ using Microsoft . AspNetCore . Mvc ;
7
+ using Microsoft . AutoGen . Abstractions ;
5
8
using Microsoft . AutoGen . Agents ;
6
9
using Microsoft . AutoGen . Extensions . SemanticKernel ;
7
10
23
26
var app = builder . Build ( ) ;
24
27
25
28
app . MapDefaultEndpoints ( ) ;
29
+
30
+ app . MapPost ( "/sessions" , async ( [ FromBody ] string message , AgentWorker client ) =>
31
+ {
32
+ var session = Guid . NewGuid ( ) . ToString ( ) ;
33
+ await client . PublishEventAsync ( new NewGreetingRequested { Message = message } . ToCloudEvent ( session ) ) ;
34
+ return session ;
35
+ } ) ;
36
+
37
+ app . MapGet ( "/sessions/{session}" , async ( string session ) =>
38
+ {
39
+
40
+ return session ;
41
+ } ) ;
42
+
26
43
app . UseRouting ( )
27
44
. UseEndpoints ( endpoints =>
28
45
{
Original file line number Diff line number Diff line change @@ -4,13 +4,11 @@ package helloWorld;
4
4
5
5
option csharp_namespace = "Backend" ;
6
6
7
- message AppOutput {
7
+ message NewGreetingRequested {
8
8
string message = 1 ;
9
9
}
10
- message AppNewMessageReceived {
11
- string message = 1 ;
12
- }
13
- message AppConversationClosed {
10
+
11
+ message NewGreetingGenerated {
14
12
string user_id = 1 ;
15
13
string user_message = 2 ;
16
14
}
You can’t perform that action at this time.
0 commit comments