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.3 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. // Copyright (c) Microsoft Corporation. All rights reserved.
  2. // EchoAgent.cs
  3. using System.Runtime.CompilerServices;
  4. using AutoGen.Core;
  5. namespace AutoGen.Service.Tests;
  6. public class EchoAgent : IStreamingAgent
  7. {
  8. public EchoAgent(string name)
  9. {
  10. Name = name;
  11. }
  12. public string Name { get; }
  13. public async Task<IMessage> GenerateReplyAsync(
  14. IEnumerable<IMessage> messages,
  15. GenerateReplyOptions? options = null,
  16. CancellationToken cancellationToken = default)
  17. {
  18. return messages.Last();
  19. }
  20. public async IAsyncEnumerable<IMessage> GenerateStreamingReplyAsync(
  21. IEnumerable<IMessage> messages,
  22. GenerateReplyOptions? options = null,
  23. [EnumeratorCancellation] CancellationToken cancellationToken = default)
  24. {
  25. var lastMessage = messages.LastOrDefault();
  26. if (lastMessage == null)
  27. {
  28. yield break;
  29. }
  30. // return each character of the last message as a separate message
  31. if (lastMessage.GetContent() is string content)
  32. {
  33. foreach (var c in content)
  34. {
  35. yield return new TextMessageUpdate(Role.Assistant, c.ToString(), this.Name);
  36. }
  37. }
  38. }
  39. }