diff --git a/Samples/Senaprc.AI.Samples.Agents/Program.cs b/Samples/Senaprc.AI.Samples.Agents/Program.cs index 18feb05..7e8bb78 100644 --- a/Samples/Senaprc.AI.Samples.Agents/Program.cs +++ b/Samples/Senaprc.AI.Samples.Agents/Program.cs @@ -4,6 +4,8 @@ using AutoGen.Core; using AutoGen.Mistral; using AutoGen.SemanticKernel; +using AutoGen.SemanticKernel.Extension; +using Microsoft.AspNetCore.Http.HttpResults; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.SemanticKernel; @@ -52,7 +54,7 @@ var parameter = new PromptConfigParameter() { MaxTokens = 2000, - Temperature = 0.7, + Temperature = 0, TopP = 0.5, }; @@ -79,19 +81,31 @@ #endregion +var accessor = new SemanticKernelAgent( + kernel: kernel, + name: "Accessor", + systemMessage: """ + 你是整个对话的对接人,用于传递消息,并接收最终的返回结果。 + """) + .RegisterTextMessageConnector(); + // Create the Administrtor -var administrator = new SemanticKernelAgent( +var ceo = new SemanticKernelAgent( kernel: kernel, - name: "行政主管", + name: "CEO", systemMessage: """ - 你是行政主管,你拥有制定合同、确认项目在公司层面的风险等责任。你正在处理一个项目需求的梳理,并且需要答复客户可行性,以及最终可能的合同条款。 + 你是公司CEO,你拥有制定合同、确认项目在公司层面的风险等责任。你正在处理一个项目需求的梳理,并且需要答复客户可行性,以及最终可能的合同条款。 你可以向你的下属提问,以获得你想要的答案,并按照要求总结后进行回复。 请注意:每一项决策都必须至少通过产品经理、项目经理的反馈和确认,才能最终给出最终的回复。 - 这些是你的下属: - - 产品经理:产品经理负责产品的功能设计和产品的功能规划。 - - 项目经理: 项目经理负责所有项目的开发任务的安排和功能可行性的评估。 + 这些是你的下属, 你可以通过@来向他们提问: + - 产品经理:负责产品的功能设计和产品的功能规划。 + - 项目经理: 负责所有项目的开发任务的安排和功能可行性的评估。 + + e.g: @产品经理 xxxx。 + + 你的客户是张三。 """) .RegisterTextMessageConnector() .RegisterCustomPrintMessage(new PrintWechatMessageMiddleware(AgentKeys.SendWechatMessage)); @@ -101,7 +115,7 @@ kernel: kernel, name: "产品经理", systemMessage: """ - 你是产品经理,你向行政主管负责,并且负责回答他的所有问题。 + 你是产品经理,你向 CEO 负责,并且负责回答他的所有问题。 为了确保你有最新的信息,你可以使用网络搜索插件在回答问题之前在网上搜索信息,也可以根据你的经验,按照要求回答问题,并作出相对应的规划和决策。 """) @@ -113,7 +127,7 @@ kernel: kernel, name: "项目经理", systemMessage: """ - 你是项目经理,你向行政主管负责,并且负责回答他的所有问题。 + 你是项目经理,你向 CEO 负责,并且负责回答他的所有问题。 产品经理可能会告诉你项目的规划方案,此时你需要对其进行评估,并安排对应的开发任务。 为了确保你有最新的信息,你可以使用网络搜索插件在回答问题之前在网上搜索信息,也可以根据你的经验,按照要求回答问题,并作出相对应的规划和决策。 @@ -125,14 +139,15 @@ // Create the hearing member -var hearingMember = new UserProxyAgent(name: "BA"); +var user = new UserProxyAgent(name: "张三") + .RegisterPrintMessage(); // Create the group admin var admin = new SemanticKernelAgent( kernel: kernel, - name: "admin", - systemMessage: "你是群管理员.") - .RegisterTextMessageConnector(); + name: "admin") + .RegisterMessageConnector() + .RegisterPrintMessage(); // Create the AI team // define the transition among group members @@ -169,9 +184,10 @@ #endregion -var graphConnector = GraphBuilder.Start() - .ConnectFrom(hearingMember).TwoWay(administrator) - .ConnectFrom(administrator).TwoWay(projectManager).AlsoTwoWay(productManager) +var graphConnector = GraphBuilder + .Start() + .ConnectFrom(user).TwoWay(ceo)//.AlsoTwoWay(accessor) + .ConnectFrom(ceo).TwoWay(projectManager).AlsoTwoWay(productManager)//.AlsoTwoWay(accessor) .Finish(); var aiTeam = graphConnector.CreateAiTeam(admin); @@ -188,21 +204,29 @@ // start the chat // generate a greeting message to hearing member from Administrator -var greetingMessage = await administrator.SendAsync("你好,如果已经就绪,请告诉我们“已就位”,并和 BA 打个招呼"); +var greetingMessage = await ceo.SendAsync("你好,如果已经就绪,请告诉我们“已就位”,并和张三打个招呼"); try { - await administrator.SendMessageToGroupAsync( - groupChat: aiTeam, - chatHistory: [greetingMessage], - maxRound: 20); + await foreach (var message in aiTeam.SendAsync(chatHistory: [greetingMessage], + maxRound: 20)) + { + // process exit + if (message.GetContent()?.Contains("exit") is true) + { + Console.WriteLine("您已推出对话"); + return; + } + } } catch (Exception ex) { Console.WriteLine($"抱歉发生了异常: {ex.Message}. "); } -Console.WriteLine("好,让我们重新开始!"); + + +Console.WriteLine("本轮对话已结束,让我们重新开始!"); Console.WriteLine(); goto Start; \ No newline at end of file diff --git a/Samples/Senaprc.AI.Samples.Agents/Senaprc.AI.Samples.Agents.csproj b/Samples/Senaprc.AI.Samples.Agents/Senaprc.AI.Samples.Agents.csproj index 2bb7d2a..8b06903 100644 --- a/Samples/Senaprc.AI.Samples.Agents/Senaprc.AI.Samples.Agents.csproj +++ b/Samples/Senaprc.AI.Samples.Agents/Senaprc.AI.Samples.Agents.csproj @@ -31,11 +31,11 @@ - - + + - - + + diff --git a/src/Senparc.AI.Agents/AgentExtensions/AgentExtension.cs b/src/Senparc.AI.Agents/AgentExtensions/AgentExtension.cs index a21be17..c6cc963 100644 --- a/src/Senparc.AI.Agents/AgentExtensions/AgentExtension.cs +++ b/src/Senparc.AI.Agents/AgentExtensions/AgentExtension.cs @@ -77,7 +77,15 @@ public static GraphConnectorEnd AlsoTwoWay(this GraphConnectorEnd from #region AI Team 构造 - public static GroupChat CreateAiTeam(this GraphConnector graphConnector, TFromAgent adminAgent) where TFromAgent : IAgent + /// + /// 创建 AITeam 对象(GroupChat) + /// + /// + /// + /// + /// + public static GroupChat CreateAiTeam(this GraphConnector graphConnector, TFromAgent adminAgent) + where TFromAgent : IAgent { var aiTeam = new GroupChat( members: graphConnector.Agents.Values, diff --git a/src/Senparc.AI.Agents/Senparc.AI.Agents.csproj b/src/Senparc.AI.Agents/Senparc.AI.Agents.csproj index d0fc817..4cc4e75 100644 --- a/src/Senparc.AI.Agents/Senparc.AI.Agents.csproj +++ b/src/Senparc.AI.Agents/Senparc.AI.Agents.csproj @@ -2,7 +2,7 @@ netstandard2.1 - 0.2.0 + 0.3.0-beta1 enable 10.0 Senparc.AI.Agents @@ -40,7 +40,7 @@ - + \ No newline at end of file