autogen icon indicating copy to clipboard operation
autogen copied to clipboard

AutoGen.OpenAI.OpenAIChatAgent using Azure.AI.OpenAI.AzureOpenAIClient fails

Open graemefoster opened this issue 1 year ago • 2 comments

What happened?

Vanilla install of AutoGen 0.2.1 (DOTNET 8). The RegisterPrintMessage consistently fails with this message:

Declaration referenced in a method implementation cannot be a final method.  Type: 'OpenAI.Chat.AsyncStreamingChatCompletionUpdateCollection'.  Assembly: 'OpenAI, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b4187f3e65366280'.

No other nuget packages (other than Azure.Identity) are referenced.

What did you expect to happen?

No errors

How can we reproduce it (as minimally and precisely as possible)?

var userProxy = new UserProxyAgent( "userProxyAgent", "You are the voice of the observer watching the game and will be asked if you are happy to accept a tactic change.", humanInputMode: HumanInputMode.ALWAYS);

var otherAgent = new AutoGen.OpenAI.OpenAIChatAgent( new Azure.AI.OpenAI.AzureOpenAIClient( new Uri(...), new DefaultAzureCredential()).GetChatClient("gpt-4o"), name: name, systemMessage: systemMessage ) .RegisterMessageConnector() .RegisterPrintMessage();

await userProxy.InitiateChatAsync(otherAgent, "Hello");

AutoGen version

0.2.1 nuget package

Which package was this bug in

Core

Model used

gpt-4o

Python version

N/A

Operating system

MAC OS Sequoia 15.1.1

Any additional info you think would be helpful for fixing this bug

No response

graemefoster avatar Dec 10 '24 02:12 graemefoster

Somehow I can't reproduce the error on my end, could you provide a minimal reproducable example.

LittleLittleCloud avatar Dec 10 '24 20:12 LittleLittleCloud

Sure:

DOTNET 8 (also fails on DOTNET 9) Tested on Windows and Mac M3

Using AutoGen 0.2.1 AutoGen.OpenAI 0.2.1 Azure.Identity 1.13.1

var tacticianAgent = BuildAgent(
	"tacticianAgent",
	"You are an expert football tactician. Given the state of a game in play you can suggest changes to your team. Only offer max 3 suggestions.");

var stattoAgent = BuildAgent(
	"stattoAgent",
	"You are an expert football statistician. Given a games current state you can make a prediction on what the outcome will be given a change to the team's formation.");

var userProxy = new UserProxyAgent(
	"userProxyAgent",
	"You are the voice of the observer watching the game and will be asked if you are happy to accept a tactic change.",
	humanInputMode: HumanInputMode.ALWAYS);
	
var groupChat = new GroupChat([userProxy, tacticianAgent, stattoAgent]);
var groupChatManager = new GroupChatManager(groupChat);

// Start the conversation
await userProxy.InitiateChatAsync(groupChatManager, "We're playing a 4-3-3 against a 4-3-2-1 and are 1-0 down with ten minutes to go. What should we do to give ourselves a maximum chance of winning?");


IAgent BuildAgent(string name, string systemMessage)
{
        // WORKS WITHOUT ISSUES 
	//return new AutoGen.Ollama.OllamaAgent(
	//	new HttpClient()
	//	{
	//		BaseAddress = new Uri("http://localhost:11434")
	//	},
	//	name: name,
	//	systemMessage: systemMessage,
	//	modelName: "llama3.2"
	//)
	//.RegisterMessageConnector()
	//.RegisterPrintMessage(); // Register a hook to print messages nicely to console

        //FAILS
	return new AutoGen.OpenAI.OpenAIChatAgent(
		new Azure.AI.OpenAI.AzureOpenAIClient(
			new Uri(<uri>),
			new DefaultAzureCredential()).GetChatClient(<gpt-4o>),
		name: name,
		systemMessage: systemMessage
	)
	.RegisterMessageConnector()
	.RegisterPrintMessage(); // Register a hook to print messages nicely to console
}

graemefoster avatar Dec 12 '24 00:12 graemefoster

Turns out it's because of imcompatibility between different version of OpenAI packages. Updating to nightly build version seems to resolve the issue

Here's the NuGet.Config which connects to nightly build

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <packageSources>
    <clear />
    <add key="nuget.org" value="https://api.nuget.org/v3/index.json" />
    <add key="AutoGen-Nightly" value="https://pkgs.dev.azure.com/AGPublish/AGPublic/_packaging/AutoGen-Nightly/nuget/v3/index.json" />
  </packageSources>
</configuration>

And nightly-build version

0.2.2-dev.20241209.1

LittleLittleCloud avatar Dec 12 '24 22:12 LittleLittleCloud

Any ideas when a working version will be pushed to nuget.org? Be good to get the 'out-the-box' experience working. Happy to put a PR up.

graemefoster avatar Dec 13 '24 01:12 graemefoster

@graemefoster Thanks, the fix is already in main. We are waiting for #3801 to be completed before making another release to nuget., There are some internal processes needed to be completed for ESRP real sign configuration

LittleLittleCloud avatar Dec 13 '24 02:12 LittleLittleCloud