-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5b0422b
commit c9d1358
Showing
1 changed file
with
35 additions
and
36 deletions.
There are no files selected for viewing
71 changes: 35 additions & 36 deletions
71
dotnet/src/Microsoft.AutoGen/Agents/Agents/IOAgent/ConsoleAgent/IHandleConsole.cs
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 |
---|---|---|
@@ -1,47 +1,46 @@ | ||
using Microsoft.AutoGen.Abstractions; | ||
|
||
namespace Microsoft.AutoGen.Agents | ||
namespace Microsoft.AutoGen.Agents; | ||
|
||
public interface IHandleConsole : IHandle<Output>, IHandle<Input> | ||
{ | ||
public interface IHandleConsole : IHandle<Output>, IHandle<Input> | ||
{ | ||
string Route { get; } | ||
AgentId AgentId { get; } | ||
ValueTask PublishEvent(CloudEvent item); | ||
string Route { get; } | ||
AgentId AgentId { get; } | ||
ValueTask PublishEvent(CloudEvent item); | ||
|
||
async Task IHandle<Output>.Handle(Output item) | ||
{ | ||
// Assuming item has a property `Message` that we want to write to the console | ||
Console.WriteLine(item.Message); | ||
await ProcessOutput(item.Message); | ||
async Task IHandle<Output>.Handle(Output item) | ||
{ | ||
// Assuming item has a property `Message` that we want to write to the console | ||
Console.WriteLine(item.Message); | ||
await ProcessOutput(item.Message); | ||
|
||
var evt = new OutputWritten | ||
{ | ||
Route = "console" | ||
}.ToCloudEvent(AgentId.Key); | ||
await PublishEvent(evt); | ||
} | ||
async Task IHandle<Input>.Handle(Input item) | ||
var evt = new OutputWritten | ||
{ | ||
Console.WriteLine("Please enter input:"); | ||
string content = Console.ReadLine() ?? string.Empty; | ||
Route = "console" | ||
}.ToCloudEvent(AgentId.Key); | ||
await PublishEvent(evt); | ||
} | ||
async Task IHandle<Input>.Handle(Input item) | ||
{ | ||
Console.WriteLine("Please enter input:"); | ||
string content = Console.ReadLine() ?? string.Empty; | ||
|
||
await ProcessInput(content); | ||
await ProcessInput(content); | ||
|
||
var evt = new InputProcessed | ||
{ | ||
Route = "console" | ||
}.ToCloudEvent(AgentId.Key); | ||
await PublishEvent(evt); | ||
} | ||
static Task ProcessOutput(string message) | ||
var evt = new InputProcessed | ||
{ | ||
// Implement your output processing logic here | ||
return Task.CompletedTask; | ||
} | ||
static Task<string> ProcessInput(string message) | ||
{ | ||
// Implement your input processing logic here | ||
return Task.FromResult(message); | ||
} | ||
Route = "console" | ||
}.ToCloudEvent(AgentId.Key); | ||
await PublishEvent(evt); | ||
} | ||
static Task ProcessOutput(string message) | ||
{ | ||
// Implement your output processing logic here | ||
return Task.CompletedTask; | ||
} | ||
static Task<string> ProcessInput(string message) | ||
{ | ||
// Implement your input processing logic here | ||
return Task.FromResult(message); | ||
} | ||
} |