A programming framework for agentic AI
[.Net] Mark Message as obsolete and add ToolCallAggregateMessage type (#2716)
Xiaoyun Zhang90ca2ca64bba
diff --git a/dotnet/sample/AutoGen.BasicSamples/CodeSnippet/OpenAICodeSnippet.cs b/dotnet/sample/AutoGen.BasicSamples/CodeSnippet/OpenAICodeSnippet.csindex 022f7e9f9..cf0452212 100644--- a/dotnet/sample/AutoGen.BasicSamples/CodeSnippet/OpenAICodeSnippet.cs+++ b/dotnet/sample/AutoGen.BasicSamples/CodeSnippet/OpenAICodeSnippet.cs@@ -84,7 +84,7 @@ public partial class OpenAICodeSnippetnew TextMessage(Role.Assistant, "Hello", from: "user"),],from: "user"),- new Message(Role.Assistant, "Hello", from: "user"), // Message type is going to be deprecated, please use TextMessage instead+ new TextMessage(Role.Assistant, "Hello", from: "user"), // Message type is going to be deprecated, please use TextMessage instead};foreach (var message in messages)diff --git a/dotnet/sample/AutoGen.BasicSamples/Example03_Agent_FunctionCall.cs b/dotnet/sample/AutoGen.BasicSamples/Example03_Agent_FunctionCall.csindex e1eb5dea3..0ef8eaa48 100644--- a/dotnet/sample/AutoGen.BasicSamples/Example03_Agent_FunctionCall.cs+++ b/dotnet/sample/AutoGen.BasicSamples/Example03_Agent_FunctionCall.cs@@ -77,26 +77,26 @@ public partial class Example03_Agent_FunctionCall// talk to the assistant agentvar upperCase = await agent.SendAsync("convert to upper case: hello world");upperCase.GetContent()?.Should().Be("HELLO WORLD");- upperCase.Should().BeOfType<AggregateMessage<ToolCallMessage, ToolCallResultMessage>>();+ upperCase.Should().BeOfType<ToolCallAggregateMessage>();upperCase.GetToolCalls().Should().HaveCount(1);upperCase.GetToolCalls().First().FunctionName.Should().Be(nameof(UpperCase));var concatString = await agent.SendAsync("concatenate strings: a, b, c, d, e");concatString.GetContent()?.Should().Be("a b c d e");- concatString.Should().BeOfType<AggregateMessage<ToolCallMessage, ToolCallResultMessage>>();+ concatString.Should().BeOfType<ToolCallAggregateMessage>();concatString.GetToolCalls().Should().HaveCount(1);concatString.GetToolCalls().First().FunctionName.Should().Be(nameof(ConcatString));var calculateTax = await agent.SendAsync("calculate tax: 100, 0.1");calculateTax.GetContent().Should().Be("tax is 10");- calculateTax.Should().BeOfType<AggregateMessage<ToolCallMessage, ToolCallResultMessage>>();+ calculateTax.Should().BeOfType<ToolCallAggregateMessage>();calculateTax.GetToolCalls().Should().HaveCount(1);calculateTax.GetToolCalls().First().FunctionName.Should().Be(nameof(CalculateTax));// parallel function callsvar calculateTaxes = await agent.SendAsync("calculate tax: 100, 0.1; calculate tax: 200, 0.2");calculateTaxes.GetContent().Should().Be("tax is 10\ntax is 40"); // "tax is 10\n tax is 40- calculateTaxes.Should().BeOfType<AggregateMessage<ToolCallMessage, ToolCallResultMessage>>();+ calculateTaxes.Should().BeOfType<ToolCallAggregateMessage>();calculateTaxes.GetToolCalls().Should().HaveCount(2);calculateTaxes.GetToolCalls().First().FunctionName.Should().Be(nameof(CalculateTax));diff --git a/dotnet/sample/AutoGen.BasicSamples/Example04_Dynamic_GroupChat_Coding_Task.cs b/dotnet/sample/AutoGen.BasicSamples/Example04_Dynamic_GroupChat_Coding_Task.csindex c5d9a01f9..47dd8ce66 100644--- a/dotnet/sample/AutoGen.BasicSamples/Example04_Dynamic_GroupChat_Coding_Task.cs+++ b/dotnet/sample/AutoGen.BasicSamples/Example04_Dynamic_GroupChat_Coding_Task.cs@@ -40,7 +40,8 @@ public partial class Example04_Dynamic_GroupChat_Coding_Taskname: "groupAdmin",systemMessage: "You are the admin of the group chat",temperature: 0f,- config: gptConfig);+ config: gptConfig)+ .RegisterPrintMessage();var userProxy = new UserProxyAgent(name: "user", defaultReply: GroupChatExtension.TERMINATE, humanInputMode: HumanInputMode.NEVER).RegisterPrintMessage();diff --git a/dotnet/sample/AutoGen.BasicSamples/Example05_Dalle_And_GPT4V.cs b/dotnet/sample/AutoGen.BasicSamples/Example05_Dalle_And_GPT4V.csindex 9fccd7ab3..2d21615ef 100644--- a/dotnet/sample/AutoGen.BasicSamples/Example05_Dalle_And_GPT4V.cs+++ b/dotnet/sample/AutoGen.BasicSamples/Example05_Dalle_And_GPT4V.cs@@ -1,8 +1,9 @@// Copyright (c) Microsoft Corporation. All rights reserved.// Example05_Dalle_And_GPT4V.cs-using AutoGen;using AutoGen.Core;+using AutoGen.OpenAI;+using AutoGen.OpenAI.Extension;using Azure.AI.OpenAI;using FluentAssertions;using autogen = AutoGen.LLMConfigAPI;@@ -66,50 +67,39 @@ The image is generated from prompt {prompt}File.Delete(imagePath);}- var dalleAgent = new AssistantAgent(- name: "dalle",- systemMessage: "You are a DALL-E agent that generate image from prompt, when conversation is terminated, return the most recent image url",- llmConfig: new ConversableAgentConfig- {- Temperature = 0,- ConfigList = gpt35Config,- FunctionContracts = new[]- {- instance.GenerateImageFunctionContract,- },- },+ var generateImageFunctionMiddleware = new FunctionCallMiddleware(+ functions: [instance.GenerateImageFunctionContract],functionMap: new Dictionary<string, Func<string, Task<string>>>{{ nameof(GenerateImage), instance.GenerateImageWrapper },- })+ });+ var dalleAgent = new OpenAIChatAgent(+ openAIClient: openAIClient,+ modelName: "gpt-3.5-turbo",+ name: "dalle",+ systemMessage: "You are a DALL-E agent that generate image from prompt, when conversation is terminated, return the most recent image url")+ .RegisterMessageConnector()+ .RegisterStreamingMiddleware(generateImageFunctionMiddleware).RegisterMiddleware(async (msgs, option, agent, ct) =>{- // if last message contains [TERMINATE], then find the last image url and terminate the conversation- if (msgs.Last().GetContent()?.Contains("TERMINATE") is true)+ if (msgs.Any(msg => msg.GetContent()?.ToLower().Contains("approve") is true)){- var lastMessageWithImage = msgs.Last(msg => msg is ImageMessage) as ImageMessage;- var lastImageUrl = lastMessageWithImage.Url;- Console.WriteLine($"download image from {lastImageUrl} to {imagePath}");- var httpClient = new HttpClient();- var imageBytes = await httpClient.GetByteArrayAsync(lastImageUrl);- File.WriteAllBytes(imagePath, imageBytes);-- var messageContent = $@"{GroupChatExtension.TERMINATE}--{lastImageUrl}";- return new TextMessage(Role.Assistant, messageContent)- {- From = "dalle",- };+ return new TextMessage(Role.Assistant, $"The image satisfies the condition, conversation is terminated. {GroupChatExtension.TERMINATE}");}- var reply = await agent.GenerateReplyAsync(msgs, option, ct);+ var msgsWithoutImage = msgs.Where(msg => msg is not ImageMessage).ToList();+ var reply = await agent.GenerateReplyAsync(msgsWithoutImage, option, ct);if (reply.GetContent() is string content && content.Contains("IMAGE_GENERATION")){var imageUrl = content.Split("\n").Last();var imageMessage = new ImageMessage(Role.Assistant, imageUrl, from: reply.From);+ Console.WriteLine($"download image from {imageUrl} to {imagePath}");+ var httpClient = new HttpClient();+ var imageBytes = await httpClient.GetByteArrayAsync(imageUrl, ct);+ File.WriteAllBytes(imagePath, imageBytes);+return imageMessage;}else@@ -119,33 +109,25 @@ The image is generated from prompt {prompt}}).RegisterPrintMessage();- var gpt4VAgent = new AssistantAgent(+ var gpt4VAgent = new OpenAIChatAgent(+ openAIClient: openAIClient,name: "gpt4v",+ modelName: "gpt-4-vision-preview",systemMessage: @"You are a critism that provide feedback to DALL-E agent.Carefully check the image generated by DALL-E agent and provide feedback.-If the image satisfies the condition, then terminate the conversation by saying [TERMINATE].+If the image satisfies the condition, then say [APPROVE].Otherwise, provide detailed feedback to DALL-E agent so it can generate better image.The image should satisfy the following conditions:- There should be a cat and a mouse in the image-- The cat should be chasing after the mouse-",- llmConfig: new ConversableAgentConfig- {- Temperature = 0,- ConfigList = gpt4vConfig,- })+- The cat should be chasing after the mouse")+ .RegisterMessageConnector().RegisterPrintMessage();- IEnumerable<IMessage> conversation = new List<IMessage>()- {- new TextMessage(Role.User, "Hey dalle, please generate image from prompt: English short hair blue cat chase after a mouse")- };- var maxRound = 20;await gpt4VAgent.InitiateChatAsync(receiver: dalleAgent,message: "Hey dalle, please generate image from prompt: English short hair blue cat chase after a mouse",- maxRound: maxRound);+ maxRound: 10);File.Exists(imagePath).Should().BeTrue();}diff --git a/dotnet/src/AutoGen.Core/Extension/MessageExtension.cs b/dotnet/src/AutoGen.Core/Extension/MessageExtension.csindex 830772c4b..3dbba9668 100644--- a/dotnet/src/AutoGen.Core/Extension/MessageExtension.cs+++ b/dotnet/src/AutoGen.Core/Extension/MessageExtension.cs@@ -1,6 +1,7 @@// Copyright (c) Microsoft Corporation. All rights reserved.// MessageExtension.cs+using System;using System.Collections.Generic;using System.Linq;using System.Text;@@ -15,7 +16,9 @@ public static class MessageExtension{return message switch{+#pragma warning disable CS0618 // deprecatedMessage msg => msg.FormatMessage(),+#pragma warning restore CS0618 // deprecatedTextMessage textMessage => textMessage.FormatMessage(),ImageMessage imageMessage => imageMessage.FormatMessage(),ToolCallMessage toolCallMessage => toolCallMessage.FormatMessage(),@@ -110,6 +113,8 @@ public static class MessageExtensionreturn sb.ToString();}++ [Obsolete("This method is deprecated, please use the extension method FormatMessage(this IMessage message) instead.")]public static string FormatMessage(this Message message){var sb = new StringBuilder();@@ -149,15 +154,16 @@ public static class MessageExtensionreturn message switch{TextMessage textMessage => textMessage.Role == Role.System,+#pragma warning disable CS0618 // deprecatedMessage msg => msg.Role == Role.System,+#pragma warning restore CS0618 // deprecated_ => false,};}/// <summary>/// Get the content from the message- /// <para>if the message is a <see cref="Message"/> or <see cref="TextMessage"/>, return the content</para>- /// <para>if the message is a <see cref="ToolCallResultMessage"/> and only contains one function call, return the result of that function call</para>+ /// <para>if the message implements <see cref="ICanGetTextContent"/>, return the content from the message by calling <see cref="ICanGetTextContent.GetContent()"/></para>/// <para>if the message is a <see cref="AggregateMessage{ToolCallMessage, ToolCallResultMessage}"/> where TMessage1 is <see cref="ToolCallMessage"/> and TMessage2 is <see cref="ToolCallResultMessage"/> and the second message only contains one function call, return the result of that function call</para>/// <para>for all other situation, return null.</para>/// </summary>@@ -166,10 +172,11 @@ public static class MessageExtension{return message switch{- TextMessage textMessage => textMessage.Content,- Message msg => msg.Content,- ToolCallResultMessage toolCallResultMessage => toolCallResultMessage.ToolCalls.Count == 1 ? toolCallResultMessage.ToolCalls.First().Result : null,+ ICanGetTextContent canGetTextContent => canGetTextContent.GetContent(),AggregateMessage<ToolCallMessage, ToolCallResultMessage> aggregateMessage => string.Join("\n", aggregateMessage.Message2.ToolCalls.Where(x => x.Result is not null).Select(x => x.Result)),+#pragma warning disable CS0618 // deprecated+ Message msg => msg.Content,+#pragma warning restore CS0618 // deprecated_ => null,};}@@ -182,7 +189,9 @@ public static class MessageExtensionreturn message switch{TextMessage textMessage => textMessage.Role,+#pragma warning disable CS0618 // deprecatedMessage msg => msg.Role,+#pragma warning restore CS0618 // deprecatedImageMessage img => img.Role,MultiModalMessage multiModal => multiModal.Role,_ => null,@@ -191,8 +200,7 @@ public static class MessageExtension/// <summary>/// Return the tool calls from the message if it's available.- /// <para>if the message is a <see cref="ToolCallMessage"/>, return its tool calls</para>- /// <para>if the message is a <see cref="Message"/> and the function name and function arguments are available, return a list of tool call with one item</para>+ /// <para>if the message implements <see cref="ICanGetToolCalls"/>, return the tool calls from the message by calling <see cref="ICanGetToolCalls.GetToolCalls()"/></para>/// <para>if the message is a <see cref="AggregateMessage{ToolCallMessage, ToolCallResultMessage}"/> where TMessage1 is <see cref="ToolCallMessage"/> and TMessage2 is <see cref="ToolCallResultMessage"/>, return the tool calls from the first message</para>/// </summary>/// <param name="message"></param>@@ -201,11 +209,13 @@ public static class MessageExtension{return message switch{- ToolCallMessage toolCallMessage => toolCallMessage.ToolCalls,+ ICanGetToolCalls canGetToolCalls => canGetToolCalls.GetToolCalls().ToList(),+#pragma warning disable CS0618 // deprecatedMessage msg => msg.FunctionName is not null && msg.FunctionArguments is not null- ? msg.Content is not null ? new List<ToolCall> { new ToolCall(msg.FunctionName, msg.FunctionArguments, result: msg.Content) }- : new List<ToolCall> { new ToolCall(msg.FunctionName, msg.FunctionArguments) }+ ? msg.Content is not null ? [new ToolCall(msg.FunctionName, msg.FunctionArguments, result: msg.Content)]+ : new List<ToolCall> { new(msg.FunctionName, msg.FunctionArguments) }: null,+#pragma warning restore CS0618 // deprecatedAggregateMessage<ToolCallMessage, ToolCallResultMessage> aggregateMessage => aggregateMessage.Message1.ToolCalls,_ => null,};diff --git a/dotnet/src/AutoGen.Core/GroupChat/GroupChat.cs b/dotnet/src/AutoGen.Core/GroupChat/GroupChat.csindex 3b6288ca0..cd17a21f8 100644--- a/dotnet/src/AutoGen.Core/GroupChat/GroupChat.cs+++ b/dotnet/src/AutoGen.Core/GroupChat/GroupChat.cs@@ -110,7 +110,7 @@ The available roles are:{string.Join(",", agentNames)}Each message will start with 'From name:', e.g:-From admin:+From {agentNames.First()}://your message//.");var conv = this.ProcessConversationsForRolePlay(this.initializeMessages, conversationHistory);diff --git a/dotnet/src/AutoGen.Core/Message/IMessage.cs b/dotnet/src/AutoGen.Core/Message/IMessage.csindex 7b48f4f0d..ad215d510 100644--- a/dotnet/src/AutoGen.Core/Message/IMessage.cs+++ b/dotnet/src/AutoGen.Core/Message/IMessage.cs@@ -1,6 +1,8 @@// Copyright (c) Microsoft Corporation. All rights reserved.// IMessage.cs+using System.Collections.Generic;+namespace AutoGen.Core;/// <summary>@@ -29,7 +31,7 @@ namespace AutoGen.Core;/// <item>/// <see cref="AggregateMessage{TMessage1, TMessage2}"/>: an aggregate message type that contains two message types./// This type is useful when you want to combine two message types into one unique message type. One example is when invoking a tool call and you want to return both <see cref="ToolCallMessage"/> and <see cref="ToolCallResultMessage"/>.-/// One example of how this type is used in AutoGen is <see cref="FunctionCallMiddleware"/>+/// One example of how this type is used in AutoGen is <see cref="FunctionCallMiddleware"/> and its return message <see cref="ToolCallAggregateMessage"/>/// </item>/// </list>/// </summary>@@ -41,6 +43,24 @@ public interface IMessage<out T> : IMessage, IStreamingMessage<T>{}+/// <summary>+/// The interface for messages that can get text content.+/// This interface will be used by <see cref="MessageExtension.GetContent(IMessage)"/> to get the content from the message.+/// </summary>+public interface ICanGetTextContent : IMessage, IStreamingMessage+{+ public string? GetContent();+}++/// <summary>+/// The interface for messages that can get a list of <see cref="ToolCall"/>+/// </summary>+public interface ICanGetToolCalls : IMessage, IStreamingMessage+{+ public IEnumerable<ToolCall> GetToolCalls();+}++public interface IStreamingMessage{string? From { get; set; }diff --git a/dotnet/src/AutoGen.Core/Message/Message.cs b/dotnet/src/AutoGen.Core/Message/Message.csindex ec4751b93..b31b413ec 100644--- a/dotnet/src/AutoGen.Core/Message/Message.cs+++ b/dotnet/src/AutoGen.Core/Message/Message.cs@@ -1,10 +1,12 @@// Copyright (c) Microsoft Corporation. All rights reserved.// Message.cs+using System;using System.Collections.Generic;namespace AutoGen.Core;+[Obsolete("This message class is deprecated, please use a specific AutoGen built-in message type instead. For more information, please visit https://microsoft.github.io/autogen-for-net/articles/Built-in-messages.html")]public class Message : IMessage{public Message(diff --git a/dotnet/src/AutoGen.Core/Message/TextMessage.cs b/dotnet/src/AutoGen.Core/Message/TextMessage.csindex ed4d7436d..addd8728a 100644--- a/dotnet/src/AutoGen.Core/Message/TextMessage.cs+++ b/dotnet/src/AutoGen.Core/Message/TextMessage.cs@@ -3,7 +3,7 @@namespace AutoGen.Core;-public class TextMessage : IMessage, IStreamingMessage+public class TextMessage : IMessage, IStreamingMessage, ICanGetTextContent{public TextMessage(Role role, string content, string? from = null){@@ -44,9 +44,14 @@ public class TextMessage : IMessage, IStreamingMessage{return $"TextMessage({this.Role}, {this.Content}, {this.From})";}++ public string? GetContent()+ {+ return this.Content;+ }}-public class TextMessageUpdate : IStreamingMessage+public class TextMessageUpdate : IStreamingMessage, ICanGetTextContent{public TextMessageUpdate(Role role, string? content, string? from = null){@@ -60,4 +65,9 @@ public class TextMessageUpdate : IStreamingMessagepublic string? From { get; set; }public Role Role { get; set; }++ public string? GetContent()+ {+ return this.Content;+ }}diff --git a/dotnet/src/AutoGen.Core/Message/ToolCallAggregateMessage.cs b/dotnet/src/AutoGen.Core/Message/ToolCallAggregateMessage.csnew file mode 100644index 000000000..7781b785e--- /dev/null+++ b/dotnet/src/AutoGen.Core/Message/ToolCallAggregateMessage.cs@@ -0,0 +1,28 @@+// Copyright (c) Microsoft Corporation. All rights reserved.+// FunctionCallAggregateMessage.cs++using System.Collections.Generic;++namespace AutoGen.Core;++/// <summary>+/// An aggregate message that contains a tool call message and a tool call result message.+/// This message type is used by <see cref="FunctionCallMiddleware"/> to return both <see cref="ToolCallMessage"/> and <see cref="ToolCallResultMessage"/>.+/// </summary>+public class ToolCallAggregateMessage : AggregateMessage<ToolCallMessage, ToolCallResultMessage>, ICanGetTextContent, ICanGetToolCalls+{+ public ToolCallAggregateMessage(ToolCallMessage message1, ToolCallResultMessage message2, string? from = null)+ : base(message1, message2, from)+ {+ }++ public string? GetContent()+ {+ return this.Message2.GetContent();+ }++ public IEnumerable<ToolCall> GetToolCalls()+ {+ return this.Message1.GetToolCalls();+ }+}diff --git a/dotnet/src/AutoGen.Core/Message/ToolCallMessage.cs b/dotnet/src/AutoGen.Core/Message/ToolCallMessage.csindex 7312fd671..396dba3d3 100644--- a/dotnet/src/AutoGen.Core/Message/ToolCallMessage.cs+++ b/dotnet/src/AutoGen.Core/Message/ToolCallMessage.cs@@ -36,7 +36,7 @@ public class ToolCall}}-public class ToolCallMessage : IMessage+public class ToolCallMessage : IMessage, ICanGetToolCalls{public ToolCallMessage(IEnumerable<ToolCall> toolCalls, string? from = null){@@ -47,7 +47,7 @@ public class ToolCallMessage : IMessagepublic ToolCallMessage(string functionName, string functionArgs, string? from = null){this.From = from;- this.ToolCalls = new List<ToolCall> { new ToolCall(functionName, functionArgs) };+ this.ToolCalls = new List<ToolCall> { new ToolCall(functionName, functionArgs) { ToolCallId = functionName } };}public ToolCallMessage(ToolCallMessageUpdate update)@@ -91,6 +91,11 @@ public class ToolCallMessage : IMessagereturn sb.ToString();}++ public IEnumerable<ToolCall> GetToolCalls()+ {+ return this.ToolCalls;+ }}public class ToolCallMessageUpdate : IStreamingMessagediff --git a/dotnet/src/AutoGen.Core/Message/ToolCallResultMessage.cs b/dotnet/src/AutoGen.Core/Message/ToolCallResultMessage.csindex 99c774084..fa7357c94 100644--- a/dotnet/src/AutoGen.Core/Message/ToolCallResultMessage.cs+++ b/dotnet/src/AutoGen.Core/Message/ToolCallResultMessage.cs@@ -7,7 +7,7 @@ using System.Text;namespace AutoGen.Core;-public class ToolCallResultMessage : IMessage+public class ToolCallResultMessage : IMessage, ICanGetTextContent{public ToolCallResultMessage(IEnumerable<ToolCall> toolCalls, string? from = null){@@ -18,7 +18,7 @@ public class ToolCallResultMessage : IMessagepublic ToolCallResultMessage(string result, string functionName, string functionArgs, string? from = null){this.From = from;- var toolCall = new ToolCall(functionName, functionArgs);+ var toolCall = new ToolCall(functionName, functionArgs) { ToolCallId = functionName };toolCall.Result = result;this.ToolCalls = [toolCall];}@@ -30,6 +30,15 @@ public class ToolCallResultMessage : IMessagepublic string? From { get; set; }+ public string? GetContent()+ {+ var results = this.ToolCalls+ .Where(x => x.Result != null)+ .Select(x => x.Result);++ return string.Join("\n", results);+ }+public override string ToString(){var sb = new StringBuilder();@@ -41,16 +50,4 @@ public class ToolCallResultMessage : IMessagereturn sb.ToString();}-- private void Validate()- {- // each tool call must have a result- foreach (var toolCall in this.ToolCalls)- {- if (string.IsNullOrEmpty(toolCall.Result))- {- throw new System.ArgumentException($"The tool call {toolCall} does not have a result");- }- }- }}diff --git a/dotnet/src/AutoGen.Core/Middleware/FunctionCallMiddleware.cs b/dotnet/src/AutoGen.Core/Middleware/FunctionCallMiddleware.csindex 3bc8b2f1c..d0788077b 100644--- a/dotnet/src/AutoGen.Core/Middleware/FunctionCallMiddleware.cs+++ b/dotnet/src/AutoGen.Core/Middleware/FunctionCallMiddleware.cs@@ -18,8 +18,7 @@ namespace AutoGen.Core;/// <para>Otherwise, the message will be sent to the inner agent. In this situation</para>/// <para>if the reply from the inner agent is <see cref="ToolCallMessage"/>,/// and the tool calls is available in this middleware's function map, the tools from the reply will be invoked,-/// and a <see cref="AggregateMessage{TMessage1, TMessage2}"/> where TMessage1 is <see cref="ToolCallMessage"/> and TMessage2 is <see cref="ToolCallResultMessage"/>"/>-/// will be returned.+/// and a <see cref="ToolCallAggregateMessage"/> will be returned./// </para>/// <para>If the reply from the inner agent is <see cref="ToolCallMessage"/> but the tool calls is not available in this middleware's function map,/// or the reply from the inner agent is not <see cref="ToolCallMessage"/>, the original reply from the inner agent will be returned.</para>@@ -163,7 +162,7 @@ public class FunctionCallMiddleware : IStreamingMiddlewareif (toolCallResult.Count() > 0){var toolCallResultMessage = new ToolCallResultMessage(toolCallResult, from: agent.Name);- return new AggregateMessage<ToolCallMessage, ToolCallResultMessage>(toolCallMsg, toolCallResultMessage, from: agent.Name);+ return new ToolCallAggregateMessage(toolCallMsg, toolCallResultMessage, from: agent.Name);}else{diff --git a/dotnet/src/AutoGen.Mistral/DTOs/ChatMessage.cs b/dotnet/src/AutoGen.Mistral/DTOs/ChatMessage.csindex c5dae2aa3..b0a05d857 100644--- a/dotnet/src/AutoGen.Mistral/DTOs/ChatMessage.cs+++ b/dotnet/src/AutoGen.Mistral/DTOs/ChatMessage.cs@@ -67,18 +67,25 @@ public class ChatMessage[JsonPropertyName("tool_calls")]public List<FunctionContent>? ToolCalls { get; set; }++ [JsonPropertyName("tool_call_id")]+ public string? ToolCallId { get; set; }}public class FunctionContent{- public FunctionContent(FunctionCall function)+ public FunctionContent(string id, FunctionCall function){this.Function = function;+ this.Id = id;}[JsonPropertyName("function")]public FunctionCall Function { get; set; }+ [JsonPropertyName("id")]+ public string Id { get; set; }+public class FunctionCall{public FunctionCall(string name, string arguments)diff --git a/dotnet/src/AutoGen.Mistral/Middleware/MistralChatMessageConnector.cs b/dotnet/src/AutoGen.Mistral/Middleware/MistralChatMessageConnector.csindex 3ba910aa7..95592e97f 100644--- a/dotnet/src/AutoGen.Mistral/Middleware/MistralChatMessageConnector.cs+++ b/dotnet/src/AutoGen.Mistral/Middleware/MistralChatMessageConnector.cs@@ -158,7 +158,7 @@ public class MistralChatMessageConnector : IStreamingMiddleware, IMiddlewareelse if (finishReason == Choice.FinishReasonEnum.ToolCalls){var functionContents = choice.Message?.ToolCalls ?? throw new ArgumentNullException("choice.Message.ToolCalls");- var toolCalls = functionContents.Select(f => new ToolCall(f.Function.Name, f.Function.Arguments)).ToList();+ var toolCalls = functionContents.Select(f => new ToolCall(f.Function.Name, f.Function.Arguments) { ToolCallId = f.Id }).ToList();return new ToolCallMessage(toolCalls, from: from.Name);}else@@ -257,6 +257,7 @@ public class MistralChatMessageConnector : IStreamingMiddleware, IMiddlewarevar message = new ChatMessage(ChatMessage.RoleEnum.Tool, content: toolCall.Result){Name = toolCall.FunctionName,+ ToolCallId = toolCall.ToolCallId,};messages.Add(message);@@ -305,10 +306,12 @@ public class MistralChatMessageConnector : IStreamingMiddleware, IMiddleware// convert tool call message to chat messagevar chatMessage = new ChatMessage(ChatMessage.RoleEnum.Assistant);chatMessage.ToolCalls = new List<FunctionContent>();- foreach (var toolCall in toolCallMessage.ToolCalls)+ for (var i = 0; i < toolCallMessage.ToolCalls.Count; i++){+ var toolCall = toolCallMessage.ToolCalls[i];+ var toolCallId = toolCall.ToolCallId ?? $"{toolCall.FunctionName}_{i}";var functionCall = new FunctionContent.FunctionCall(toolCall.FunctionName, toolCall.FunctionArguments);- var functionContent = new FunctionContent(functionCall);+ var functionContent = new FunctionContent(toolCallId, functionCall);chatMessage.ToolCalls.Add(functionContent);}diff --git a/dotnet/src/AutoGen.OpenAI/Agent/GPTAgent.cs b/dotnet/src/AutoGen.OpenAI/Agent/GPTAgent.csindex 52070788e..cdc6cc464 100644--- a/dotnet/src/AutoGen.OpenAI/Agent/GPTAgent.cs+++ b/dotnet/src/AutoGen.OpenAI/Agent/GPTAgent.cs@@ -29,10 +29,8 @@ namespace AutoGen.OpenAI;/// </summary>public class GPTAgent : IStreamingAgent{- private readonly IDictionary<string, Func<string, Task<string>>>? functionMap;private readonly OpenAIClient openAIClient;- private readonly string? modelName;- private readonly OpenAIChatAgent _innerAgent;+ private readonly IStreamingAgent _innerAgent;public GPTAgent(string name,@@ -52,16 +50,23 @@ public class GPTAgent : IStreamingAgent_ => throw new ArgumentException($"Unsupported config type {config.GetType()}"),};- modelName = config switch+ var modelName = config switch{AzureOpenAIConfig azureConfig => azureConfig.DeploymentName,OpenAIConfig openAIConfig => openAIConfig.ModelId,_ => throw new ArgumentException($"Unsupported config type {config.GetType()}"),};- _innerAgent = new OpenAIChatAgent(openAIClient, name, modelName, systemMessage, temperature, maxTokens, seed, responseFormat, functions);+ _innerAgent = new OpenAIChatAgent(openAIClient, name, modelName, systemMessage, temperature, maxTokens, seed, responseFormat, functions)+ .RegisterMessageConnector();++ if (functionMap is not null)+ {+ var functionMapMiddleware = new FunctionCallMiddleware(functionMap: functionMap);+ _innerAgent = _innerAgent.RegisterStreamingMiddleware(functionMapMiddleware);+ }+Name = name;- this.functionMap = functionMap;}public GPTAgent(@@ -77,10 +82,16 @@ public class GPTAgent : IStreamingAgentIDictionary<string, Func<string, Task<string>>>? functionMap = null){this.openAIClient = openAIClient;- this.modelName = modelName;Name = name;- this.functionMap = functionMap;- _innerAgent = new OpenAIChatAgent(openAIClient, name, modelName, systemMessage, temperature, maxTokens, seed, responseFormat, functions);++ _innerAgent = new OpenAIChatAgent(openAIClient, name, modelName, systemMessage, temperature, maxTokens, seed, responseFormat, functions)+ .RegisterMessageConnector();++ if (functionMap is not null)+ {+ var functionMapMiddleware = new FunctionCallMiddleware(functionMap: functionMap);+ _innerAgent = _innerAgent.RegisterStreamingMiddleware(functionMapMiddleware);+ }}public string Name { get; }@@ -90,14 +101,7 @@ public class GPTAgent : IStreamingAgentGenerateReplyOptions? options = null,CancellationToken cancellationToken = default){- var agent = this._innerAgent.RegisterMessageConnector();- if (this.functionMap is not null)- {- var functionMapMiddleware = new FunctionCallMiddleware(functionMap: this.functionMap);- agent = agent.RegisterStreamingMiddleware(functionMapMiddleware);- }-- return await agent.GenerateReplyAsync(messages, options, cancellationToken);+ return await _innerAgent.GenerateReplyAsync(messages, options, cancellationToken);}public IAsyncEnumerable<IStreamingMessage> GenerateStreamingReplyAsync(@@ -105,13 +109,6 @@ public class GPTAgent : IStreamingAgentGenerateReplyOptions? options = null,CancellationToken cancellationToken = default){- var agent = this._innerAgent.RegisterMessageConnector();- if (this.functionMap is not null)- {- var functionMapMiddleware = new FunctionCallMiddleware(functionMap: this.functionMap);- agent = agent.RegisterStreamingMiddleware(functionMapMiddleware);- }-- return agent.GenerateStreamingReplyAsync(messages, options, cancellationToken);+ return _innerAgent.GenerateStreamingReplyAsync(messages, options, cancellationToken);}}diff --git a/dotnet/src/AutoGen.OpenAI/Extension/MessageExtension.cs b/dotnet/src/AutoGen.OpenAI/Extension/MessageExtension.csindex b3dfb1e86..ed795e5e8 100644--- a/dotnet/src/AutoGen.OpenAI/Extension/MessageExtension.cs+++ b/dotnet/src/AutoGen.OpenAI/Extension/MessageExtension.cs@@ -12,6 +12,8 @@ public static class MessageExtension{public static string TEXT_CONTENT_TYPE = "text";public static string IMAGE_CONTENT_TYPE = "image";++ [Obsolete("This method is deprecated, please replace Message with one of the built-in message types.")]public static ChatRequestUserMessage ToChatRequestUserMessage(this Message message){if (message.Value is ChatRequestUserMessage message1)@@ -50,6 +52,7 @@ public static class MessageExtensionthrow new ArgumentException("Content is null and metadata is null");}+ [Obsolete("This method is deprecated")]public static IEnumerable<ChatRequestMessage> ToOpenAIChatRequestMessage(this IAgent agent, IMessage message){if (message is IMessage<ChatRequestMessage> oaiMessage)diff --git a/dotnet/src/AutoGen.OpenAI/Middleware/OpenAIChatRequestMessageConnector.cs b/dotnet/src/AutoGen.OpenAI/Middleware/OpenAIChatRequestMessageConnector.csindex 106296fce..8f1825e2f 100644--- a/dotnet/src/AutoGen.OpenAI/Middleware/OpenAIChatRequestMessageConnector.cs+++ b/dotnet/src/AutoGen.OpenAI/Middleware/OpenAIChatRequestMessageConnector.cs@@ -178,7 +178,9 @@ public class OpenAIChatRequestMessageConnector : IMiddleware, IStreamingMiddlewaToolCallMessage toolCallMessage when (toolCallMessage.From is null || toolCallMessage.From == agent.Name) => ProcessToolCallMessage(agent, toolCallMessage),ToolCallResultMessage toolCallResultMessage => ProcessToolCallResultMessage(toolCallResultMessage),AggregateMessage<ToolCallMessage, ToolCallResultMessage> aggregateMessage => ProcessFunctionCallMiddlewareMessage(agent, aggregateMessage),+#pragma warning disable CS0618 // deprecatedMessage msg => ProcessMessage(agent, msg),+#pragma warning restore CS0618 // deprecated_ when strictMode is false => [],_ => throw new InvalidOperationException($"Invalid message type: {m.GetType().Name}"),};@@ -195,6 +197,7 @@ public class OpenAIChatRequestMessageConnector : IMiddleware, IStreamingMiddlewa});}+ [Obsolete("This method is deprecated, please use ProcessIncomingMessages(IAgent agent, IEnumerable<IMessage> messages) instead.")]private IEnumerable<ChatRequestMessage> ProcessIncomingMessagesForSelf(Message message){if (message.Role == Role.System)@@ -230,6 +233,7 @@ public class OpenAIChatRequestMessageConnector : IMiddleware, IStreamingMiddlewa}}+ [Obsolete("This method is deprecated, please use ProcessIncomingMessages(IAgent agent, IEnumerable<IMessage> messages) instead.")]private IEnumerable<ChatRequestMessage> ProcessIncomingMessagesForOther(Message message){if (message.Role == Role.System)@@ -339,6 +343,7 @@ public class OpenAIChatRequestMessageConnector : IMiddleware, IStreamingMiddlewa.Select((tc, i) => new ChatRequestToolMessage(tc.Result, tc.ToolCallId ?? $"{tc.FunctionName}_{i}"));}+ [Obsolete("This method is deprecated, please use ProcessIncomingMessages(IAgent agent, IEnumerable<IMessage> messages) instead.")]private IEnumerable<ChatRequestMessage> ProcessMessage(IAgent agent, Message message){if (message.From is not null && message.From != agent.Name)diff --git a/dotnet/src/AutoGen.SemanticKernel/Middleware/SemanticKernelChatMessageContentConnector.cs b/dotnet/src/AutoGen.SemanticKernel/Middleware/SemanticKernelChatMessageContentConnector.csindex 6a8395ef2..6ce242eb1 100644--- a/dotnet/src/AutoGen.SemanticKernel/Middleware/SemanticKernelChatMessageContentConnector.cs+++ b/dotnet/src/AutoGen.SemanticKernel/Middleware/SemanticKernelChatMessageContentConnector.cs@@ -133,7 +133,9 @@ public class SemanticKernelChatMessageContentConnector : IMiddleware, IStreaming{TextMessage textMessage => ProcessMessageForSelf(textMessage),MultiModalMessage multiModalMessage => ProcessMessageForSelf(multiModalMessage),+#pragma warning disable CS0618 // deprecatedMessage m => ProcessMessageForSelf(m),+#pragma warning restore CS0618 // deprecated_ => throw new System.NotImplementedException(),};}@@ -145,7 +147,9 @@ public class SemanticKernelChatMessageContentConnector : IMiddleware, IStreamingTextMessage textMessage => ProcessMessageForOthers(textMessage),MultiModalMessage multiModalMessage => ProcessMessageForOthers(multiModalMessage),ImageMessage imageMessage => ProcessMessageForOthers(imageMessage),+#pragma warning disable CS0618 // deprecatedMessage m => ProcessMessageForOthers(m),+#pragma warning restore CS0618 // deprecated_ => throw new InvalidOperationException("unsupported message type, only support TextMessage, ImageMessage, MultiModalMessage and Message."),};}@@ -208,7 +212,7 @@ public class SemanticKernelChatMessageContentConnector : IMiddleware, IStreamingreturn [new ChatMessageContent(AuthorRole.User, collections)];}-+ [Obsolete("This method is deprecated, please use the specific method instead.")]private IEnumerable<ChatMessageContent> ProcessMessageForSelf(Message message){if (message.Role == Role.System)@@ -229,6 +233,7 @@ public class SemanticKernelChatMessageContentConnector : IMiddleware, IStreaming}}+ [Obsolete("This method is deprecated, please use the specific method instead.")]private IEnumerable<ChatMessageContent> ProcessMessageForOthers(Message message){if (message.Role == Role.System)diff --git a/dotnet/test/AutoGen.Mistral.Tests/MistralClientAgentTests.cs b/dotnet/test/AutoGen.Mistral.Tests/MistralClientAgentTests.csindex 2b6839dd0..3aa61a7a7 100644--- a/dotnet/test/AutoGen.Mistral.Tests/MistralClientAgentTests.cs+++ b/dotnet/test/AutoGen.Mistral.Tests/MistralClientAgentTests.cs@@ -87,11 +87,15 @@ public partial class MistralClientAgentTests}""";var functionCallResult = await this.GetWeatherWrapper(weatherFunctionArgumets);-+ var toolCall = new ToolCall(this.GetWeatherFunctionContract.Name!, weatherFunctionArgumets)+ {+ ToolCallId = "012345678", // Mistral AI requires the tool call id to be a length of 9+ Result = functionCallResult,+ };IMessage[] chatHistory = [new TextMessage(Role.User, "what's the weather in Seattle?"),- new ToolCallMessage(this.GetWeatherFunctionContract.Name!, weatherFunctionArgumets, from: agent.Name),- new ToolCallResultMessage(functionCallResult, this.GetWeatherFunctionContract.Name!, weatherFunctionArgumets),+ new ToolCallMessage([toolCall], from: agent.Name),+ new ToolCallResultMessage([toolCall], weatherFunctionArgumets),];var reply = await agent.SendAsync(chatHistory: chatHistory);@@ -152,7 +156,7 @@ public partial class MistralClientAgentTestsvar question = new TextMessage(Role.User, "what's the weather in Seattle?");var reply = await functionCallAgent.SendAsync(question);- reply.Should().BeOfType<AggregateMessage<ToolCallMessage, ToolCallResultMessage>>();+ reply.Should().BeOfType<ToolCallAggregateMessage>();// resend the reply to the same agent so it can generate the final response// because the reply's from is the agent's namediff --git a/dotnet/test/AutoGen.OpenAI.Tests/ApprovalTests/OpenAIMessageTests.BasicMessageTest.approved.txt b/dotnet/test/AutoGen.OpenAI.Tests/ApprovalTests/OpenAIMessageTests.BasicMessageTest.approved.txtindex b0f70409d..e8e9af84d 100644--- a/dotnet/test/AutoGen.OpenAI.Tests/ApprovalTests/OpenAIMessageTests.BasicMessageTest.approved.txt+++ b/dotnet/test/AutoGen.OpenAI.Tests/ApprovalTests/OpenAIMessageTests.BasicMessageTest.approved.txt@@ -33,64 +33,6 @@}]},- {- "OriginalMessage": "Message(system, You are a helpful AI assistant, , , )",- "ConvertedMessages": [- {- "Name": null,- "Role": "system",- "Content": "You are a helpful AI assistant"- }- ]- },- {- "OriginalMessage": "Message(user, Hello, user, , )",- "ConvertedMessages": [- {- "Role": "user",- "Content": "Hello",- "Name": "user",- "MultiModaItem": null- }- ]- },- {- "OriginalMessage": "Message(assistant, How can I help you?, assistant, , )",- "ConvertedMessages": [- {- "Role": "assistant",- "Content": "How can I help you?",- "Name": null,- "TooCall": [],- "FunctionCallName": null,- "FunctionCallArguments": null- }- ]- },- {- "OriginalMessage": "Message(function, result, user, , )",- "ConvertedMessages": [- {- "Role": "user",- "Content": "result",- "Name": "user",- "MultiModaItem": null- }- ]- },- {- "OriginalMessage": "Message(assistant, , assistant, functionName, functionArguments)",- "ConvertedMessages": [- {- "Role": "assistant",- "Content": null,- "Name": null,- "TooCall": [],- "FunctionCallName": "functionName",- "FunctionCallArguments": "functionArguments"- }- ]- },{"OriginalMessage": "ImageMessage(user, https://example.com/image.png, user)","ConvertedMessages": [@@ -145,7 +87,7 @@"Type": "Function","Name": "test","Arguments": "test",- "Id": "test_0"+ "Id": "test"}],"FunctionCallName": null,@@ -159,7 +101,7 @@{"Role": "tool","Content": "result",- "ToolCallId": "test_0"+ "ToolCallId": "test"}]},@@ -216,7 +158,7 @@"Type": "Function","Name": "test","Arguments": "test",- "Id": "test_0"+ "Id": "test"}],"FunctionCallName": null,@@ -225,7 +167,7 @@{"Role": "tool","Content": "result",- "ToolCallId": "test_0"+ "ToolCallId": "test"}]}diff --git a/dotnet/test/AutoGen.OpenAI.Tests/MathClassTest.cs b/dotnet/test/AutoGen.OpenAI.Tests/MathClassTest.csnew file mode 100644index 000000000..87fc07670--- /dev/null+++ b/dotnet/test/AutoGen.OpenAI.Tests/MathClassTest.cs@@ -0,0 +1,223 @@+// Copyright (c) Microsoft Corporation. All rights reserved.+// MathClassTest.cs++using System;+using System.Collections.Generic;+using System.Linq;+using System.Threading;+using System.Threading.Tasks;+using AutoGen.OpenAI.Extension;+using AutoGen.Tests;+using Azure.AI.OpenAI;+using FluentAssertions;+using Xunit.Abstractions;++namespace AutoGen.OpenAI.Tests+{+ public partial class MathClassTest+ {+ private readonly ITestOutputHelper _output;++ // as of 2024-05-20, aoai return 500 error when round > 1+ // I'm pretty sure that round > 5 was supported before+ // So this is probably some wield regression on aoai side+ // I'll keep this test case here for now, plus setting round to 1+ // so the test can still pass.+ // In the future, we should rewind this test case to round > 1 (previously was 5)+ private int round = 1;+ public MathClassTest(ITestOutputHelper output)+ {+ _output = output;+ }++ private Task<IMessage> Print(IEnumerable<IMessage> messages, GenerateReplyOptions? option, IAgent agent, CancellationToken ct)+ {+ try+ {+ var reply = agent.GenerateReplyAsync(messages, option, ct).Result;++ _output.WriteLine(reply.FormatMessage());+ return Task.FromResult(reply);+ }+ catch (Exception)+ {+ _output.WriteLine("Request failed");+ _output.WriteLine($"agent name: {agent.Name}");+ foreach (var message in messages)+ {+ _output.WriteLine(message.FormatMessage());+ }++ throw;+ }++ }++ [FunctionAttribute]+ public async Task<string> CreateMathQuestion(string question, int question_index)+ {+ return $@"[MATH_QUESTION]+Question {question_index}:+{question}++Student, please answer";+ }++ [FunctionAttribute]+ public async Task<string> AnswerQuestion(string answer)+ {+ return $@"[MATH_ANSWER]+The answer is {answer}+teacher please check answer";+ }++ [FunctionAttribute]+ public async Task<string> AnswerIsCorrect(string message)+ {+ return $@"[ANSWER_IS_CORRECT]+{message}+please update progress";+ }++ [FunctionAttribute]+ public async Task<string> UpdateProgress(int correctAnswerCount)+ {+ if (correctAnswerCount >= this.round)+ {+ return $@"[UPDATE_PROGRESS]+{GroupChatExtension.TERMINATE}";+ }+ else+ {+ return $@"[UPDATE_PROGRESS]+the number of resolved question is {correctAnswerCount}+teacher, please create the next math question";+ }+ }+++ [ApiKeyFact("AZURE_OPENAI_API_KEY", "AZURE_OPENAI_ENDPOINT")]+ public async Task OpenAIAgentMathChatTestAsync()+ {+ var key = Environment.GetEnvironmentVariable("AZURE_OPENAI_API_KEY") ?? throw new ArgumentException("AZURE_OPENAI_API_KEY is not set");+ var endPoint = Environment.GetEnvironmentVariable("AZURE_OPENAI_ENDPOINT") ?? throw new ArgumentException("AZURE_OPENAI_ENDPOINT is not set");++ var openaiClient = new OpenAIClient(new Uri(endPoint), new Azure.AzureKeyCredential(key));+ var model = "gpt-35-turbo-16k";+ var teacher = await CreateTeacherAgentAsync(openaiClient, model);+ var student = await CreateStudentAssistantAgentAsync(openaiClient, model);++ var adminFunctionMiddleware = new FunctionCallMiddleware(+ functions: [this.UpdateProgressFunctionContract],+ functionMap: new Dictionary<string, Func<string, Task<string>>>+ {+ { this.UpdateProgressFunction.Name!, this.UpdateProgressWrapper },+ });+ var admin = new OpenAIChatAgent(+ openAIClient: openaiClient,+ modelName: model,+ name: "Admin",+ systemMessage: $@"You are admin. You update progress after each question is answered.")+ .RegisterMessageConnector()+ .RegisterStreamingMiddleware(adminFunctionMiddleware)+ .RegisterMiddleware(Print);++ var groupAdmin = new OpenAIChatAgent(+ openAIClient: openaiClient,+ modelName: model,+ name: "GroupAdmin",+ systemMessage: "You are group admin. You manage the group chat.")+ .RegisterMessageConnector()+ .RegisterMiddleware(Print);+ await RunMathChatAsync(teacher, student, admin, groupAdmin);+ }++ private async Task<IAgent> CreateTeacherAgentAsync(OpenAIClient client, string model)+ {+ var functionCallMiddleware = new FunctionCallMiddleware(+ functions: [this.CreateMathQuestionFunctionContract, this.AnswerIsCorrectFunctionContract],+ functionMap: new Dictionary<string, Func<string, Task<string>>>+ {+ { this.CreateMathQuestionFunctionContract.Name!, this.CreateMathQuestionWrapper },+ { this.AnswerIsCorrectFunctionContract.Name!, this.AnswerIsCorrectWrapper },+ });++ var teacher = new OpenAIChatAgent(+ openAIClient: client,+ name: "Teacher",+ systemMessage: @"You are a preschool math teacher.+You create math question and ask student to answer it.+Then you check if the answer is correct.+If the answer is wrong, you ask student to fix it",+ modelName: model)+ .RegisterMessageConnector()+ .RegisterStreamingMiddleware(functionCallMiddleware)+ .RegisterMiddleware(Print);++ return teacher;+ }++ private async Task<IAgent> CreateStudentAssistantAgentAsync(OpenAIClient client, string model)+ {+ var functionCallMiddleware = new FunctionCallMiddleware(+ functions: [this.AnswerQuestionFunctionContract],+ functionMap: new Dictionary<string, Func<string, Task<string>>>+ {+ { this.AnswerQuestionFunctionContract.Name!, this.AnswerQuestionWrapper },+ });+ var student = new OpenAIChatAgent(+ openAIClient: client,+ name: "Student",+ modelName: model,+ systemMessage: @"You are a student. You answer math question from teacher.")+ .RegisterMessageConnector()+ .RegisterStreamingMiddleware(functionCallMiddleware)+ .RegisterMiddleware(Print);++ return student;+ }++ private async Task RunMathChatAsync(IAgent teacher, IAgent student, IAgent admin, IAgent groupAdmin)+ {+ var teacher2Student = Transition.Create(teacher, student);+ var student2Teacher = Transition.Create(student, teacher);+ var teacher2Admin = Transition.Create(teacher, admin);+ var admin2Teacher = Transition.Create(admin, teacher);+ var workflow = new Graph(+ [+ teacher2Student,+ student2Teacher,+ teacher2Admin,+ admin2Teacher,+ ]);+ var group = new GroupChat(+ workflow: workflow,+ members: [+ admin,+ teacher,+ student,+ ],+ admin: groupAdmin);++ var groupChatManager = new GroupChatManager(group);+ var chatHistory = await admin.InitiateChatAsync(groupChatManager, "teacher, create question", maxRound: 50);++ chatHistory.Where(msg => msg.From == teacher.Name && msg.GetContent()?.Contains("[MATH_QUESTION]") is true)+ .Count()+ .Should().BeGreaterThanOrEqualTo(this.round);++ chatHistory.Where(msg => msg.From == student.Name && msg.GetContent()?.Contains("[MATH_ANSWER]") is true)+ .Count()+ .Should().BeGreaterThanOrEqualTo(this.round);++ chatHistory.Where(msg => msg.From == teacher.Name && msg.GetContent()?.Contains("[ANSWER_IS_CORRECT]") is true)+ .Count()+ .Should().BeGreaterThanOrEqualTo(this.round);++ // check if there's terminate chat message from admin+ chatHistory.Where(msg => msg.From == admin.Name && msg.IsGroupChatTerminateMessage())+ .Count()+ .Should().Be(1);+ }+ }+}diff --git a/dotnet/test/AutoGen.OpenAI.Tests/OpenAIChatAgentTest.cs b/dotnet/test/AutoGen.OpenAI.Tests/OpenAIChatAgentTest.csindex c504eb06a..284cd3856 100644--- a/dotnet/test/AutoGen.OpenAI.Tests/OpenAIChatAgentTest.cs+++ b/dotnet/test/AutoGen.OpenAI.Tests/OpenAIChatAgentTest.cs@@ -5,12 +5,12 @@ using System;using System.Collections.Generic;using System.Linq;using System.Threading.Tasks;-using AutoGen.OpenAI;using AutoGen.OpenAI.Extension;+using AutoGen.Tests;using Azure.AI.OpenAI;using FluentAssertions;-namespace AutoGen.Tests;+namespace AutoGen.OpenAI.Tests;public partial class OpenAIChatAgentTest{@@ -79,7 +79,6 @@ public partial class OpenAIChatAgentTestnew TextMessage(Role.Assistant, "Hello", from: "user"),],from: "user"),- new Message(Role.Assistant, "Hello", from: "user"), // Message type is going to be deprecated, please use TextMessage instead};foreach (var message in messages)@@ -133,7 +132,6 @@ public partial class OpenAIChatAgentTestnew TextMessage(Role.Assistant, question, from: "user"),],from: "user"),- new Message(Role.Assistant, question, from: "user"), // Message type is going to be deprecated, please use TextMessage instead};foreach (var message in messages)@@ -202,14 +200,13 @@ public partial class OpenAIChatAgentTestnew TextMessage(Role.Assistant, question, from: "user"),],from: "user"),- new Message(Role.Assistant, question, from: "user"), // Message type is going to be deprecated, please use TextMessage instead};foreach (var message in messages){var reply = await functionCallAgent.SendAsync(message);- reply.Should().BeOfType<AggregateMessage<ToolCallMessage, ToolCallResultMessage>>();+ reply.Should().BeOfType<ToolCallAggregateMessage>();reply.From.Should().Be("assistant");reply.GetToolCalls()!.Count().Should().Be(1);reply.GetToolCalls()!.First().FunctionName.Should().Be(this.GetWeatherAsyncFunctionContract.Name);@@ -229,7 +226,7 @@ public partial class OpenAIChatAgentTest}else{- streamingMessage.Should().BeOfType<AggregateMessage<ToolCallMessage, ToolCallResultMessage>>();+ streamingMessage.Should().BeOfType<ToolCallAggregateMessage>();streamingMessage.As<IMessage>().GetContent()!.ToLower().Should().Contain("seattle");}}diff --git a/dotnet/test/AutoGen.OpenAI.Tests/OpenAIMessageTests.cs b/dotnet/test/AutoGen.OpenAI.Tests/OpenAIMessageTests.csindex 71a50608c..81581d068 100644--- a/dotnet/test/AutoGen.OpenAI.Tests/OpenAIMessageTests.cs+++ b/dotnet/test/AutoGen.OpenAI.Tests/OpenAIMessageTests.cs@@ -10,12 +10,12 @@ using System.Threading.Tasks;using ApprovalTests;using ApprovalTests.Namers;using ApprovalTests.Reporters;-using AutoGen.OpenAI;+using AutoGen.Tests;using Azure.AI.OpenAI;using FluentAssertions;using Xunit;-namespace AutoGen.Tests;+namespace AutoGen.OpenAI.Tests;public class OpenAIMessageTests{@@ -34,15 +34,6 @@ public class OpenAIMessageTestsnew TextMessage(Role.System, "You are a helpful AI assistant"),new TextMessage(Role.User, "Hello", "user"),new TextMessage(Role.Assistant, "How can I help you?", from: "assistant"),- new Message(Role.System, "You are a helpful AI assistant"),- new Message(Role.User, "Hello", "user"),- new Message(Role.Assistant, "How can I help you?", from: "assistant"),- new Message(Role.Function, "result", "user"),- new Message(Role.Assistant, null, "assistant")- {- FunctionName = "functionName",- FunctionArguments = "functionArguments",- },new ImageMessage(Role.User, "https://example.com/image.png", "user"),new MultiModalMessage(Role.Assistant,[@@ -293,7 +284,7 @@ public class OpenAIMessageTestschatRequestMessage.ToolCalls.First().Should().BeOfType<ChatCompletionsFunctionToolCall>();var functionToolCall = (ChatCompletionsFunctionToolCall)chatRequestMessage.ToolCalls.First();functionToolCall.Name.Should().Be("test");- functionToolCall.Id.Should().Be("test_0");+ functionToolCall.Id.Should().Be("test");functionToolCall.Arguments.Should().Be("test");return await innerAgent.GenerateReplyAsync(msgs);})@@ -362,7 +353,7 @@ public class OpenAIMessageTestsinnerMessage!.Should().BeOfType<MessageEnvelope<ChatRequestMessage>>();var chatRequestMessage = (ChatRequestToolMessage)((MessageEnvelope<ChatRequestMessage>)innerMessage!).Content;chatRequestMessage.Content.Should().Be("result");- chatRequestMessage.ToolCallId.Should().Be("test_0");+ chatRequestMessage.ToolCallId.Should().Be("test");return await innerAgent.GenerateReplyAsync(msgs);}).RegisterMiddleware(middleware);@@ -439,7 +430,7 @@ public class OpenAIMessageTestsinnerMessage!.Should().BeOfType<MessageEnvelope<ChatRequestMessage>>();var chatRequestMessage = (ChatRequestToolMessage)((MessageEnvelope<ChatRequestMessage>)innerMessage!).Content;chatRequestMessage.Content.Should().Be("result");- chatRequestMessage.ToolCallId.Should().Be("test_0");+ chatRequestMessage.ToolCallId.Should().Be("test");var toolCallMessage = msgs.First();toolCallMessage!.Should().BeOfType<MessageEnvelope<ChatRequestMessage>>();@@ -449,7 +440,7 @@ public class OpenAIMessageTeststoolCallRequestMessage.ToolCalls.First().Should().BeOfType<ChatCompletionsFunctionToolCall>();var functionToolCall = (ChatCompletionsFunctionToolCall)toolCallRequestMessage.ToolCalls.First();functionToolCall.Name.Should().Be("test");- functionToolCall.Id.Should().Be("test_0");+ functionToolCall.Id.Should().Be("test");functionToolCall.Arguments.Should().Be("test");return await innerAgent.GenerateReplyAsync(msgs);})@@ -458,7 +449,7 @@ public class OpenAIMessageTests// user messagevar toolCallMessage = new ToolCallMessage("test", "test", "assistant");var toolCallResultMessage = new ToolCallResultMessage("result", "test", "test", "assistant");- var aggregateMessage = new AggregateMessage<ToolCallMessage, ToolCallResultMessage>(toolCallMessage, toolCallResultMessage, "assistant");+ var aggregateMessage = new ToolCallAggregateMessage(toolCallMessage, toolCallResultMessage, "assistant");await agent.GenerateReplyAsync([aggregateMessage]);}diff --git a/dotnet/test/AutoGen.SemanticKernel.Tests/KernelFunctionMiddlewareTests.cs b/dotnet/test/AutoGen.SemanticKernel.Tests/KernelFunctionMiddlewareTests.csindex f560419e8..658cc899e 100644--- a/dotnet/test/AutoGen.SemanticKernel.Tests/KernelFunctionMiddlewareTests.cs+++ b/dotnet/test/AutoGen.SemanticKernel.Tests/KernelFunctionMiddlewareTests.cs@@ -30,8 +30,8 @@ public class KernelFunctionMiddlewareTestsvar reply = await agent.SendAsync("what's the status of the light?");reply.GetContent().Should().Be("off");- reply.Should().BeOfType<AggregateMessage<ToolCallMessage, ToolCallResultMessage>>();- if (reply is AggregateMessage<ToolCallMessage, ToolCallResultMessage> aggregateMessage)+ reply.Should().BeOfType<ToolCallAggregateMessage>();+ if (reply is ToolCallAggregateMessage aggregateMessage){var toolCallMessage = aggregateMessage.Message1;toolCallMessage.ToolCalls.Should().HaveCount(1);@@ -44,8 +44,8 @@ public class KernelFunctionMiddlewareTestsreply = await agent.SendAsync("change the status of the light to on");reply.GetContent().Should().Be("The status of the light is now on");- reply.Should().BeOfType<AggregateMessage<ToolCallMessage, ToolCallResultMessage>>();- if (reply is AggregateMessage<ToolCallMessage, ToolCallResultMessage> aggregateMessage1)+ reply.Should().BeOfType<ToolCallAggregateMessage>();+ if (reply is ToolCallAggregateMessage aggregateMessage1){var toolCallMessage = aggregateMessage1.Message1;toolCallMessage.ToolCalls.Should().HaveCount(1);@@ -75,8 +75,8 @@ public class KernelFunctionMiddlewareTestsvar reply = await agent.SendAsync("what's the weather in Seattle?");reply.GetContent().Should().Be("The weather in Seattle is sunny.");- reply.Should().BeOfType<AggregateMessage<ToolCallMessage, ToolCallResultMessage>>();- if (reply is AggregateMessage<ToolCallMessage, ToolCallResultMessage> getWeatherMessage)+ reply.Should().BeOfType<ToolCallAggregateMessage>();+ if (reply is ToolCallAggregateMessage getWeatherMessage){var toolCallMessage = getWeatherMessage.Message1;toolCallMessage.ToolCalls.Should().HaveCount(1);@@ -88,8 +88,8 @@ public class KernelFunctionMiddlewareTestsreply = await agent.SendAsync("Create a person object with name: John, email: [email protected], age: 30");reply.GetContent().Should().Be("Name: John, Email: [email protected], Age: 30");- reply.Should().BeOfType<AggregateMessage<ToolCallMessage, ToolCallResultMessage>>();- if (reply is AggregateMessage<ToolCallMessage, ToolCallResultMessage> createPersonObjectMessage)+ reply.Should().BeOfType<ToolCallAggregateMessage>();+ if (reply is ToolCallAggregateMessage createPersonObjectMessage){var toolCallMessage = createPersonObjectMessage.Message1;toolCallMessage.ToolCalls.Should().HaveCount(1);diff --git a/dotnet/test/AutoGen.Tests/MathClassTest.cs b/dotnet/test/AutoGen.Tests/MathClassTest.csdeleted file mode 100644index 3f1eac762..000000000--- a/dotnet/test/AutoGen.Tests/MathClassTest.cs+++ /dev/null@@ -1,242 +0,0 @@-// Copyright (c) Microsoft Corporation. All rights reserved.-// MathClassTest.cs--using System;-using System.Collections.Generic;-using System.Linq;-using System.Threading.Tasks;-using AutoGen.OpenAI;-using FluentAssertions;-using Xunit.Abstractions;--namespace AutoGen.Tests-{- public partial class MathClassTest- {- private readonly ITestOutputHelper _output;- public MathClassTest(ITestOutputHelper output)- {- _output = output;- }-- [FunctionAttribute]- public async Task<string> CreateMathQuestion(string question, int question_index)- {- return $@"// ignore this line [MATH_QUESTION]-Question #{question_index}:-{question}";- }-- [FunctionAttribute]- public async Task<string> AnswerQuestion(string answer)- {- return $@"// ignore this line [MATH_ANSWER]-The answer is {answer}, teacher please check answer";- }-- [FunctionAttribute]- public async Task<string> AnswerIsCorrect(string message)- {- return $@"// ignore this line [ANSWER_IS_CORRECT]-{message}";- }-- [FunctionAttribute]- public async Task<string> UpdateProgress(int correctAnswerCount)- {- if (correctAnswerCount >= 5)- {- return $@"// ignore this line [UPDATE_PROGRESS]-{GroupChatExtension.TERMINATE}";- }- else- {- return $@"// ignore this line [UPDATE_PROGRESS]-the number of resolved question is {correctAnswerCount}-teacher, please create the next math question";- }- }--- [ApiKeyFact("AZURE_OPENAI_API_KEY", "AZURE_OPENAI_ENDPOINT")]- public async Task AssistantAgentMathChatTestAsync()- {- var teacher = await CreateTeacherAssistantAgentAsync();- var student = await CreateStudentAssistantAgentAsync();- var key = Environment.GetEnvironmentVariable("AZURE_OPENAI_API_KEY") ?? throw new ArgumentException("AZURE_OPENAI_API_KEY is not set");- var endPoint = Environment.GetEnvironmentVariable("AZURE_OPENAI_ENDPOINT") ?? throw new ArgumentException("AZURE_OPENAI_ENDPOINT is not set");- var model = "gpt-35-turbo-16k";- var admin = new GPTAgent(- name: "Admin",- systemMessage: $@"You are admin. You ask teacher to create 5 math questions. You update progress after each question is answered.",- config: new AzureOpenAIConfig(endPoint, model, key),- functions: new[]- {- this.UpdateProgressFunction,- },- functionMap: new Dictionary<string, Func<string, Task<string>>>- {- { this.UpdateProgressFunction.Name, this.UpdateProgressWrapper },- })- .RegisterMiddleware(async (messages, options, agent, ct) =>- {- // check admin reply to make sure it calls UpdateProgress function- var maxAttempt = 5;- var reply = await agent.GenerateReplyAsync(messages, options, ct);- while (maxAttempt-- > 0)- {- if (options?.Functions is { Length: 0 })- {- return reply;- }-- var formattedMessage = reply.FormatMessage();- this._output.WriteLine(formattedMessage);- if (reply.GetContent()?.Contains("[UPDATE_PROGRESS]") is true)- {- return reply;- }- else- {- await Task.Delay(1000);- var review = "Admin, please update progress based on conversation";- reply = await agent.SendAsync(review, messages, ct);- }- }-- throw new Exception("Admin does not call UpdateProgress function");- });-- await RunMathChatAsync(teacher, student, admin);- }-- private async Task<IAgent> CreateTeacherAssistantAgentAsync()- {- var key = Environment.GetEnvironmentVariable("AZURE_OPENAI_API_KEY") ?? throw new ArgumentException("AZURE_OPENAI_API_KEY is not set");- var endPoint = Environment.GetEnvironmentVariable("AZURE_OPENAI_ENDPOINT") ?? throw new ArgumentException("AZURE_OPENAI_ENDPOINT is not set");- var model = "gpt-35-turbo-16k";- var config = new AzureOpenAIConfig(endPoint, model, key);- var llmConfig = new ConversableAgentConfig- {- ConfigList = new[]- {- config,- },- FunctionContracts = new[]- {- this.CreateMathQuestionFunctionContract,- this.AnswerIsCorrectFunctionContract,- },- };-- var teacher = new AssistantAgent(- name: "Teacher",- systemMessage: $@"You are a preschool math teacher.-You create math question and ask student to answer it.-Then you check if the answer is correct.-If the answer is wrong, you ask student to fix it.-If the answer is correct, you create another math question.-",- llmConfig: llmConfig,- functionMap: new Dictionary<string, Func<string, Task<string>>>- {- { this.CreateMathQuestionFunction.Name, this.CreateMathQuestionWrapper },- { this.AnswerIsCorrectFunction.Name, this.AnswerIsCorrectWrapper },- });-- return teacher;- }-- private async Task<IAgent> CreateStudentAssistantAgentAsync()- {- var key = Environment.GetEnvironmentVariable("AZURE_OPENAI_API_KEY") ?? throw new ArgumentException("AZURE_OPENAI_API_KEY is not set");- var endPoint = Environment.GetEnvironmentVariable("AZURE_OPENAI_ENDPOINT") ?? throw new ArgumentException("AZURE_OPENAI_ENDPOINT is not set");- var model = "gpt-35-turbo-16k";- var config = new AzureOpenAIConfig(endPoint, model, key);- var llmConfig = new ConversableAgentConfig- {- FunctionContracts = new[]- {- this.AnswerQuestionFunctionContract,- },- ConfigList = new[]- {- config,- },- };- var student = new AssistantAgent(- name: "Student",- systemMessage: $@"You are a student. Here's your workflow in pseudo code:--workflow--answer_question-if answer is wrong- fix_answer--end---Here are a few examples of answer_question:--example 1--2--Here are a few examples of fix_answer:--example 1--sorry, the answer should be 2, not 3-",- llmConfig: llmConfig,- functionMap: new Dictionary<string, Func<string, Task<string>>>- {- { this.AnswerQuestionFunction.Name, this.AnswerQuestionWrapper }- });-- return student;- }-- private async Task RunMathChatAsync(IAgent teacher, IAgent student, IAgent admin)- {- var group = new GroupChat(- [- admin,- teacher,- student,- ],- admin);-- admin.SendIntroduction($@"Welcome to the group chat! I'm admin", group);- teacher.SendIntroduction($@"Hey I'm Teacher", group);- student.SendIntroduction($@"Hey I'm Student", group);- admin.SendIntroduction(@$"Teacher, please create pre-school math question for student and check answer.-Student, for each question, please answer it and ask teacher to check if the answer is correct.-I'll update the progress after each question is answered.-The conversation will end after 5 correct answers.-", group);-- var groupChatManager = new GroupChatManager(group);- var chatHistory = await admin.InitiateChatAsync(groupChatManager, maxRound: 50);-- // print chat history- foreach (var message in chatHistory)- {- _output.WriteLine(message.FormatMessage());- }-- // check if there's five questions from teacher- chatHistory.Where(msg => msg.From == teacher.Name && msg.GetContent()?.Contains("[MATH_QUESTION]") is true)- .Count()- .Should().BeGreaterThanOrEqualTo(5);-- // check if there's more than five answers from student (answer might be wrong)- chatHistory.Where(msg => msg.From == student.Name && msg.GetContent()?.Contains("[MATH_ANSWER]") is true)- .Count()- .Should().BeGreaterThanOrEqualTo(5);-- // check if there's five answer_is_correct from teacher- chatHistory.Where(msg => msg.From == teacher.Name && msg.GetContent()?.Contains("[ANSWER_IS_CORRECT]") is true)- .Count()- .Should().BeGreaterThanOrEqualTo(5);-- // check if there's terminate chat message from admin- chatHistory.Where(msg => msg.From == admin.Name && msg.IsGroupChatTerminateMessage())- .Count()- .Should().Be(1);- }- }-}diff --git a/dotnet/test/AutoGen.Tests/SingleAgentTest.cs b/dotnet/test/AutoGen.Tests/SingleAgentTest.csindex 79d2b9c2f..b784ff8da 100644--- a/dotnet/test/AutoGen.Tests/SingleAgentTest.cs+++ b/dotnet/test/AutoGen.Tests/SingleAgentTest.cs@@ -118,7 +118,6 @@ namespace AutoGen.Testsvar agentWithFunction = new GPTAgent("gpt", "You are a helpful AI assistant", config, 0, functions: new[] { this.EchoAsyncFunction });await EchoFunctionCallTestAsync(agentWithFunction);- await UpperCaseTestAsync(agentWithFunction);}[ApiKeyFact("AZURE_OPENAI_API_KEY", "AZURE_OPENAI_ENDPOINT")]@@ -144,7 +143,6 @@ namespace AutoGen.TestsllmConfig: llmConfig);await EchoFunctionCallTestAsync(assistantAgent);- await UpperCaseTestAsync(assistantAgent);}[Fact]@@ -286,7 +284,7 @@ namespace AutoGen.Testsreply.GetContent().Should().Be("[ECHO] Hello world");reply.From.Should().Be(agent.Name);- reply.Should().BeOfType<AggregateMessage<ToolCallMessage, ToolCallResultMessage>>();+ reply.Should().BeOfType<ToolCallAggregateMessage>();}public async Task EchoFunctionCallExecutionStreamingTestAsync(IStreamingAgent agent)@@ -306,7 +304,7 @@ namespace AutoGen.TestsfinalReply = reply;}- if (finalReply is AggregateMessage<ToolCallMessage, ToolCallResultMessage> aggregateMessage)+ if (finalReply is ToolCallAggregateMessage aggregateMessage){var toolCallResultMessage = aggregateMessage.Message2;toolCallResultMessage.ToolCalls.First().Result.Should().Be(answer);diff --git a/dotnet/test/AutoGen.Tests/TwoAgentTest.cs b/dotnet/test/AutoGen.Tests/TwoAgentTest.csindex 91437eaa6..5c9a350e0 100644--- a/dotnet/test/AutoGen.Tests/TwoAgentTest.cs+++ b/dotnet/test/AutoGen.Tests/TwoAgentTest.cs@@ -68,7 +68,7 @@ public partial class TwoAgentTestelse{// terminate message- return new Message(Role.Assistant, GroupChatExtension.TERMINATE);+ return new TextMessage(Role.Assistant, GroupChatExtension.TERMINATE);}}).RegisterMiddleware(async (msgs, option, agent, ct) =>diff --git a/dotnet/test/AutoGen.Tests/WorkflowTest.cs b/dotnet/test/AutoGen.Tests/WorkflowTest.csindex d57cf2126..d1d12010e 100644--- a/dotnet/test/AutoGen.Tests/WorkflowTest.cs+++ b/dotnet/test/AutoGen.Tests/WorkflowTest.cs@@ -30,12 +30,12 @@ public class WorkflowTestvar canTransit = await aliceToBob.CanTransitionAsync([]);canTransit.Should().BeFalse();- canTransit = await aliceToBob.CanTransitionAsync(new[] { new Message(Role.Assistant, "Hello") });+ canTransit = await aliceToBob.CanTransitionAsync(new[] { new TextMessage(Role.Assistant, "Hello") });canTransit.Should().BeTrue();// if no function is provided, it should always return truevar aliceToBobNoFunction = Transition.Create(alice, bob);- canTransit = await aliceToBobNoFunction.CanTransitionAsync(new[] { new Message(Role.Assistant, "Hello") });+ canTransit = await aliceToBobNoFunction.CanTransitionAsync(new[] { new TextMessage(Role.Assistant, "Hello") });canTransit.Should().BeTrue();}diff --git a/dotnet/website/articles/Built-in-messages.md b/dotnet/website/articles/Built-in-messages.mdindex 2767091bd..3a3754a30 100644--- a/dotnet/website/articles/Built-in-messages.md+++ b/dotnet/website/articles/Built-in-messages.md@@ -7,12 +7,15 @@ Besides, AutoGen also provides a set of built-in message types that implement th> [!NOTE]> The minimal requirement for an agent to be used as admin in @AutoGen.Core.GroupChat is to support @AutoGen.Core.TextMessage.+> [!NOTE]+> @AutoGen.Core.Message will be deprecated in 0.0.14. Please replace it with a more specific message type like @AutoGen.Core.TextMessage, @AutoGen.Core.ImageMessage, etc.+- @AutoGen.Core.TextMessage: A message that contains a piece of text.- @AutoGen.Core.ImageMessage: A message that contains an image.- @AutoGen.Core.MultiModalMessage: A message that contains multiple modalities like text, image, etc.- @AutoGen.Core.ToolCallMessage: A message that represents a function call request.- @AutoGen.Core.ToolCallResultMessage: A message that represents a function call result.-- @AutoGen.Core.AggregateMessage`2: A message that represents an aggregate message that contains multiple sub-messages. This type of message is used by @AutoGen.Core.FunctionCallMiddleware to aggregate both @AutoGen.Core.ToolCallMessage and @AutoGen.Core.ToolCallResultMessage into a single message.+- @AutoGen.Core.ToolCallAggregateMessage: A message that contains both @AutoGen.Core.ToolCallMessage and @AutoGen.Core.ToolCallResultMessage. This type of message is used by @AutoGen.Core.FunctionCallMiddleware to aggregate both @AutoGen.Core.ToolCallMessage and @AutoGen.Core.ToolCallResultMessage into a single message.- @AutoGen.Core.MessageEnvelope`1: A message that represents an envelope that contains a message of any type.- @AutoGen.Core.Message: The original message type before 0.0.9. This message type is reserved for backward compatibility. It is recommended to replace it with a more specific message type like @AutoGen.Core.TextMessage, @AutoGen.Core.ImageMessage, etc.