In AgentGroupChat only One Agent is Participating out of three? My Code is in C# and uses Agentic Framework #10148
Unanswered
lovedeepatsgit
asked this question in
Q&A
Replies: 2 comments
-
Tagging @crickman for visibility. |
Beta Was this translation helpful? Give feedback.
0 replies
-
Thanks for your question and the clear code sample, @lovedeepatsgit. A couple observations:
Please try running this version to make progress on your starting point: //Defining the agent names for use in functions
const string Agent_One = "agent_teacher";
const string Agent_Two = "beta_agent";
const string Agent_Three = "gamma_agent";
ChatCompletionAgent agent_teacher =
new()
{
//Name = "Agent_One",
Name = Agent_One,
Instructions = "You are an Helpful Ai Teacher, who helps students to Learn Statistics.",
Kernel = kernel
};
ChatCompletionAgent beta_agent =
new()
{
//Name = "Agent_Two",
Name = Agent_Two,
Instructions = "Your are Assessment Teacher, Your task is listen to the conversation and ask questions to test the knowledge of students.",
Kernel = kernel
};
ChatCompletionAgent gamma_agent =
new()
{
//Name = "Agent_Three",
Name = Agent_Three,
Instructions = "You are an expert in Statistics, Your task is to provide the correct answers to the questions",
Kernel = kernel
};
// Defining a Kernel Function for Selection Strategy of Agents
KernelFunction selectionFunction =
AgentGroupChat.CreatePromptFunctionForStrategy(
$$$"""
Determine which participant to take the next turn in a conversation.
Choose only from these participants:
- {{{Agent_One}}}
- {{{Agent_Two}}}
- {{{Agent_Three}}}
Always follow these rules when selecting the next participant:
- After {{{Agent_One}}} takes a turn, {{{Agent_Two}}} should take the next turn.
- After {{{Agent_Two}}} takes a turn, {{{Agent_Three}}} should take the next turn.
Reply only with the agent name without explanation or formatting.
History:
{{$history}}
""",
safeParameterNames: "history");
// Defining Selection staretgy for the agent group chat
KernelFunctionSelectionStrategy selectionStrategy =
new(selectionFunction, kernel)
{
// Always start with teacher_agent (agent_one)
InitialAgent = agent_teacher,
//Parse the function response.
ResultParser = (result) =>
{
Console.WriteLine("###: " + result);
return result.GetValue<string>() ?? Agent_One;
},
// The prompt variable name for the history argument.
HistoryVariableName = "history",
};
// Defining a kernel function for the termination strategy of the agent group chat.
KernelFunction terminationFunction =
AgentGroupChat.CreatePromptFunctionForStrategy(
$$$"""
if {{{Agent_Three}}} has spoken respond with the single word: terminate.
otherwise respond with the single word: continue.
History:
{{$history}}
""",
safeParameterNames: "history");
//Define the termination strategy for the agent group chat.
KernelFunctionTerminationStrategy terminationStrategy =
new(terminationFunction, kernel)
{
//Agents can approve.
Agents = [agent_teacher, beta_agent, gamma_agent],
//Parse the function response.
ResultParser = (result) =>
{
Console.WriteLine("$$$: " + result);
return result.GetValue<string>()?.Contains("terminate", StringComparison.OrdinalIgnoreCase) ?? false;
},
//The prompt variable name for the history argument.
HistoryVariableName = "history",
//Limit total number of turns to 10.
MaximumIterations = 10,
};
AgentGroupChat agentGroupChat = new(agent_teacher, beta_agent, gamma_agent)
{
ExecutionSettings = new AgentGroupChatSettings
{
SelectionStrategy = selectionStrategy,
TerminationStrategy = terminationStrategy,
}
};
agentGroupChat.AddChatMessage(new ChatMessageContent(AuthorRole.User, "What is the use statistics in real life?"));
await foreach (ChatMessageContent response in agentGroupChat.InvokeAsync())
{
Console.WriteLine("**************************************************");
Console.WriteLine(value: $"[{response.AuthorName}] {response.Content}");
}
Console.WriteLine(agentGroupChat.IsComplete); |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
In the Below Code Only One Agent (Agent_One) responds and the conversation stops, I have tried this code many times but still getting the same issue, If someone have some insights or solutions then please reply to this query.
Beta Was this translation helpful? Give feedback.
All reactions