You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
So, after lengthy (all day) debugging and trial and error, I have code that still does not work.
I am trying to do an Agent in C# that has Mary and Joe telling each other jokes. I don't care what the actual conversation is.
So doing dual agent: I set it up with OllamaAgent (works fine for a simple query). Then make two ConversableAgent, Mary and Joe.
(I setup up some Transition for a Graph, but that was not working so unused code.)
Then make a RoundRobbinGroupChat, and a GroupChatManager and then kick it off with "Tell a joke Mary."
I then GenerateReplyAsync on the groupChatManager. And loop showing the result, and appending the history.
What I get is just the same joke repeated 3 times (my loop limit).
I suspect I am doing something basically wrong. Any help?
Here is the source.
`
using AutoGen;
using AutoGen.Core;
using AutoGen.Ollama;
using AutoGen.Ollama.Extension;
using AutoGen.SemanticKernel.Extension;
namespace AutoGenTest1;
internal class Program
{
static async Task Main(string[] args)
{
await (new Program()).RunAgents(args);
}
async Task RunAgents(string[] args)
{
CancellationToken ct = new();
ConsoleColor consoleColor = Console.ForegroundColor;
Console.WriteLine("Hello, AutoGen");
Console.ForegroundColor = ConsoleColor.Green;
HttpClient httpClient = new()
{
BaseAddress = new Uri("http://localhost:11434"),
};
IAgent ollamaAgent = new OllamaAgent(
httpClient: httpClient,
name: "ollama",
modelName: "llama3.2",
systemMessage: "You are a helpful AI assistant")
.RegisterMessageConnector()
.RegisterPrintMessage();
Dictionary<string, Func<string, Task<string>>> functionMap = new()
{
{ "test", MyFunction }
};
IAgent joeAgent = new ConversableAgent(
name: "Joe",
systemMessage: "Your name is Joe and you are part of a comedy duo. Always prefix your answers with Joe| and postfix with 'What do you think Mary'",
innerAgent: ollamaAgent,
defaultAutoReply: "I'm sorry, I don't know how to help with that. (Joe)",
humanInputMode: HumanInputMode.AUTO,
isTermination: null,
functionMap: functionMap
).RegisterPrintMessage();
IAgent maryAgent = new ConversableAgent(
name: "Mary",
systemMessage: "Your name is Mary and you are part of a comedy duo. Always prefix your answers with Mary| and postfix with 'What do you think Joe'",
innerAgent: ollamaAgent,
defaultAutoReply: "I'm sorry, I don't know how to help with that. (Mary)",
humanInputMode: HumanInputMode.AUTO,
isTermination: null,
functionMap: functionMap
).RegisterPrintMessage();
List<Transition> transitions = [
Transition.Create(from: joeAgent, to: maryAgent),
Transition.Create(from: maryAgent, to: joeAgent)
];
Graph graph = new(transitions);
RoundRobinGroupChat groupChat = new(
agents: [joeAgent, maryAgent]
);
GroupChatManager groupChatManager = new(groupChat);
GenerateReplyOptions generateReplyOptions = new()
{
MaxToken = 100
};
List<AutoGen.Core.IMessage> chatHistory = [
new AutoGen.Core.TextMessage(AutoGen.Core.Role.User, "Tell a joke Mary,", "Joe"),
];
int maxLoops = 3;
while (maxLoops > 0)
{
var result = await groupChatManager.GenerateReplyAsync(
options: generateReplyOptions,
messages: chatHistory,
cancellationToken: ct);
Console.WriteLine(".........................................");
Console.WriteLine(result);
Console.WriteLine("==============================================");
chatHistory.Add(result);
maxLoops--;
}
Console.ForegroundColor = consoleColor;
Console.WriteLine("Done");
}
public async Task<string> MyFunction(string input)
{
// Your logic here
await Task.Delay(100); // Simulate async work
return $"Processed: {input}";
}
}
`
And the output
`
Hello, AutoGen
from: ollama
Mary|I've got one! Why couldn't the bicycle stand up by itself? Because it was two-tired! What do you think Joe?
TextMessage from ollama
--------------------
Mary|I've got one! Why couldn't the bicycle stand up by itself? Because it was two-tired! What do you think Joe?
--------------------
.........................................
TextMessage(assistant, Mary|I've got one! Why couldn't the bicycle stand up by itself? Because it was two-tired! What do you think Joe?, ollama)
==============================================
.........................................
TextMessage(assistant, Mary|I've got one! Why couldn't the bicycle stand up by itself? Because it was two-tired! What do you think Joe?, ollama)
==============================================
.........................................
TextMessage(assistant, Mary|I've got one! Why couldn't the bicycle stand up by itself? Because it was two-tired! What do you think Joe?, ollama)
==============================================
Done
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
So, after lengthy (all day) debugging and trial and error, I have code that still does not work.
I am trying to do an Agent in C# that has Mary and Joe telling each other jokes. I don't care what the actual conversation is.
So doing dual agent: I set it up with OllamaAgent (works fine for a simple query). Then make two ConversableAgent, Mary and Joe.
(I setup up some Transition for a Graph, but that was not working so unused code.)
Then make a RoundRobbinGroupChat, and a GroupChatManager and then kick it off with "Tell a joke Mary."
I then GenerateReplyAsync on the groupChatManager. And loop showing the result, and appending the history.
What I get is just the same joke repeated 3 times (my loop limit).
I suspect I am doing something basically wrong. Any help?
Here is the source.
`
`
And the output
`
Hello, AutoGen
from: ollama
Mary|I've got one! Why couldn't the bicycle stand up by itself? Because it was two-tired! What do you think Joe?
`
Beta Was this translation helpful? Give feedback.
All reactions