You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

EchoAgent.cs 1.0 kB

12345678910111213141516171819202122232425262728293031323334353637
  1. // Copyright (c) Microsoft Corporation. All rights reserved.
  2. // EchoAgent.cs
  3. using System.Runtime.CompilerServices;
  4. using AutoGen.Core;
  5. namespace AutoGen.Tests;
  6. public class EchoAgent : IStreamingAgent
  7. {
  8. public EchoAgent(string name)
  9. {
  10. Name = name;
  11. }
  12. public string Name { get; }
  13. public Task<IMessage> GenerateReplyAsync(
  14. IEnumerable<IMessage> conversation,
  15. GenerateReplyOptions? options = null,
  16. CancellationToken ct = default)
  17. {
  18. // return the most recent message
  19. var lastMessage = conversation.Last();
  20. lastMessage.From = this.Name;
  21. return Task.FromResult(lastMessage);
  22. }
  23. public async IAsyncEnumerable<IMessage> GenerateStreamingReplyAsync(IEnumerable<IMessage> messages, GenerateReplyOptions? options = null, [EnumeratorCancellation] CancellationToken cancellationToken = default)
  24. {
  25. foreach (var message in messages)
  26. {
  27. message.From = this.Name;
  28. yield return message;
  29. }
  30. }
  31. }